Пример #1
0
        /// <summary>
        /// Informações do evento
        /// </summary>
        /// <param name="id">id do evento</param>
        /// <returns>Obtêm informações do evento</returns>
        /// <see cref="http://api.boletosimples.com.br/reference/v1/events/#informações-do-evento"/>
        public async Task <ApiResponse <EventData> > GetAsync(int id)
        {
            var request = _requestBuilder.To(_client.Connection.GetBaseUri(), $"{EVENTS_API}/{id}")
                          .WithMethod(HttpMethod.Get)
                          .Build();

            return(await _client.SendAsync <EventData>(request));
        }
Пример #2
0
        /// <summary>
        /// Enviar CNAB
        /// </summary>
        /// <param name="fileName">nome do arquivo</param>
        /// <param name="file">conteudo do arquivo</param>
        /// <see cref="http://api.boletosimples.com.br/reference/v1/discharges/#enviar-cnab"/>
        /// <returns>Modelo que representa o arquivo de retorno</returns>
        public async Task <ApiResponse <Discharge> > PostAsync(string fileName, Stream file)
        {
            var request = _requestBuilder.To(_client.Connection.GetBaseUri(), DISCHARGE_API)
                          .WithMethod(HttpMethod.Post)
                          .AppendFileContent("discharge[file]", fileName, file)
                          .Build();

            return(await _client.SendAsync <Discharge>(request));
        }
Пример #3
0
        /// <summary>
        /// Cria um carnê
        /// </summary>
        /// <param name="installment">dados do carne</param>
        /// <returns>Carnê criado com sucesso</returns>
        /// <see cref="http://api.boletosimples.com.br/reference/v1/installments/#criar-carnê"/>
        public async Task <ApiResponse <Installment> > PostAsync(Installment installment)
        {
            var request = _requestBuilder.To(_client.Connection.GetBaseUri(), INSTALLMENTS_API)
                          .WithMethod(HttpMethod.Post)
                          .AndOptionalContent(installment)
                          .Build();

            return(await _client.SendAsync <Installment>(request));
        }
Пример #4
0
        /// <summary>
        /// Criar CNAB(Remessa)
        /// </summary>
        /// <param name="remittance">nome do arquivo</param>
        /// <see cref="http://api.boletosimples.com.br/reference/v1/remittances/#criar-cnab"/>
        /// <returns>Modelo que representa o arquivo de remessa</returns>
        public async Task <ApiResponse <Remittance> > PostAsync(Remittance remittance)
        {
            var request = _requestBuilder.To(_client.Connection.GetBaseUri(), REMITTANCE_API)
                          .WithMethod(HttpMethod.Post)
                          .AndOptionalContent(remittance)
                          .Build();

            return(await _client.SendAsync <Remittance>(request));
        }
Пример #5
0
        /// <summary>
        /// Cria um boleto
        /// </summary>
        /// <param name="bankBillet">dados do boleto</param>
        /// <returns>Boleto criado com sucesso</returns>
        /// <see cref="http://api.boletosimples.com.br/reference/v1/bank_billets/#criar-boleto"/>
        public async Task <ApiResponse <BankBillet> > PostAsync(BankBillet bankBillet)
        {
            var request = _requestBuilder.To(_client.Connection.GetBaseUri(), BANK_BILLET_API)
                          .WithMethod(HttpMethod.Post)
                          .AndOptionalContent(bankBillet)
                          .Build();

            return(await _client.SendAsync <BankBillet>(request));
        }
Пример #6
0
        // TODO: Implementar fluxo com OAuth

        /*
         * public async Task<ApiResponse<UserInfoResponseMessage>> GetOAuthToken()
         * {
         *  var request = _requestBuilder.To(new Uri("http://locahost"))
         *                               .WithMethod(HttpMethod.Get)
         *                               .AndOptionalContent(new StringContent(""))
         *                               .Build();
         *
         *  return await _client.SendAsync<UserInfoResponseMessage>(request);
         * }
         */

        /// <summary>
        /// Obtem informação do usuário pelo token de acesso
        /// </summary>
        /// <returns>Informações gerais do usuário</returns>
        /// <see cref="http://api.boletosimples.com.br/authentication/token/"/>
        public async Task <ApiResponse <UserInfo> > GetUserInfoAsync()
        {
            var request = _requestBuilder.To(_client.Connection.GetBaseUri(), "/userinfo")
                          .WithMethod(HttpMethod.Get)
                          .Build();

            return(await _client.SendAsync <UserInfo>(request));
        }
Пример #7
0
        public async Task Build_a_complex_http_request_message_with_json_body_custom_header_and_query_string()
        {
            // Arrange and Act
            var buildedRequestMessage = Builder.To(new Uri("http://any-uri.io"), "any-resource")
                                        .WithMethod(HttpMethod.Post)
                                        .AndOptionalContent(new { AnyContent = "Any Content" })
                                        .AppendQuery(new Dictionary <string, string> {
                ["query"] = "any"
            })
                                        .AditionalHeaders(new Dictionary <string, string> {
                ["My-Header"] = "Any Value"
            })
                                        .Build();

            var content = await buildedRequestMessage.Content.ReadAsStringAsync().ConfigureAwait(false);

            // Assert
            Assert.That(buildedRequestMessage.RequestUri, Is.EqualTo(new Uri("http://any-uri.io/any-resource?query=any")));
            Assert.That(buildedRequestMessage.Method, Is.EqualTo(HttpMethod.Post));
            Assert.That(content, Does.Contain("Any Content"));
            Assert.That(buildedRequestMessage.Headers.Authorization, Is.Not.Null);
            Assert.That(buildedRequestMessage.Headers.GetValues("My-Header").First(), Is.EqualTo("Any Value"));
        }
Пример #8
0
        /// <summary>
        /// Cria uma assinatura
        /// </summary>
        /// <param name="customerSubscription">dados da assinatura</param>
        /// <returns>Assinatura criada com sucesso</returns>
        /// <see cref="http://api.boletosimples.com.br/reference/v1/customer_subscriptions/#criar-assinatura"/>
        public async Task <ApiResponse <CustomerSubscription> > PostAsync(CustomerSubscription customerSubscription)
        {
            var request = _requestBuilder.To(_client.Connection.GetBaseUri(), CUSTOMER_SUBSCRIPTION_API)
                          .WithMethod(HttpMethod.Post)
                          .AndOptionalContent(customerSubscription)
                          .Build();

            return(await _client.SendAsync <CustomerSubscription>(request));
        }