Skip to content

Commit

Permalink
Updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
bwiz committed Sep 18, 2024
1 parent ef6b986 commit 3acc506
Showing 1 changed file with 50 additions and 139 deletions.
189 changes: 50 additions & 139 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,169 +1,80 @@
# Databox - the C# library for the Static OpenAPI document of Push API resource
## Databox

Push API resources Open API documentation
This package is designed to consume the Databox Push API functionality via .NET based client.

This C# SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
Supported .NET versions: .NET 6.0 and later.

- API version: 0.4.4-alpha.4
- SDK version: 0.0.3
- Generator version: 7.6.0
- Build package: org.openapitools.codegen.languages.CSharpClientCodegen

<a id="frameworks-supported"></a>
## Frameworks supported

<a id="dependencies"></a>
## Dependencies

- [Json.NET](https://www.nuget.org/packages/Newtonsoft.Json/) - 13.0.2 or later
- [JsonSubTypes](https://www.nuget.org/packages/JsonSubTypes/) - 1.8.0 or later
- [System.ComponentModel.Annotations](https://www.nuget.org/packages/System.ComponentModel.Annotations) - 5.0.0 or later

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:
```
Install-Package Newtonsoft.Json
Install-Package JsonSubTypes
Install-Package System.ComponentModel.Annotations
```
<a id="installation"></a>
## Installation
Run the following command to generate the DLL
- [Mac/Linux] `/bin/sh build.sh`
- [Windows] `build.bat`

Then include the DLL (under the `bin` folder) in the C# project, and use the namespaces:
```csharp
using Databox.Api;
using Databox.Client;
using Databox.Model;
```
<a id="packaging"></a>
## Packaging
The package is listed as **public** in our Databox Github repository. In order to consume it, you must first add a **nuget source**.

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.
Databox package repository url is: https://nuget.pkg.github.com/databox/index.json

This `.nuspec` uses placeholders from the `.csproj`, so build the `.csproj` directly:
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).

```
nuget pack -Build -OutputDirectory out Databox.csproj
```

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.
After this is completed, the package can be installed via IDE (package named **"Databox"**) or via **dotnet cli** command

<a id="usage"></a>
## Usage

To use the API client with a HTTP proxy, setup a `System.Net.WebProxy`
```csharp
Configuration c = new Configuration();
System.Net.WebProxy webProxy = new System.Net.WebProxy("http://myProxyUrl:80/");
webProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
c.Proxy = webProxy;
```

### Connections
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.

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.

```csharp
HttpClientHandler yourHandler = new HttpClientHandler();
HttpClient yourHttpClient = new HttpClient(yourHandler);
var api = new YourApiClass(yourHttpClient, yourHandler);
dotnet add package Databox --version <version>
```

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.
### Prerequisites

```csharp
HttpClient yourHttpClient = new HttpClient();
var api = new YourApiClass(yourHttpClient);
```
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.

Here an example of DI setup in a sample web project:

```csharp
services.AddHttpClient<YourApiClass>(httpClient =>
new PetApi(httpClient));
```
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.

### Example

<a id="getting-started"></a>
## Getting Started
The basic example of pushing data to Databox is provided below:

```csharp
using System.Collections.Generic;
using System.Diagnostics;
using System.Net.Http;
using Databox.Api;
using Databox.Client;
using Databox.Model;

namespace Example
{
public class Example
public class Example
{
public static async Task Main(string[] args)
{
public static void Main()
{

Configuration config = new Configuration();
config.BasePath = "https://push.databox.com";
// Configure HTTP basic authorization: basicAuth
config.Username = "YOUR_USERNAME";
config.Password = "YOUR_PASSWORD";

// create instances of HttpClient, HttpClientHandler to be reused later with different Api classes
HttpClient httpClient = new HttpClient();
HttpClientHandler httpClientHandler = new HttpClientHandler();
var apiInstance = new DefaultApi(httpClient, config, httpClientHandler);

try
{
apiInstance.DataDelete();
}
catch (ApiException e)
{
Debug.Print("Exception when calling DefaultApi.DataDelete: " + e.Message );
Debug.Print("Status Code: "+ e.ErrorCode);
Debug.Print(e.StackTrace);
}

Configuration config = new Configuration();
config.BasePath = "https://push.databox.com";
config.Username = "<Your_Databox_API_Token>";
config.DefaultHeaders.Add("Accept", "application/vnd.databox.v2+json");


HttpClient httpClient = new HttpClient();
HttpClientHandler httpClientHandler = new HttpClientHandler();
var apiInstance = new DefaultApi(httpClient, config, httpClientHandler);
var dataPostRequest = new List<PushData>() {
new PushData() {
Key = "<Metric_name>",
Value = 123,
Date = "<Date_in_ISO8601>",
Unit = "<Unit>", // Optional
Attributes = new List<PushDataAttribute>() { // Optional
new PushDataAttribute() {
Key = "<Dimension_name>",
Value = "<Dimension_value>"
}
}
}
};

try
{
var response = await apiInstance.DataPostWithHttpInfoAsync(dataPostRequest);
Console.WriteLine(response.Data.ToString());
}
catch (ApiException e)
{
Console.WriteLine("Exception when calling DefaultApi.DataPostWithHttpInfo: " + e.Message);
Console.WriteLine("Status Code: " + e.ErrorCode);
Console.WriteLine(e.StackTrace);
}
}
}
}
```

<a id="documentation-for-api-endpoints"></a>
## Documentation for API Endpoints

All URIs are relative to *https://push.databox.com*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*DefaultApi* | [**DataDelete**](docs/DefaultApi.md#datadelete) | **DELETE** /data |
*DefaultApi* | [**DataMetricKeyDelete**](docs/DefaultApi.md#datametrickeydelete) | **DELETE** /data/{metricKey} |
*DefaultApi* | [**DataPost**](docs/DefaultApi.md#datapost) | **POST** /data |
*DefaultApi* | [**MetrickeysGet**](docs/DefaultApi.md#metrickeysget) | **GET** /metrickeys |
*DefaultApi* | [**MetrickeysPost**](docs/DefaultApi.md#metrickeyspost) | **POST** /metrickeys |
*DefaultApi* | [**PingGet**](docs/DefaultApi.md#pingget) | **GET** /ping |


<a id="documentation-for-models"></a>
## Documentation for Models

- [Model.ApiResponse](docs/ApiResponse.md)
- [Model.PushData](docs/PushData.md)
- [Model.PushDataAttribute](docs/PushDataAttribute.md)
- [Model.State](docs/State.md)


<a id="documentation-for-authorization"></a>
## Documentation for Authorization


Authentication schemes defined for the API:
<a id="basicAuth"></a>
### basicAuth

- **Type**: HTTP basic authentication

0 comments on commit 3acc506

Please sign in to comment.