Wrapper for simple access to all API functions of OneSky ("new API"), which takes care of correctly authenticating and marshalling data between .NET POCO (with PascalCase or camelCase member naming convention) and the API calls.
See https://github.com/onesky/api-documentation-platform for available API.
The wrapper is generic, so that any existing (and future) method of can be invoked. Therefore, the following list is not comprehensive as it represents just a few examples.
For all operations, an instance of ApiClient
needs to be used; we assume an instance named client
in the following examples. The instance holds the API URI and keys. Since the instance wraps a HttpClient
, the same re-use and thread-safety guidelines apply. In summary, use a single instance for the lifetime of your application, you may use it from multiple threads, and it should be disposed at the end.
var response = client.GetAll<ApiIdName>("project-groups").Result;
foreach (var pair in response) {
Console.WriteLine($"{pair.Id}: {pair.Name}");
}
var response = client.GetAll<ApiIdName>($"project-groups/{groupId}/projects").Result;
foreach (var pair in response) {
Console.WriteLine($"{pair.Id}: {pair.Name}");
}
var response = client.GetAll<ApiFileInfo>($"projects/{projectId}/files").Result;
foreach (var pair in response) {
Console.WriteLine($"{pair.FileName}: {pair.StringCount}");
}
using (MemoryStream data = new MemoryStream()) {
var response = client.GetFile($"projects/{projectId}/translations", new {
SourceFileName = fileName,
Locale = "de",
FileFormat = "HIERARCHICAL_JSON"
}, data).Result;
data.Seek(0, SeekOrigin.Begin);
using (TextReader textReader = new StreamReader(data, Encoding.GetEncoding(response.Headers.ContentType?.CharSet ?? "UTF-8"))) {
Console.WriteLine(textReader.ReadToEnd());
}
}
var jsonContent = new StringContent(@"{ ""key"": ""Some text"" }");
jsonContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data") {
FileName = remoteFileName
};
jsonContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var response = client.Post<ApiFileUploadInfo>(projectFilesUri, new {
File = jsonContent,
FileFormat = "HIERARCHICAL_JSON"
})).Result;
var response = client.Delete<ApiName>(projectFilesUri, new {
FileName = remoteFileName
}).Result;
(C) 2016 Sirius Technologies AG
MIT license, see LICENSE.txt