Compare commits
	
		
			3 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					cb511b1215 | ||
| 
						 | 
					ca886787ea | ||
| 
						 | 
					bfcc4833e1 | 
							
								
								
									
										100
									
								
								5sim_api/Api.cs
									
									
									
									
									
								
							
							
						
						
									
										100
									
								
								5sim_api/Api.cs
									
									
									
									
									
								
							@ -23,7 +23,13 @@ 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}";
 | 
				
			||||||
@ -120,94 +126,26 @@ 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)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            String uri = $"user/check/{id}";
 | 
					            return actionNumber("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)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            String uri = $"user/finish/{id}";
 | 
					            return actionNumber("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)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            String uri = $"user/cancel/{id}";
 | 
					            return actionNumber("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}");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        public Number banNumber(int id)
 | 
					        public Number banNumber(int id)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            String uri = $"user/ban/{id}";
 | 
					            return actionNumber("ban", id);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private Number actionNumber(string type, int id)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            String uri = $"user/{type}/{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}");
 | 
				
			||||||
@ -234,8 +172,6 @@ namespace YoutubeBot._5sim
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // ----------
 | 
					        // ----------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private static void checkAndThrowException(HttpStatusCode statusCode, string content)
 | 
					        private static void checkAndThrowException(HttpStatusCode statusCode, string content)
 | 
				
			||||||
@ -253,6 +189,10 @@ 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]
 | 
				
			||||||
    class HostingOrderException : Exception
 | 
					    public class HostingOrderException : Exception
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        public HostingOrderException()
 | 
					        public HostingOrderException()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
				
			|||||||
@ -5,7 +5,7 @@ using System.Text;
 | 
				
			|||||||
namespace YoutubeBot._5sim.Exceptions
 | 
					namespace YoutubeBot._5sim.Exceptions
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    [Serializable]
 | 
					    [Serializable]
 | 
				
			||||||
    class NoFreePhonesException : Exception
 | 
					    public class NoFreePhonesException : Exception
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        public NoFreePhonesException()
 | 
					        public NoFreePhonesException()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
				
			|||||||
@ -5,7 +5,7 @@ using System.Text;
 | 
				
			|||||||
namespace YoutubeBot._5sim.Exceptions
 | 
					namespace YoutubeBot._5sim.Exceptions
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    [Serializable]
 | 
					    [Serializable]
 | 
				
			||||||
    class NotEnoughProductQuantityException : Exception
 | 
					    public class NotEnoughProductQuantityException : Exception
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        public NotEnoughProductQuantityException()
 | 
					        public NotEnoughProductQuantityException()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
				
			|||||||
@ -5,7 +5,7 @@ using System.Text;
 | 
				
			|||||||
namespace YoutubeBot._5sim.Exceptions
 | 
					namespace YoutubeBot._5sim.Exceptions
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    [Serializable]
 | 
					    [Serializable]
 | 
				
			||||||
    class NotEnoughRatingException : Exception
 | 
					    public class NotEnoughRatingException : Exception
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        public NotEnoughRatingException()
 | 
					        public NotEnoughRatingException()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
				
			|||||||
@ -5,7 +5,7 @@ using System.Text;
 | 
				
			|||||||
namespace YoutubeBot._5sim.Exceptions
 | 
					namespace YoutubeBot._5sim.Exceptions
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    [Serializable]
 | 
					    [Serializable]
 | 
				
			||||||
    class NotEnoughUserBalanceException : Exception
 | 
					    public class NotEnoughUserBalanceException : Exception
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        public NotEnoughUserBalanceException()
 | 
					        public NotEnoughUserBalanceException()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
				
			|||||||
@ -5,7 +5,7 @@ using System.Text;
 | 
				
			|||||||
namespace YoutubeBot._5sim.Exceptions
 | 
					namespace YoutubeBot._5sim.Exceptions
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    [Serializable]
 | 
					    [Serializable]
 | 
				
			||||||
    class OrderExpiredException : Exception
 | 
					    public class OrderExpiredException : Exception
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        public OrderExpiredException()
 | 
					        public OrderExpiredException()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
				
			|||||||
@ -5,7 +5,7 @@ using System.Text;
 | 
				
			|||||||
namespace YoutubeBot._5sim.Exceptions
 | 
					namespace YoutubeBot._5sim.Exceptions
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    [Serializable]
 | 
					    [Serializable]
 | 
				
			||||||
    class OrderHasSmsException : Exception
 | 
					    public class OrderHasSmsException : Exception
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        public OrderHasSmsException()
 | 
					        public OrderHasSmsException()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
				
			|||||||
@ -5,7 +5,7 @@ using System.Text;
 | 
				
			|||||||
namespace YoutubeBot._5sim.Exceptions
 | 
					namespace YoutubeBot._5sim.Exceptions
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    [Serializable]
 | 
					    [Serializable]
 | 
				
			||||||
    class OrderNotFoundException : Exception
 | 
					    public class OrderNotFoundException : Exception
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        public OrderNotFoundException()
 | 
					        public OrderNotFoundException()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user