boletosimples 0.0.7 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- data/README.md +156 -3
- data/boletosimples.gemspec +9 -9
- data/lib/boletosimples.rb +38 -4
- data/lib/boletosimples/configuration.rb +69 -0
- data/lib/boletosimples/extra.rb +8 -0
- data/lib/boletosimples/last_request.rb +43 -0
- data/lib/boletosimples/middlewares/last_request.rb +9 -0
- data/lib/boletosimples/middlewares/raise_error.rb +11 -0
- data/lib/boletosimples/middlewares/user_agent.rb +10 -0
- data/lib/boletosimples/resources/bank_billet.rb +13 -0
- data/lib/boletosimples/resources/base_model.rb +8 -0
- data/lib/boletosimples/resources/customer.rb +4 -0
- data/lib/boletosimples/resources/partner/user.rb +7 -0
- data/lib/boletosimples/resources/transaction.rb +4 -0
- data/lib/boletosimples/response_error.rb +43 -0
- data/lib/boletosimples/version.rb +1 -1
- data/spec/boletosimples/configuration_spec.rb +84 -0
- data/spec/boletosimples/extra_spec.rb +31 -0
- data/spec/boletosimples/last_request_spec.rb +34 -0
- data/spec/boletosimples/resources/bank_billet_spec.rb +75 -0
- data/spec/boletosimples/resources/customer_spec.rb +66 -0
- data/spec/boletosimples/resources/partner/user_spec.rb +19 -0
- data/spec/boletosimples/resources/transactions_spec.rb +17 -0
- data/spec/fixtures/vcr_cassettes/configuration/client_credentials/invalid.yml +64 -0
- data/spec/fixtures/vcr_cassettes/configuration/client_credentials/valid.yml +56 -0
- data/spec/fixtures/vcr_cassettes/extra/userinfo/authenticated.yml +58 -0
- data/spec/fixtures/vcr_cassettes/extra/userinfo/not_authenticated.yml +54 -0
- data/spec/fixtures/vcr_cassettes/last_request/bank_billets.yml +129 -0
- data/spec/fixtures/vcr_cassettes/last_request/userinfo.yml +58 -0
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/all.yml +132 -0
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/cancel.yml +125 -0
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/invalid_params.yml +61 -0
- data/spec/fixtures/vcr_cassettes/{BoletoSimples_Client/_cancel_bank_billet/already_canceled.yml → resources/bank_billet/create/invalid_root.yml} +24 -24
- data/spec/fixtures/vcr_cassettes/{BoletoSimples_Client/_create_bank_billet/with_valid_data.yml → resources/bank_billet/create/valid.yml} +32 -28
- data/spec/fixtures/vcr_cassettes/{BoletoSimples_Client/_bank_billet/existing_bank_billet.yml → resources/bank_billet/find.yml} +30 -28
- data/spec/fixtures/vcr_cassettes/resources/customer/all.yml +72 -0
- data/spec/fixtures/vcr_cassettes/resources/customer/create/invalid_params.yml +59 -0
- data/spec/fixtures/vcr_cassettes/resources/customer/create/invalid_root.yml +58 -0
- data/spec/fixtures/vcr_cassettes/{BoletoSimples_Client/_create_customer/with_valid_data.yml → resources/customer/create/valid.yml} +30 -26
- data/spec/fixtures/vcr_cassettes/resources/customer/find.yml +59 -0
- data/spec/fixtures/vcr_cassettes/resources/partner/user/create.yml +60 -0
- data/spec/fixtures/vcr_cassettes/resources/transaction/all.yml +62 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/support/vcr.rb +8 -0
- metadata +97 -80
- data/example/access_token_example.rb +0 -79
- data/example/oauth_example.rb +0 -126
- data/lib/boletosimples/client.rb +0 -100
- data/lib/boletosimples/oauth_client.rb +0 -74
- data/spec/boletosimples/client_spec.rb +0 -415
- data/spec/boletosimples/oauth_client_spec.rb +0 -17
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_bank_billet/not_found.yml +0 -44
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_bank_billets.yml +0 -63
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_cancel_bank_billet/with_invalid_bank_billet.yml +0 -54
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_cancel_bank_billet/with_valid_bank_billet.yml +0 -71
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_create_bank_billet/with_invalid_data.yml +0 -64
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_create_customer/with_invalid_data.yml +0 -59
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_customer/existing_customer.yml +0 -57
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_customer/not_found.yml +0 -58
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_customers.yml +0 -59
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_transactions.yml +0 -67
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_userinfo/with_authentication.yml +0 -56
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_userinfo/with_authentication/.yml +0 -56
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_userinfo/without_authentication.yml +0 -54
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_userinfo/without_authentication/.yml +0 -54
- data/spec/fixtures/vcr_cassettes/BoletoSimples_OAuthClient/_userinfo/without_authentication/.yml +0 -62
@@ -0,0 +1,43 @@
|
|
1
|
+
module BoletoSimples
|
2
|
+
# BoletoSimples::ResponseError
|
3
|
+
# Exception that gets raised if the response is an error (4xx or 5xx)
|
4
|
+
#
|
5
|
+
# Formats a readable error message including HTTP status, method and requested URL
|
6
|
+
#
|
7
|
+
# Examples:
|
8
|
+
#
|
9
|
+
# BoletoSimples::BankBillet.all
|
10
|
+
# BoletoSimples::ResponseError: 401 POST https://sandbox.boletosimples.com.br/api/v1/bank_billets
|
11
|
+
#
|
12
|
+
# begin
|
13
|
+
# BoletoSimples::BankBillet.all
|
14
|
+
# rescue BoletoSimples::ResponseError => response
|
15
|
+
# response.status # => 401
|
16
|
+
# response.method # => "GET"
|
17
|
+
# response.url # => "https://sandbox.boletosimples.com.br/api/v1/bank_billets"
|
18
|
+
# response.body # => "{"error":"Você precisa se logar ou registrar antes de prosseguir."}"
|
19
|
+
# response.error_message # => "Você precisa se logar ou registrar antes de prosseguir."
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
class ResponseError < StandardError
|
23
|
+
attr_reader :response, :body, :status, :method, :url, :error_message
|
24
|
+
|
25
|
+
def initialize(response = nil)
|
26
|
+
@response = response
|
27
|
+
|
28
|
+
@body = response[:body][:data]
|
29
|
+
@status = response[:status].to_i
|
30
|
+
@method = response[:method].to_s.upcase
|
31
|
+
@url = response[:url]
|
32
|
+
@error_message = @body[:error]
|
33
|
+
|
34
|
+
super
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_s
|
38
|
+
msg = "#{status} #{method} #{url}"
|
39
|
+
msg << " (#{error_message})" unless error_message.blank?
|
40
|
+
msg
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
RSpec.describe BoletoSimples::Configuration do
|
5
|
+
describe 'defaults' do
|
6
|
+
before {
|
7
|
+
allow(ENV).to receive(:[]).with('BOLETOSIMPLES_ENV').and_return(nil)
|
8
|
+
allow(ENV).to receive(:[]).with('BOLETOSIMPLES_APP_ID').and_return(nil)
|
9
|
+
allow(ENV).to receive(:[]).with('BOLETOSIMPLES_APP_SECRET').and_return(nil)
|
10
|
+
allow(ENV).to receive(:[]).with('BOLETOSIMPLES_ACCESS_TOKEN').and_return(nil)
|
11
|
+
}
|
12
|
+
subject { BoletoSimples::Configuration.new }
|
13
|
+
it { expect(subject.environment).to eq(:sandbox) }
|
14
|
+
it { expect(subject.base_uri).to eq('https://sandbox.boletosimples.com.br/api/v1') }
|
15
|
+
it { expect(subject.application_id).to be_nil }
|
16
|
+
it { expect(subject.application_secret).to be_nil }
|
17
|
+
it { expect(subject.access_token).to be_nil }
|
18
|
+
it { expect(subject.cache).to be_nil }
|
19
|
+
it { expect(subject).not_to be_access_token }
|
20
|
+
end
|
21
|
+
describe 'environment variables' do
|
22
|
+
before {
|
23
|
+
allow(ENV).to receive(:[]).with('BOLETOSIMPLES_ENV').and_return('production')
|
24
|
+
allow(ENV).to receive(:[]).with('BOLETOSIMPLES_APP_ID').and_return('app-id')
|
25
|
+
allow(ENV).to receive(:[]).with('BOLETOSIMPLES_APP_SECRET').and_return('app-secret')
|
26
|
+
allow(ENV).to receive(:[]).with('BOLETOSIMPLES_ACCESS_TOKEN').and_return('access-token')
|
27
|
+
}
|
28
|
+
subject { BoletoSimples::Configuration.new }
|
29
|
+
it { expect(subject.environment).to eq(:production) }
|
30
|
+
it { expect(subject.base_uri).to eq('https://boletosimples.com.br/api/v1') }
|
31
|
+
it { expect(subject.application_id).to eq('app-id') }
|
32
|
+
it { expect(subject.application_secret).to eq('app-secret') }
|
33
|
+
it { expect(subject.access_token).to eq('access-token') }
|
34
|
+
it { expect(subject).to be_access_token }
|
35
|
+
describe 'cache' do
|
36
|
+
it { expect(subject.cache).to be_nil }
|
37
|
+
it { expect(Her::API.default_api.connection.builder.handlers).not_to include(Faraday::HttpCache) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
describe 'configuration' do
|
41
|
+
let(:cache_object) { double('Dalli') }
|
42
|
+
before {
|
43
|
+
BoletoSimples.configure do |c|
|
44
|
+
c.environment = :production
|
45
|
+
c.application_id = 'app-id'
|
46
|
+
c.application_secret = 'app-secret'
|
47
|
+
c.access_token = 'access-token'
|
48
|
+
c.cache = cache_object
|
49
|
+
end
|
50
|
+
}
|
51
|
+
subject { BoletoSimples.configuration }
|
52
|
+
it { expect(subject.environment).to eq(:production) }
|
53
|
+
it { expect(subject.user_agent).to eq("BoletoSimples Ruby Client v#{BoletoSimples::VERSION} (contato@boletosimples.com.br)") }
|
54
|
+
it { expect(subject.base_uri).to eq('https://boletosimples.com.br/api/v1') }
|
55
|
+
it { expect(subject.application_id).to eq('app-id') }
|
56
|
+
it { expect(subject.application_secret).to eq('app-secret') }
|
57
|
+
it { expect(subject.access_token).to eq('access-token') }
|
58
|
+
describe 'cache' do
|
59
|
+
it { expect(subject.cache).to eq(cache_object) }
|
60
|
+
it { expect(Her::API.default_api.connection.builder.handlers).to include(Faraday::HttpCache) }
|
61
|
+
end
|
62
|
+
describe 'client credentials' do
|
63
|
+
context 'invalid credentials', vcr: { cassette_name: 'configuration/client_credentials/invalid'} do
|
64
|
+
before {
|
65
|
+
BoletoSimples.configure do |c|
|
66
|
+
c.application_id = 'app-id'
|
67
|
+
c.application_secret = 'app-secret'
|
68
|
+
c.access_token = nil
|
69
|
+
end
|
70
|
+
}
|
71
|
+
it { expect{subject.client_credentials}.to raise_error(BoletoSimples::ResponseError, "401 POST https://sandbox.boletosimples.com.br/api/v1/oauth2/token (invalid_client)") }
|
72
|
+
end
|
73
|
+
context 'valid credentials', vcr: { cassette_name: 'configuration/client_credentials/valid'} do
|
74
|
+
# Before running this spec again, you need to set environment variable BOLETOSIMPLES_APP_ID and BOLETOSIMPLES_APP_SECRET
|
75
|
+
before {
|
76
|
+
BoletoSimples.configure do |c|
|
77
|
+
c.access_token = nil
|
78
|
+
end
|
79
|
+
}
|
80
|
+
it { expect(subject.client_credentials).to include(:access_token) }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
# Before running this spec again, you need to set environment variable BOLETOSIMPLES_ACCESS_TOKEN
|
5
|
+
RSpec.describe BoletoSimples::Extra do
|
6
|
+
context 'not authenticated' do
|
7
|
+
before {
|
8
|
+
BoletoSimples.configure do |c|
|
9
|
+
c.application_id = nil
|
10
|
+
c.application_secret = nil
|
11
|
+
c.access_token = 'invalid'
|
12
|
+
end
|
13
|
+
}
|
14
|
+
describe 'userinfo', vcr: { cassette_name: 'extra/userinfo/not_authenticated'} do
|
15
|
+
subject { BoletoSimples::Extra.userinfo }
|
16
|
+
it { expect{subject}.to raise_error(BoletoSimples::ResponseError, "401 GET https://sandbox.boletosimples.com.br/api/v1/userinfo.json?access_token=invalid (Você precisa se logar ou registrar antes de prosseguir.)") }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
context 'authenticated' do
|
20
|
+
before {
|
21
|
+
BoletoSimples.configure do |c|
|
22
|
+
c.application_id = nil
|
23
|
+
c.application_secret = nil
|
24
|
+
end
|
25
|
+
}
|
26
|
+
describe 'userinfo', vcr: { cassette_name: 'extra/userinfo/authenticated'} do
|
27
|
+
subject { BoletoSimples::Extra.userinfo }
|
28
|
+
it { expect(subject).to eq({:id=>53, :login_url=>"https://sandbox.boletosimples.com.br/welcome?email=user1%40example.com&token=Dx6tDtrP_v9_CcDjMRmr", :email=>"user1@example.com", :account_type=>nil, :first_name=>nil, :middle_name=>nil, :last_name=>nil, :full_name=>nil, :cpf=>nil, :date_of_birth=>nil, :mother_name=>nil, :father_name=>nil, :account_level=>2, :phone_number=>nil, :address_street_name=>nil, :address_number=>nil, :address_complement=>nil, :address_neighborhood=>nil, :address_postal_code=>nil, :address_city_name=>nil, :address_state=>nil, :business_name=>nil, :business_cnpj=>nil, :business_legal_name=>nil}) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
RSpec.describe BoletoSimples::LastRequest do
|
5
|
+
before {
|
6
|
+
BoletoSimples.configure do |c|
|
7
|
+
c.application_id = nil
|
8
|
+
c.application_secret = nil
|
9
|
+
end
|
10
|
+
}
|
11
|
+
describe 'bank_billets', vcr: { cassette_name: 'last_request/bank_billets'} do
|
12
|
+
before { BoletoSimples::BankBillet.all.size }
|
13
|
+
subject { BoletoSimples.last_request }
|
14
|
+
it { expect(subject).to be_kind_of(BoletoSimples::LastRequest) }
|
15
|
+
it { expect(subject.body).to be_kind_of(Array) }
|
16
|
+
it { expect(subject.body.first).to be_kind_of(Hash) }
|
17
|
+
it { expect(subject.response_headers).to be_kind_of(Hash) }
|
18
|
+
it { expect(subject.total).to be_kind_of(Integer) }
|
19
|
+
it { expect(subject.ratelimit_limit).to be_kind_of(Integer) }
|
20
|
+
it { expect(subject.ratelimit_remaining).to be_kind_of(Integer) }
|
21
|
+
it { expect(subject.links.keys).to match_array([:next, :last]) }
|
22
|
+
end
|
23
|
+
describe 'user_info', vcr: { cassette_name: 'last_request/userinfo'} do
|
24
|
+
before { BoletoSimples::Extra.userinfo }
|
25
|
+
subject { BoletoSimples.last_request }
|
26
|
+
it { expect(subject).to be_kind_of(BoletoSimples::LastRequest) }
|
27
|
+
it { expect(subject.body).to be_kind_of(Hash) }
|
28
|
+
it { expect(subject.response_headers).to be_kind_of(Hash) }
|
29
|
+
it { expect(subject.total).to eq(0) }
|
30
|
+
it { expect(subject.ratelimit_limit).to be_kind_of(Integer) }
|
31
|
+
it { expect(subject.ratelimit_remaining).to be_kind_of(Integer) }
|
32
|
+
it { expect(subject.links).to eq({}) }
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
# Before running this spec again, you need to set environment variable BOLETOSIMPLES_ACCESS_TOKEN
|
6
|
+
RSpec.describe BoletoSimples::BankBillet do
|
7
|
+
before {
|
8
|
+
BoletoSimples.configure do |c|
|
9
|
+
c.application_id = nil
|
10
|
+
c.application_secret = nil
|
11
|
+
end
|
12
|
+
}
|
13
|
+
describe 'methods' do
|
14
|
+
before {
|
15
|
+
VCR.use_cassette('resources/bank_billet/create/valid') do
|
16
|
+
@bank_billet = BoletoSimples::BankBillet.create({
|
17
|
+
amount: 9.01,
|
18
|
+
description: 'Despesas do contrato 0012',
|
19
|
+
expire_at: '2014-01-01',
|
20
|
+
customer_address: 'Rua quinhentos',
|
21
|
+
customer_address_complement: 'Sala 4',
|
22
|
+
customer_address_number: '111',
|
23
|
+
customer_city_name: 'Rio de Janeiro',
|
24
|
+
customer_cnpj_cpf: '012.345.678-90',
|
25
|
+
customer_email: 'cliente@bom.com',
|
26
|
+
customer_neighborhood: 'Sao Francisco',
|
27
|
+
customer_person_name: 'Joao da Silva',
|
28
|
+
customer_person_type: 'individual',
|
29
|
+
customer_phone_number: '2112123434',
|
30
|
+
customer_state: 'RJ',
|
31
|
+
customer_zipcode: '12312-123',
|
32
|
+
notification_url: 'http://example.com.br/notify'
|
33
|
+
})
|
34
|
+
end
|
35
|
+
}
|
36
|
+
describe 'create' do
|
37
|
+
context 'valid parameters' do
|
38
|
+
subject { @bank_billet }
|
39
|
+
it { expect(subject).to be_a_kind_of(BoletoSimples::BankBillet) }
|
40
|
+
it { expect(subject.response_errors).to eq({}) }
|
41
|
+
it { expect(subject.attributes.keys).to match_array(["amount","description","expire_at","customer_address","customer_address_complement","customer_address_number","customer_city_name","customer_cnpj_cpf","customer_email","customer_neighborhood","customer_person_name","customer_person_type","customer_phone_number","customer_state","customer_zipcode","notification_url","id","paid_at","status","shorten_url","send_email_on_creation","created_via_api","paid_amount"]) }
|
42
|
+
end
|
43
|
+
context 'invalid parameters' do
|
44
|
+
context 'empty bank_billet' do
|
45
|
+
subject {
|
46
|
+
VCR.use_cassette('resources/bank_billet/create/invalid_root') do
|
47
|
+
BoletoSimples::BankBillet.create({})
|
48
|
+
end
|
49
|
+
}
|
50
|
+
it { expect(subject.response_errors).to eq({:bank_billet=>["não pode ficar em branco"]}) }
|
51
|
+
end
|
52
|
+
context 'invalid params' do
|
53
|
+
subject {
|
54
|
+
VCR.use_cassette('resources/bank_billet/create/invalid_params') do
|
55
|
+
BoletoSimples::BankBillet.create({amount: 9.1})
|
56
|
+
end
|
57
|
+
}
|
58
|
+
it { expect(subject.response_errors).to eq({:expire_at=>["não pode ficar em branco", "não é uma data válida"], :customer_person_name=>["não pode ficar em branco"], :customer_cnpj_cpf=>["não pode ficar em branco"], :description=>["não pode ficar em branco"], :customer_zipcode=>["não pode ficar em branco"]}) }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
describe 'find', vcr: { cassette_name: 'resources/bank_billet/find'} do
|
63
|
+
subject { BoletoSimples::BankBillet.find(@bank_billet.id) }
|
64
|
+
it { expect(subject).to be_a_kind_of(BoletoSimples::BankBillet) }
|
65
|
+
end
|
66
|
+
describe 'cancel', vcr: { cassette_name: 'resources/bank_billet/cancel'} do
|
67
|
+
subject { BoletoSimples::BankBillet.find(@bank_billet.id).cancel }
|
68
|
+
it { expect(subject).to be_a_kind_of(BoletoSimples::BankBillet) }
|
69
|
+
end
|
70
|
+
describe 'all', vcr: { cassette_name: 'resources/bank_billet/all'} do
|
71
|
+
subject { BoletoSimples::BankBillet.all }
|
72
|
+
it { expect(subject.first).to be_a_kind_of(BoletoSimples::BankBillet) }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
# Before running this spec again, you need to set environment variable BOLETOSIMPLES_ACCESS_TOKEN
|
6
|
+
RSpec.describe BoletoSimples::Customer do
|
7
|
+
before {
|
8
|
+
BoletoSimples.configure do |c|
|
9
|
+
c.application_id = nil
|
10
|
+
c.application_secret = nil
|
11
|
+
end
|
12
|
+
}
|
13
|
+
describe 'methods' do
|
14
|
+
before {
|
15
|
+
VCR.use_cassette('resources/customer/create/valid') do
|
16
|
+
@customer = BoletoSimples::Customer.create({
|
17
|
+
person_name: "Maria José",
|
18
|
+
cnpj_cpf: "811.536.151-85",
|
19
|
+
email: "cliente@bom.com",
|
20
|
+
address: "Rua quinhentos",
|
21
|
+
city_name: "Rio de Janeiro",
|
22
|
+
state: "RJ",
|
23
|
+
neighborhood: "bairro",
|
24
|
+
zipcode: "12312-123",
|
25
|
+
address_number: "111",
|
26
|
+
address_complement: "Sala 4",
|
27
|
+
phone_number: "2112123434"
|
28
|
+
})
|
29
|
+
end
|
30
|
+
}
|
31
|
+
describe 'create' do
|
32
|
+
context 'valid parameters' do
|
33
|
+
subject { @customer }
|
34
|
+
it { expect(subject).to be_a_kind_of(BoletoSimples::Customer) }
|
35
|
+
it { expect(subject.response_errors).to eq({}) }
|
36
|
+
it { expect(subject.attributes.keys).to match_array(["person_name","cnpj_cpf","email","address","city_name","state","neighborhood","zipcode","address_number","address_complement","phone_number","mobile_number","person_type","mobile_local_code","created_via_api","id"]) }
|
37
|
+
end
|
38
|
+
context 'invalid parameters' do
|
39
|
+
context 'empty bank_billet' do
|
40
|
+
subject {
|
41
|
+
VCR.use_cassette('resources/customer/create/invalid_root') do
|
42
|
+
BoletoSimples::Customer.create({})
|
43
|
+
end
|
44
|
+
}
|
45
|
+
it { expect(subject.response_errors).to eq({:customer=>["não pode ficar em branco"]}) }
|
46
|
+
end
|
47
|
+
context 'invalid params' do
|
48
|
+
subject {
|
49
|
+
VCR.use_cassette('resources/customer/create/invalid_params') do
|
50
|
+
BoletoSimples::Customer.create({person_name: ''})
|
51
|
+
end
|
52
|
+
}
|
53
|
+
it { expect(subject.response_errors).to eq({:person_name=>["não pode ficar em branco"], :cnpj_cpf=>["não pode ficar em branco"], :zipcode=>["não pode ficar em branco"]}) }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
describe 'find', vcr: { cassette_name: 'resources/customer/find'} do
|
58
|
+
subject { BoletoSimples::Customer.find(@customer.id) }
|
59
|
+
it { expect(subject).to be_a_kind_of(BoletoSimples::Customer) }
|
60
|
+
end
|
61
|
+
describe 'all', vcr: { cassette_name: 'resources/customer/all'} do
|
62
|
+
subject { BoletoSimples::Customer.all }
|
63
|
+
it { expect(subject.first).to be_a_kind_of(BoletoSimples::Customer) }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
# Before running this spec again, you need to set environment variable BOLETOSIPLES_CLIENT_CREDENTIALS_TOKEN
|
6
|
+
RSpec.describe BoletoSimples::Partner::User do
|
7
|
+
before {
|
8
|
+
BoletoSimples.configure do |c|
|
9
|
+
c.access_token = ENV['BOLETOSIMPLES_CLIENT_CREDENTIALS_TOKEN']
|
10
|
+
end
|
11
|
+
}
|
12
|
+
# ATENÇÃO: Após rodar este teste, edite o vcr_cassette e remova o token do login_url e substitua o application_access_token para xxx
|
13
|
+
describe 'create', vcr: { cassette_name: 'resources/partner/user/create'} do
|
14
|
+
subject { BoletoSimples::Partner::User.create(email: 'user2@example.com') }
|
15
|
+
it { expect(subject.id).not_to be_nil }
|
16
|
+
it { expect(subject.response_errors).to eq({}) }
|
17
|
+
it { expect(subject.attributes.keys).to eq(["email", "id", "account_type", "sex", "cpf", "address_street_name", "address_state", "address_neighborhood", "address_postal_code", "address_number", "address_complement", "phone_number", "withdrawal_period", "notification_url", "first_name", "middle_name", "last_name", "date_of_birth", "business_category", "business_subcategory", "business_website", "business_name", "business_legal_name", "business_type", "business_cnpj", "address_city_name", "full_name", "login_url", "mother_name", "father_name", "application_access_token"]) }
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
# Before running this spec again, you need to set environment variable BOLETOSIMPLES_ACCESS_TOKEN
|
6
|
+
RSpec.describe BoletoSimples::Transaction do
|
7
|
+
before {
|
8
|
+
BoletoSimples.configure do |c|
|
9
|
+
c.application_id = nil
|
10
|
+
c.application_secret = nil
|
11
|
+
end
|
12
|
+
}
|
13
|
+
describe 'all', vcr: { cassette_name: 'resources/transaction/all'} do
|
14
|
+
subject { BoletoSimples::Transaction.all }
|
15
|
+
it { expect(subject.first).to be_a_kind_of(BoletoSimples::Transaction) }
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://sandbox.boletosimples.com.br/api/v1/oauth2/token
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"grant_type":"client_credentials","client_id":"app-id","client_secret":"app-secret"}'
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- BoletoSimples Ruby Client v0.1.0 (contato@boletosimples.com.br)
|
12
|
+
Content-Type:
|
13
|
+
- application/json
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- "*/*"
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 401
|
21
|
+
message: Unauthorized
|
22
|
+
headers:
|
23
|
+
Server:
|
24
|
+
- Cowboy
|
25
|
+
Connection:
|
26
|
+
- keep-alive
|
27
|
+
Strict-Transport-Security:
|
28
|
+
- max-age=2592000
|
29
|
+
Cache-Control:
|
30
|
+
- no-store
|
31
|
+
Pragma:
|
32
|
+
- no-cache
|
33
|
+
Content-Type:
|
34
|
+
- application/json; charset=utf-8
|
35
|
+
Www-Authenticate:
|
36
|
+
- !binary |-
|
37
|
+
QmVhcmVyIHJlYWxtPSJCb2xldG9TaW1wbGVzIiwgZXJyb3I9ImludmFsaWRf
|
38
|
+
Y2xpZW50IiwgZXJyb3JfZGVzY3JpcHRpb249IkF1dGVudGljYcOnw6NvIGRv
|
39
|
+
IGNsaWVudGUgZmFsaG91IGRldmlkbyBow6EgdW0gY2xpZW50ZSBkZXNjb25o
|
40
|
+
ZWNpZG8sIG5lbmh1bSBjbGllbnRlIGRlIGF1dGVudGljYcOnw6NvIGluY2x1
|
41
|
+
c28sIG91IG3DqXRvZG8gZGUgYXV0ZW50aWNhw6fDo28gbsOjbyBzdXBvcnRh
|
42
|
+
ZG8uIg==
|
43
|
+
X-Request-Id:
|
44
|
+
- c694e3a4-3021-40b6-94f4-b8e8d8bac941
|
45
|
+
X-Runtime:
|
46
|
+
- '0.014012'
|
47
|
+
Date:
|
48
|
+
- Sun, 08 Mar 2015 19:58:22 GMT
|
49
|
+
X-Rack-Cache:
|
50
|
+
- invalidate, pass
|
51
|
+
Vary:
|
52
|
+
- Accept-Encoding
|
53
|
+
Transfer-Encoding:
|
54
|
+
- chunked
|
55
|
+
Via:
|
56
|
+
- 1.1 vegur
|
57
|
+
body:
|
58
|
+
encoding: UTF-8
|
59
|
+
string: '{"error":"invalid_client","error_description":"Autenticação do cliente
|
60
|
+
falhou devido há um cliente desconhecido, nenhum cliente de autenticação incluso,
|
61
|
+
ou método de autenticação não suportado."}'
|
62
|
+
http_version:
|
63
|
+
recorded_at: Sun, 08 Mar 2015 19:58:21 GMT
|
64
|
+
recorded_with: VCR 2.9.3
|