public static ListUploadedFilesResponse List(OneSkyService service, int projectId, int startPage, int itemsPerPage) { //https://github.com/onesky/api-documentation-platform/blob/master/resources/file.md#upload---upload-a-file Debug.Assert(startPage >= 1); Debug.Assert(itemsPerPage >= 1); string url = service.AddAuthenticationParameters(String.Format("https://platform.api.onesky.io/1/projects/{0}/files", projectId)); url += "&page=" + startPage + "&per_page=" + itemsPerPage; using (var client = new WebClient()) using (var stream = client.OpenRead(url)) { var jsonSerializer = new DataContractJsonSerializer(typeof(ListUploadedFilesResponse)); return((ListUploadedFilesResponse)jsonSerializer.ReadObject(stream)); } }
public static bool Delete(OneSkyService service, int projectId) { //https://github.com/onesky/api-documentation-platform/blob/master/resources/project.md string url = service.AddAuthenticationParameters(string.Format("https://platform.api.onesky.io/1/projects/{0}", projectId)); try { using (var client = new WebClient()) { client.UploadString(url, "DELETE", ""); } return(true); } catch (WebException) { return(false); } }
public static Task <UploadFileResponse> Upload(OneSkyService service, int projectId, string filename, Stream stream, string cultureName) { //https://github.com/onesky/api-documentation-platform/blob/master/resources/file.md#upload---upload-a-file Debug.Assert(stream != null); Debug.Assert(cultureName != null); string url = service.AddAuthenticationParameters(String.Format("https://platform.api.onesky.io/1/projects/{0}/files", projectId)); string fileFormat = GetFileFormat(Path.GetExtension(filename)); if (fileFormat == null) { return(null); } url += "&file_format=" + fileFormat + "&locale=" + cultureName + "&is_keeping_all_strings=false"; return(Task.Factory.StartNew(() => { return HttpWebRequestUploadFile(service, url, filename, "file", stream, fileFormat); })); }
public static Task Status(OneSkyService service, int projectId, string filename, CultureInfo culture) { return(Task.Factory.StartNew((obj) => { //https://github.com/onesky/api-documentation-platform/blob/master/resources/translation.md Debug.Assert(!String.IsNullOrWhiteSpace(filename)); Debug.Assert(culture != null); string url = service.AddAuthenticationParameters(String.Format("https://platform.api.onesky.io/1/projects/{0}/translations/status", projectId)); url += "&locale=" + LocaleCodeHelper.ConvertToLocaleCode(culture.Name) + "&file_name=" + filename; var state = (TranslationExportStatus)obj; TranslationStatusResponse response; using (var client = new WebClient()) using (var stream = client.OpenRead(url)) { var jsonSerializer = new DataContractJsonSerializer(typeof(TranslationStatusResponse)); response = (TranslationStatusResponse)jsonSerializer.ReadObject(stream); } state.Progress = response.Data.Progress; while (response.Meta.Status == 200 && response.Data.Progress != "100%") { Thread.Sleep(5000); // Wait 5 seconds state.Progress = response.Data.Progress; using (var client = new WebClient()) using (var stream = client.OpenRead(url)) { var jsonSerializer = new DataContractJsonSerializer(typeof(TranslationStatusResponse)); response = (TranslationStatusResponse)jsonSerializer.ReadObject(stream); } } }, new TranslationExportStatus())); }