|
|
|
@ -23,13 +23,7 @@ namespace YoutubeBot._5sim
|
|
|
|
|
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")
|
|
|
|
|
{
|
|
|
|
|
String uri = $"guest/products/{country}/{carrier}";
|
|
|
|
@ -126,26 +120,94 @@ namespace YoutubeBot._5sim
|
|
|
|
|
throw new InvalidOperationException($"Invalid response: {response.StatusCode}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
return actionNumber("cancel", id);
|
|
|
|
|
}
|
|
|
|
|
public Number banNumber(int id)
|
|
|
|
|
{
|
|
|
|
|
return actionNumber("ban", id);
|
|
|
|
|
String uri = $"user/cancel/{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}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
request.AddHeader("Authorization", $"Bearer {token}");
|
|
|
|
@ -172,6 +234,8 @@ namespace YoutubeBot._5sim
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
|
|
|
|
|
|
private static void checkAndThrowException(HttpStatusCode statusCode, string content)
|
|
|
|
@ -189,10 +253,6 @@ namespace YoutubeBot._5sim
|
|
|
|
|
case HttpStatusCode.BadRequest:
|
|
|
|
|
switch (content)
|
|
|
|
|
{
|
|
|
|
|
// Api had responded with 400 instead of 404
|
|
|
|
|
case "order not found":
|
|
|
|
|
throw new OrderNotFoundException();
|
|
|
|
|
|
|
|
|
|
case "not enough product qty":
|
|
|
|
|
throw new NotEnoughProductQuantityException();
|
|
|
|
|
|
|
|
|
|