|
1 | | -# Databox - the C# library for the Static OpenAPI document of Push API resource |
| 1 | +## Databox |
2 | 2 |
|
3 | | -Push API resources Open API documentation |
| 3 | +This package is designed to consume the Databox Push API functionality via .NET based client. |
4 | 4 |
|
5 | | -This C# SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project: |
| 5 | +Supported .NET versions: .NET 6.0 and later. |
6 | 6 |
|
7 | | -- API version: 0.4.4-alpha.4 |
8 | | -- SDK version: 0.0.3 |
9 | | -- Generator version: 7.6.0 |
10 | | -- Build package: org.openapitools.codegen.languages.CSharpClientCodegen |
11 | | - |
12 | | -<a id="frameworks-supported"></a> |
13 | | -## Frameworks supported |
14 | | - |
15 | | -<a id="dependencies"></a> |
16 | | -## Dependencies |
17 | | - |
18 | | -- [Json.NET](https://www.nuget.org/packages/Newtonsoft.Json/) - 13.0.2 or later |
19 | | -- [JsonSubTypes](https://www.nuget.org/packages/JsonSubTypes/) - 1.8.0 or later |
20 | | -- [System.ComponentModel.Annotations](https://www.nuget.org/packages/System.ComponentModel.Annotations) - 5.0.0 or later |
21 | | - |
22 | | -The DLLs included in the package may not be the latest version. We recommend using [NuGet](https://docs.nuget.org/consume/installing-nuget) to obtain the latest version of the packages: |
23 | | -``` |
24 | | -Install-Package Newtonsoft.Json |
25 | | -Install-Package JsonSubTypes |
26 | | -Install-Package System.ComponentModel.Annotations |
27 | | -``` |
28 | | -<a id="installation"></a> |
29 | 7 | ## Installation |
30 | | -Run the following command to generate the DLL |
31 | | -- [Mac/Linux] `/bin/sh build.sh` |
32 | | -- [Windows] `build.bat` |
33 | 8 |
|
34 | | -Then include the DLL (under the `bin` folder) in the C# project, and use the namespaces: |
35 | | -```csharp |
36 | | -using Databox.Api; |
37 | | -using Databox.Client; |
38 | | -using Databox.Model; |
39 | | -``` |
40 | | -<a id="packaging"></a> |
41 | | -## Packaging |
| 9 | +The package is listed as **public** in our Databox Github repository. In order to consume it, you must first add a **nuget source**. |
42 | 10 |
|
43 | | -A `.nuspec` is included with the project. You can follow the Nuget quickstart to [create](https://docs.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package#create-the-package) and [publish](https://docs.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package#publish-the-package) packages. |
| 11 | +Databox package repository url is: https://nuget.pkg.github.com/databox/index.json |
44 | 12 |
|
45 | | -This `.nuspec` uses placeholders from the `.csproj`, so build the `.csproj` directly: |
| 13 | +Detail instructions on how to add this to your project is available [here](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-nuget-registry). |
46 | 14 |
|
47 | | -``` |
48 | | -nuget pack -Build -OutputDirectory out Databox.csproj |
49 | | -``` |
50 | | - |
51 | | -Then, publish to a [local feed](https://docs.microsoft.com/en-us/nuget/hosting-packages/local-feeds) or [other host](https://docs.microsoft.com/en-us/nuget/hosting-packages/overview) and consume the new package via Nuget as usual. |
| 15 | +After this is completed, the package can be installed via IDE (package named **"Databox"**) or via **dotnet cli** command |
52 | 16 |
|
53 | | -<a id="usage"></a> |
54 | | -## Usage |
55 | | - |
56 | | -To use the API client with a HTTP proxy, setup a `System.Net.WebProxy` |
57 | | -```csharp |
58 | | -Configuration c = new Configuration(); |
59 | | -System.Net.WebProxy webProxy = new System.Net.WebProxy("http://myProxyUrl:80/"); |
60 | | -webProxy.Credentials = System.Net.CredentialCache.DefaultCredentials; |
61 | | -c.Proxy = webProxy; |
62 | 17 | ``` |
63 | | - |
64 | | -### Connections |
65 | | -Each ApiClass (properly the ApiClient inside it) will create an instance of HttpClient. It will use that for the entire lifecycle and dispose it when called the Dispose method. |
66 | | - |
67 | | -To better manager the connections it's a common practice to reuse the HttpClient and HttpClientHandler (see [here](https://docs.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests#issues-with-the-original-httpclient-class-available-in-net) for details). To use your own HttpClient instance just pass it to the ApiClass constructor. |
68 | | - |
69 | | -```csharp |
70 | | -HttpClientHandler yourHandler = new HttpClientHandler(); |
71 | | -HttpClient yourHttpClient = new HttpClient(yourHandler); |
72 | | -var api = new YourApiClass(yourHttpClient, yourHandler); |
| 18 | +dotnet add package Databox --version <version> |
73 | 19 | ``` |
74 | 20 |
|
75 | | -If you want to use an HttpClient and don't have access to the handler, for example in a DI context in Asp.net Core when using IHttpClientFactory. |
| 21 | +### Prerequisites |
76 | 22 |
|
77 | | -```csharp |
78 | | -HttpClient yourHttpClient = new HttpClient(); |
79 | | -var api = new YourApiClass(yourHttpClient); |
80 | | -``` |
81 | | -You'll loose some configuration settings, the features affected are: Setting and Retrieving Cookies, Client Certificates, Proxy settings. You need to either manually handle those in your setup of the HttpClient or they won't be available. |
82 | | - |
83 | | -Here an example of DI setup in a sample web project: |
84 | | - |
85 | | -```csharp |
86 | | -services.AddHttpClient<YourApiClass>(httpClient => |
87 | | - new PetApi(httpClient)); |
88 | | -``` |
| 23 | +In use the Databox Push API functionality, please refer to [Databox Developers Page](https://developers.databox.com/), specifically the **Quick Guide** section, where you will learn how to create a **Databox Push API token** which is required for pushing your data. |
89 | 24 |
|
| 25 | +### Example |
90 | 26 |
|
91 | | -<a id="getting-started"></a> |
92 | | -## Getting Started |
| 27 | +The basic example of pushing data to Databox is provided below: |
93 | 28 |
|
94 | 29 | ```csharp |
95 | | -using System.Collections.Generic; |
96 | 30 | using System.Diagnostics; |
97 | | -using System.Net.Http; |
98 | 31 | using Databox.Api; |
99 | 32 | using Databox.Client; |
100 | 33 | using Databox.Model; |
101 | 34 |
|
102 | 35 | namespace Example |
103 | 36 | { |
104 | | - public class Example |
| 37 | + public class Example |
| 38 | + { |
| 39 | + public static async Task Main(string[] args) |
105 | 40 | { |
106 | | - public static void Main() |
107 | | - { |
108 | | - |
109 | | - Configuration config = new Configuration(); |
110 | | - config.BasePath = "https://push.databox.com"; |
111 | | - // Configure HTTP basic authorization: basicAuth |
112 | | - config.Username = "YOUR_USERNAME"; |
113 | | - config.Password = "YOUR_PASSWORD"; |
114 | | - |
115 | | - // create instances of HttpClient, HttpClientHandler to be reused later with different Api classes |
116 | | - HttpClient httpClient = new HttpClient(); |
117 | | - HttpClientHandler httpClientHandler = new HttpClientHandler(); |
118 | | - var apiInstance = new DefaultApi(httpClient, config, httpClientHandler); |
119 | | - |
120 | | - try |
121 | | - { |
122 | | - apiInstance.DataDelete(); |
123 | | - } |
124 | | - catch (ApiException e) |
125 | | - { |
126 | | - Debug.Print("Exception when calling DefaultApi.DataDelete: " + e.Message ); |
127 | | - Debug.Print("Status Code: "+ e.ErrorCode); |
128 | | - Debug.Print(e.StackTrace); |
129 | | - } |
130 | 41 |
|
| 42 | + Configuration config = new Configuration(); |
| 43 | + config.BasePath = "https://push.databox.com"; |
| 44 | + config.Username = "<Your_Databox_API_Token>"; |
| 45 | + config.DefaultHeaders.Add("Accept", "application/vnd.databox.v2+json"); |
| 46 | + |
| 47 | + |
| 48 | + HttpClient httpClient = new HttpClient(); |
| 49 | + HttpClientHandler httpClientHandler = new HttpClientHandler(); |
| 50 | + var apiInstance = new DefaultApi(httpClient, config, httpClientHandler); |
| 51 | + var dataPostRequest = new List<PushData>() { |
| 52 | + new PushData() { |
| 53 | + Key = "<Metric_name>", |
| 54 | + Value = 123, |
| 55 | + Date = "<Date_in_ISO8601>", |
| 56 | + Unit = "<Unit>", // Optional |
| 57 | + Attributes = new List<PushDataAttribute>() { // Optional |
| 58 | + new PushDataAttribute() { |
| 59 | + Key = "<Dimension_name>", |
| 60 | + Value = "<Dimension_value>" |
| 61 | + } |
| 62 | + } |
131 | 63 | } |
| 64 | + }; |
| 65 | + |
| 66 | + try |
| 67 | + { |
| 68 | + var response = await apiInstance.DataPostWithHttpInfoAsync(dataPostRequest); |
| 69 | + Console.WriteLine(response.Data.ToString()); |
| 70 | + } |
| 71 | + catch (ApiException e) |
| 72 | + { |
| 73 | + Console.WriteLine("Exception when calling DefaultApi.DataPostWithHttpInfo: " + e.Message); |
| 74 | + Console.WriteLine("Status Code: " + e.ErrorCode); |
| 75 | + Console.WriteLine(e.StackTrace); |
| 76 | + } |
132 | 77 | } |
| 78 | + } |
133 | 79 | } |
134 | 80 | ``` |
135 | | - |
136 | | -<a id="documentation-for-api-endpoints"></a> |
137 | | -## Documentation for API Endpoints |
138 | | - |
139 | | -All URIs are relative to *https://push.databox.com* |
140 | | - |
141 | | -Class | Method | HTTP request | Description |
142 | | ------------- | ------------- | ------------- | ------------- |
143 | | -*DefaultApi* | [**DataDelete**](docs/DefaultApi.md#datadelete) | **DELETE** /data | |
144 | | -*DefaultApi* | [**DataMetricKeyDelete**](docs/DefaultApi.md#datametrickeydelete) | **DELETE** /data/{metricKey} | |
145 | | -*DefaultApi* | [**DataPost**](docs/DefaultApi.md#datapost) | **POST** /data | |
146 | | -*DefaultApi* | [**MetrickeysGet**](docs/DefaultApi.md#metrickeysget) | **GET** /metrickeys | |
147 | | -*DefaultApi* | [**MetrickeysPost**](docs/DefaultApi.md#metrickeyspost) | **POST** /metrickeys | |
148 | | -*DefaultApi* | [**PingGet**](docs/DefaultApi.md#pingget) | **GET** /ping | |
149 | | - |
150 | | - |
151 | | -<a id="documentation-for-models"></a> |
152 | | -## Documentation for Models |
153 | | - |
154 | | - - [Model.ApiResponse](docs/ApiResponse.md) |
155 | | - - [Model.PushData](docs/PushData.md) |
156 | | - - [Model.PushDataAttribute](docs/PushDataAttribute.md) |
157 | | - - [Model.State](docs/State.md) |
158 | | - |
159 | | - |
160 | | -<a id="documentation-for-authorization"></a> |
161 | | -## Documentation for Authorization |
162 | | - |
163 | | - |
164 | | -Authentication schemes defined for the API: |
165 | | -<a id="basicAuth"></a> |
166 | | -### basicAuth |
167 | | - |
168 | | -- **Type**: HTTP basic authentication |
169 | | - |
0 commit comments