Пример #1
0
        public Client(Credentials credentials, IEnvironment env = null)
        {
            if (credentials == null)
            {
                throw new ArgumentNullException(nameof(credentials));
            }

            environment = env ?? Environments.Production;
            requester   = new Requester(credentials, environment, null, this.apiVersion);

            Account      = new AccountResource(requester);
            Balance      = new BalanceResource(requester);
            Charges      = new ChargeResource(requester);
            Customers    = new CustomerResource(requester);
            Disputes     = new DisputeResource(requester);
            Events       = new EventResource(requester);
            Forex        = new ForexResource(requester);
            Links        = new LinkResource(requester);
            Occurrences  = new OccurrenceResource(requester);
            Sources      = new PaymentSourceResource(requester);
            Receipts     = new ReceiptResource(requester);
            Recipients   = new RecipientResource(requester);
            Refunds      = new RefundResource(requester);
            Schedules    = new ScheduleResource(requester);
            Tokens       = new TokenResource(requester);
            Transactions = new TransactionResource(requester);
            Transfers    = new TransferResource(requester);
        }
Пример #2
0
        public override void Upgrade()
        {
            if (buildingLevel + 1 >= buildCost.Length)
            {
                throw new System.ArgumentException("Tried to upgrade past maximum building level");
            }
            // change spirte
            CityController city = FindObjectOfType <CityController>();

            city.Buy(buildCost[buildingLevel + 1].ResourceCost);
            city.DecreaseBalance(resourceGenerated[buildingLevel]);
            if (upkeepCost.Length != 0)
            {
                for (int i = 0; i < upkeepCost[buildingLevel].BalanceCost.Length; i++)
                {
                    BalanceResource bal = upkeepCost[buildingLevel].BalanceCost[i];
                    bal.resourceAmount = -bal.resourceAmount;
                    FindObjectOfType <CityController>().StrainBalance(bal);
                }
            }
            buildingLevel++;
            city.IncreaseBalance(resourceGenerated[buildingLevel]);
            if (upkeepCost.Length != 0)
            {
                FindObjectOfType <CityController>().StrainBalance(upkeepCost[buildingLevel].BalanceCost);
            }
        }
Пример #3
0
 public BalanceResource[] GetBalanceSummary()
 {
     BalanceResource[] bal = new BalanceResource[balanceAvailable.Length];
     for (int i = 0; i < balanceAvailable.Length; i++)
     {
         bal[i].resourceAmount = balanceAvailable[i].resourceAmount - balanceStrain[i].resourceAmount;
     }
     return(bal);
 }
Пример #4
0
 /// <summary>
 /// Increses balance.
 /// </summary>
 public void IncreaseBalance(BalanceResource increaseIncome)
 {
     for (int i = 0; i < balanceAvailable.Length; i++)
     {
         if (increaseIncome.resourceType == balanceAvailable[i].resourceType)
         {
             balanceAvailable[i].resourceAmount += increaseIncome.resourceAmount;
             break;
         }
     }
     UpdateUI();
 }
Пример #5
0
 /// <summary>
 /// Puts additional load on available ballance
 /// </summary>
 /// <param name="decreseBalance"></param>
 public void StrainBalance(BalanceResource decreseBalance)
 {
     for (int i = 0; i < balanceAvailable.Length; i++)
     {
         if (decreseBalance.resourceType == balanceAvailable[i].resourceType)
         {
             balanceStrain[i].resourceAmount += decreseBalance.resourceAmount;
             break;
         }
     }
     UpdateUI();
 }
Пример #6
0
 public override void PrepareRemoval()
 {
     if (upkeepCost.Length != 0)
     {
         for (int i = 0; i < upkeepCost[buildingLevel].BalanceCost.Length; i++)
         {
             BalanceResource bal = upkeepCost[buildingLevel].BalanceCost[i];
             bal.resourceAmount = -bal.resourceAmount;
             FindObjectOfType <CityController>().StrainBalance(bal);
         }
     }
 }
Пример #7
0
 public async Task <BalanceResource> GetAccountBalance()
 {
     try
     {
         return(await BalanceResource.FetchAsync(new FetchBalanceOptions
         {
             PathAccountSid = APIKeys.TwilioAccoutSid
         }, _client));
     }
     catch (Exception e)
     {
         _logger.LogError(e, e.InnerException?.Message);
         return(null);
     }
 }
        public void TestFetchResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.OK,
                         "{\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"balance\": \"0.05\",\"currency\": \"USD\"}"
                         ));

            var response = BalanceResource.Fetch(client: twilioRestClient);

            Assert.NotNull(response);
        }
Пример #9
0
        public Client(Credentials credentials) {
            if (credentials == null) throw new ArgumentNullException("credentials");
            requester = new Requester(credentials);

            Account = new AccountResource(requester);
            Balance = new BalanceResource(requester);
            Cards = new CardResourceShim(requester);
            Charges = new ChargeResource(requester);
            Customers = new CustomerResource(requester);
            Disputes = new DisputeResource(requester);
            Events = new EventResource(requester);
            Recipients = new RecipientResource(requester);
            Refunds = new RefundResourceShim(requester);
            Tokens = new TokenResource(requester);
            Transactions = new TransactionResource(requester);
            Transfers = new TransferResource(requester);
        }
        public void TestFetchRequest()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();
            var request          = new Request(
                HttpMethod.Get,
                Twilio.Rest.Domain.Api,
                "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Balance.json",
                ""
                );

            twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
            twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content"));

            try
            {
                BalanceResource.Fetch(client: twilioRestClient);
                Assert.Fail("Expected TwilioException to be thrown for 500");
            }
            catch (ApiException) {}
            twilioRestClient.Received().Request(request);
        }
Пример #11
0
        public Client(Credentials credentials)
        {
            if (credentials == null)
            {
                throw new ArgumentNullException(nameof(credentials));
            }
            requester = new Requester(credentials);

            Account      = new AccountResource(requester);
            Balance      = new BalanceResource(requester);
            Cards        = new CardResourceShim(requester);
            Charges      = new ChargeResource(requester);
            Customers    = new CustomerResource(requester);
            Disputes     = new DisputeResource(requester);
            Events       = new EventResource(requester);
            Links        = new LinkResource(requester);
            Recipients   = new RecipientResource(requester);
            Refunds      = new RefundResourceShim(requester);
            Tokens       = new TokenResource(requester);
            Transactions = new TransactionResource(requester);
            Transfers    = new TransferResource(requester);
        }