Skip to content

Commit

Permalink
Merge pull request #9 from StackPointCloud/nuget-packge
Browse files Browse the repository at this point in the history
updated SDK with latest API operations
  • Loading branch information
alibazlamit authored May 9, 2017
2 parents a28aeb0 + d7b9de5 commit 79b4a66
Show file tree
Hide file tree
Showing 95 changed files with 7,383 additions and 4,770 deletions.
90 changes: 90 additions & 0 deletions OneAndOne.Client/Endpoints/Common/Common.cs
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;
}
}

}
}
92 changes: 92 additions & 0 deletions OneAndOne.Client/Endpoints/DataCenter/DataCenters.cs
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;
}
}
}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OneAndOne.Client.RESTHelpers;
using Newtonsoft.Json;
using OneAndOne.Client.RESTHelpers;
using OneAndOne.POCO.Requests.FirewallPolicies;
using OneAndOne.POCO.Response;
using RestSharp;
Expand Down Expand Up @@ -51,12 +52,12 @@ public List<FirewallPolicyResponse> Get(int? page = null, int? perPage = null, s
}
var request = new RestRequest(requestUrl, Method.GET);

var result = restclient.Execute<List<FirewallPolicyResponse>>(request);
var result = restclient.Execute(request);
if (result.StatusCode != HttpStatusCode.OK)
{
throw new Exception(result.Content);
}
return result.Data;
return JsonConvert.DeserializeObject<List<FirewallPolicyResponse>>(result.Content);
}
catch
{
Expand Down
2 changes: 1 addition & 1 deletion OneAndOne.Client/Endpoints/Logs/Logs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public List<LogsResponse> Get(PeriodType period, int? page = null, int? perPage
/// <summary>
/// Returns information about a log
/// </summary>
/// <param name="log_id">Unique monitoring policy's identifier.</param>
/// <param name="log_id">Unique log's identifier.</param>
///
public LogsResponse Show(string log_id)
{
Expand Down
Loading

0 comments on commit 79b4a66

Please sign in to comment.