Compare commits

..

No commits in common. 'master' and '1.0.0' have entirely different histories.

@ -3,7 +3,6 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>_5sim_api</RootNamespace> <RootNamespace>_5sim_api</RootNamespace>
<Version>1.0.1</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

@ -23,13 +23,7 @@ namespace YoutubeBot._5sim
this.token = token; this.token = token;
} }
/// <summary>
/// Get a given service
/// </summary>
/// <param name="service_name">Name of service (e.g. 'google')</param>
/// <param name="country">Country of service (Default is 'any')</param>
/// <param name="carrier">Carrier of service (Default is 'any')</param>
/// <returns></returns>
public Service getService(string service_name, string country = "any", string carrier = "any") public Service getService(string service_name, string country = "any", string carrier = "any")
{ {
String uri = $"guest/products/{country}/{carrier}"; String uri = $"guest/products/{country}/{carrier}";
@ -126,26 +120,94 @@ namespace YoutubeBot._5sim
throw new InvalidOperationException($"Invalid response: {response.StatusCode}"); throw new InvalidOperationException($"Invalid response: {response.StatusCode}");
} }
public Number checkNumber(int id) public Number checkNumber(int id)
{ {
return actionNumber("check", id); String uri = $"user/check/{id}";
RestRequest request = new RestRequest(uri, Method.GET);
request.AddHeader("Authorization", $"Bearer {token}");
IRestResponse response = client.Execute(request);
// Client-error handling
Exception ex = response.ErrorException;
if (ex != null) throw ex;
// Check for expected errors and throw the corresponding exception of necessary
checkAndThrowException(response.StatusCode, response.Content);
if (response.StatusCode == HttpStatusCode.OK)
{
JObject activationNumber_json = (JObject)JsonConvert.DeserializeObject(response.Content);
Number activationNumber = activationNumber_json.ToObject<Number>();
activationNumber.carrier = (string)activationNumber_json["operator"];
return activationNumber;
}
else
throw new InvalidOperationException($"Invalid response: {response.StatusCode}");
} }
public Number finishNumber(int id) public Number finishNumber(int id)
{ {
return actionNumber("finish", id); String uri = $"user/finish/{id}";
RestRequest request = new RestRequest(uri, Method.GET);
request.AddHeader("Authorization", $"Bearer {token}");
IRestResponse response = client.Execute(request);
// Client-error handling
Exception ex = response.ErrorException;
if (ex != null) throw ex;
// Check for expected errors and throw the corresponding exception of necessary
checkAndThrowException(response.StatusCode, response.Content);
if (response.StatusCode == HttpStatusCode.OK)
{
JObject activationNumber_json = (JObject)JsonConvert.DeserializeObject(response.Content);
Number activationNumber = activationNumber_json.ToObject<Number>();
activationNumber.carrier = (string)activationNumber_json["operator"];
return activationNumber;
} }
else
throw new InvalidOperationException($"Invalid response: {response.StatusCode}");
}
public Number cancelNumber(int id) public Number cancelNumber(int id)
{ {
return actionNumber("cancel", id); String uri = $"user/cancel/{id}";
} RestRequest request = new RestRequest(uri, Method.GET);
public Number banNumber(int id)
request.AddHeader("Authorization", $"Bearer {token}");
IRestResponse response = client.Execute(request);
// Client-error handling
Exception ex = response.ErrorException;
if (ex != null) throw ex;
// Check for expected errors and throw the corresponding exception of necessary
checkAndThrowException(response.StatusCode, response.Content);
if (response.StatusCode == HttpStatusCode.OK)
{ {
return actionNumber("ban", id); JObject activationNumber_json = (JObject)JsonConvert.DeserializeObject(response.Content);
Number activationNumber = activationNumber_json.ToObject<Number>();
activationNumber.carrier = (string)activationNumber_json["operator"];
return activationNumber;
}
else
throw new InvalidOperationException($"Invalid response: {response.StatusCode}");
} }
private Number actionNumber(string type, int id) public Number banNumber(int id)
{ {
String uri = $"user/{type}/{id}"; String uri = $"user/ban/{id}";
RestRequest request = new RestRequest(uri, Method.GET); RestRequest request = new RestRequest(uri, Method.GET);
request.AddHeader("Authorization", $"Bearer {token}"); request.AddHeader("Authorization", $"Bearer {token}");
@ -172,6 +234,8 @@ namespace YoutubeBot._5sim
} }
// ---------- // ----------
private static void checkAndThrowException(HttpStatusCode statusCode, string content) private static void checkAndThrowException(HttpStatusCode statusCode, string content)
@ -189,10 +253,6 @@ namespace YoutubeBot._5sim
case HttpStatusCode.BadRequest: case HttpStatusCode.BadRequest:
switch (content) switch (content)
{ {
// Api had responded with 400 instead of 404
case "order not found":
throw new OrderNotFoundException();
case "not enough product qty": case "not enough product qty":
throw new NotEnoughProductQuantityException(); throw new NotEnoughProductQuantityException();

@ -5,7 +5,7 @@ using System.Text;
namespace YoutubeBot._5sim.Exceptions namespace YoutubeBot._5sim.Exceptions
{ {
[Serializable] [Serializable]
public class HostingOrderException : Exception class HostingOrderException : Exception
{ {
public HostingOrderException() public HostingOrderException()
{ {

@ -5,7 +5,7 @@ using System.Text;
namespace YoutubeBot._5sim.Exceptions namespace YoutubeBot._5sim.Exceptions
{ {
[Serializable] [Serializable]
public class NoFreePhonesException : Exception class NoFreePhonesException : Exception
{ {
public NoFreePhonesException() public NoFreePhonesException()
{ {

@ -5,7 +5,7 @@ using System.Text;
namespace YoutubeBot._5sim.Exceptions namespace YoutubeBot._5sim.Exceptions
{ {
[Serializable] [Serializable]
public class NotEnoughProductQuantityException : Exception class NotEnoughProductQuantityException : Exception
{ {
public NotEnoughProductQuantityException() public NotEnoughProductQuantityException()
{ {

@ -5,7 +5,7 @@ using System.Text;
namespace YoutubeBot._5sim.Exceptions namespace YoutubeBot._5sim.Exceptions
{ {
[Serializable] [Serializable]
public class NotEnoughRatingException : Exception class NotEnoughRatingException : Exception
{ {
public NotEnoughRatingException() public NotEnoughRatingException()
{ {

@ -5,7 +5,7 @@ using System.Text;
namespace YoutubeBot._5sim.Exceptions namespace YoutubeBot._5sim.Exceptions
{ {
[Serializable] [Serializable]
public class NotEnoughUserBalanceException : Exception class NotEnoughUserBalanceException : Exception
{ {
public NotEnoughUserBalanceException() public NotEnoughUserBalanceException()
{ {

@ -5,7 +5,7 @@ using System.Text;
namespace YoutubeBot._5sim.Exceptions namespace YoutubeBot._5sim.Exceptions
{ {
[Serializable] [Serializable]
public class OrderExpiredException : Exception class OrderExpiredException : Exception
{ {
public OrderExpiredException() public OrderExpiredException()
{ {

@ -5,7 +5,7 @@ using System.Text;
namespace YoutubeBot._5sim.Exceptions namespace YoutubeBot._5sim.Exceptions
{ {
[Serializable] [Serializable]
public class OrderHasSmsException : Exception class OrderHasSmsException : Exception
{ {
public OrderHasSmsException() public OrderHasSmsException()
{ {

@ -5,7 +5,7 @@ using System.Text;
namespace YoutubeBot._5sim.Exceptions namespace YoutubeBot._5sim.Exceptions
{ {
[Serializable] [Serializable]
public class OrderNotFoundException : Exception class OrderNotFoundException : Exception
{ {
public OrderNotFoundException() public OrderNotFoundException()
{ {

@ -10,7 +10,7 @@ namespace YoutubeBot._5sim.Objects
public int id; public int id;
/// <summary>The phone-number</summary> /// <summary>The phone-number</summary>
public string phone; public string number;
/// <summary>The recieved sms (Activation only has 1 sms)</summary> /// <summary>The recieved sms (Activation only has 1 sms)</summary>
public List<Sms> sms; public List<Sms> sms;

@ -1,12 +0,0 @@
# 5sim.net Api Library
This is a library to use the official 5sim Api.
## Installation
Import the .dll into your project.
## Usage
Create a new `_5sim.Api`.
Within the constructor-method you pass your api-token from 5sim.
## How to use it
I am mostly following the official Api from 5sim,
therefore you should have a look at their Api: https://5sim.net/docs/api_en.txt?68dc38df57 (24.02.2020)
Loading…
Cancel
Save