-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from StackPointCloud/nuget-packge
updated SDK with latest API operations
- Loading branch information
Showing
95 changed files
with
7,383 additions
and
4,770 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using Newtonsoft.Json; | ||
using OneAndOne.POCO.Response.Common; | ||
using RestSharp; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace OneAndOne.Client.Endpoints.Common | ||
{ | ||
public class Common : ResourceBase | ||
{ | ||
public Common(object _apiUrl = null, object _apiKey = null) | ||
: base(_apiUrl, _apiKey) { } | ||
/// <summary> | ||
/// Returns prices for all available resources in Cloud Panel | ||
/// </summary> | ||
public PricingResponse GetPricing() | ||
{ | ||
try | ||
{ | ||
var request = new RestRequest("/pricing", Method.GET); | ||
|
||
var result = restclient.Execute(request); | ||
if (result.StatusCode != HttpStatusCode.OK) | ||
{ | ||
throw new Exception(result.Content); | ||
} | ||
return JsonConvert.DeserializeObject<PricingResponse>(result.Content); | ||
} | ||
catch | ||
{ | ||
throw; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Returns true if the API is running | ||
/// </summary> | ||
public bool Ping() | ||
{ | ||
try | ||
{ | ||
bool value = false; | ||
var request = new RestRequest("/ping", Method.GET); | ||
|
||
var result = restclient.Execute(request); | ||
if (result.StatusCode != HttpStatusCode.OK) | ||
{ | ||
return value; | ||
} | ||
if (result.Content == "[\"PONG\"]") | ||
{ value = true; } | ||
return value; | ||
} | ||
catch | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Returns true if the API is running and the token is valid | ||
/// </summary> | ||
public bool PingAuthentication() | ||
{ | ||
try | ||
{ | ||
bool value = false; | ||
var request = new RestRequest("/ping_auth", Method.GET); | ||
|
||
var result = restclient.Execute(request); | ||
if (result.StatusCode != HttpStatusCode.OK) | ||
{ | ||
return value; | ||
} | ||
if (result.Content == "[\"PONG\"]") | ||
{ value = true; } | ||
return value; | ||
} | ||
catch | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using Newtonsoft.Json; | ||
using OneAndOne.POCO.Response.DataCenters; | ||
using RestSharp; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace OneAndOne.Client.Endpoints.DataCenter | ||
{ | ||
public class DataCenters : ResourceBase | ||
{ | ||
public DataCenters(object _apiUrl = null, object _apiKey = null) | ||
: base(_apiUrl, _apiKey) { } | ||
/// <summary> | ||
/// Returns information about available datacenters to create your resources. | ||
/// </summary> | ||
/// <param name="page">Allows to use pagination. Sets the number of servers that will be shown in each page.</param> | ||
/// <param name="perPage">Current page to show.</param> | ||
/// <param name="sort">Allows to sort the result by priority:sort=name retrieves a list of elements ordered by their names.sort=-creation_date retrieves a list of elements ordered according to their creation date in descending order of priority.</param> | ||
/// <param name="query">Allows to search one string in the response and return the elements that contain it. In order to specify the string use parameter q: q=My server</param> | ||
/// <param name="fields">Returns only the parameters requested: fields=id,name,description,hardware.ram</param> | ||
public List<DataCenterResponse> Get(int? page = null, int? perPage = null, string sort = null, string query = null, string fields = null) | ||
{ | ||
try | ||
{ | ||
string requestUrl = "/datacenters?"; | ||
if (page != null) | ||
{ | ||
requestUrl += string.Format("&page={0}", page); | ||
} | ||
if (perPage != null) | ||
{ | ||
requestUrl += string.Format("&per_page={0}", perPage); | ||
} | ||
if (!string.IsNullOrEmpty(sort)) | ||
{ | ||
requestUrl += string.Format("&sort={0}", sort); | ||
} | ||
if (!string.IsNullOrEmpty(query)) | ||
{ | ||
requestUrl += string.Format("&q={0}", query); | ||
} | ||
if (!string.IsNullOrEmpty(fields)) | ||
{ | ||
requestUrl += string.Format("&fields={0}", fields); | ||
} | ||
var request = new RestRequest(requestUrl, Method.GET); | ||
|
||
var result = restclient.Execute(request); | ||
if (result.StatusCode != HttpStatusCode.OK) | ||
{ | ||
throw new Exception(result.Content); | ||
} | ||
return JsonConvert.DeserializeObject<List<DataCenterResponse>>(result.Content); | ||
} | ||
catch | ||
{ | ||
throw; | ||
} | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Returns information about a datacenter | ||
/// </summary> | ||
/// <param name="id">Appliance's ID</param> | ||
/// | ||
public DataCenterResponse Show(string id) | ||
{ | ||
try | ||
{ | ||
var request = new RestRequest("/datacenters/{id}", Method.GET); | ||
request.AddUrlSegment("id", id); | ||
|
||
var result = restclient.Execute<DataCenterResponse>(request); | ||
if (result.StatusCode != HttpStatusCode.OK) | ||
{ | ||
throw new Exception(result.Content); | ||
} | ||
return result.Data; | ||
} | ||
catch | ||
{ | ||
throw; | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.