boletosimples 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +8 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +81 -0
- data/LICENSE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +6 -0
- data/boletosimples.gemspec +29 -0
- data/example/basic_auth_example.rb +67 -0
- data/example/oauth_example.rb +77 -0
- data/lib/boletosimples.rb +6 -0
- data/lib/boletosimples/client.rb +100 -0
- data/lib/boletosimples/oauth_client.rb +70 -0
- data/lib/boletosimples/version.rb +4 -0
- data/lib/oauth2_patch.rb +24 -0
- data/spec/boletosimples/client_spec.rb +11 -0
- data/spec/boletosimples/oauth_client_spec.rb +13 -0
- data/spec/spec.opts +8 -0
- data/spec/spec_helper.rb +15 -0
- metadata +154 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 97bd8ede5768375b232808e945b760b147961959
|
4
|
+
data.tar.gz: 96875590bc4ea84c4c0a90860b27939d71c54301
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8da6e7daf3a4fdd7c297fb321faecc030f40066f7def6c575b12d24776d6da69663c65def3f72c486d0b525dccc866e778f532a283c1832856786bd28967b35a
|
7
|
+
data.tar.gz: 7f78e9ee55d82a4030ef5107f4018083032f334068dfd741732bf31776cad455f3f7a718d6aad2a6aa3b467982d4a71be8269503d61c33b703e4515ea30dc1b7
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
boletosimples-ruby
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.1
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
boletosimples (0.0.1)
|
5
|
+
httparty (>= 0.13.1)
|
6
|
+
multi_json (>= 1.10.1)
|
7
|
+
oauth2 (~> 0.9.4)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
codeclimate-test-reporter (0.3.0)
|
13
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
14
|
+
coderay (1.1.0)
|
15
|
+
coveralls (0.7.0)
|
16
|
+
multi_json (~> 1.3)
|
17
|
+
rest-client
|
18
|
+
simplecov (>= 0.7)
|
19
|
+
term-ansicolor
|
20
|
+
thor
|
21
|
+
diff-lcs (1.2.5)
|
22
|
+
docile (1.1.3)
|
23
|
+
faraday (0.9.0)
|
24
|
+
multipart-post (>= 1.2, < 3)
|
25
|
+
httparty (0.13.1)
|
26
|
+
json (~> 1.8)
|
27
|
+
multi_xml (>= 0.5.2)
|
28
|
+
json (1.8.1)
|
29
|
+
jwt (1.0.0)
|
30
|
+
method_source (0.8.2)
|
31
|
+
mime-types (2.3)
|
32
|
+
multi_json (1.10.1)
|
33
|
+
multi_xml (0.5.5)
|
34
|
+
multipart-post (2.0.0)
|
35
|
+
oauth2 (0.9.4)
|
36
|
+
faraday (>= 0.8, < 0.10)
|
37
|
+
jwt (~> 1.0)
|
38
|
+
multi_json (~> 1.3)
|
39
|
+
multi_xml (~> 0.5)
|
40
|
+
rack (~> 1.2)
|
41
|
+
pry (0.9.12.6)
|
42
|
+
coderay (~> 1.0)
|
43
|
+
method_source (~> 0.8)
|
44
|
+
slop (~> 3.4)
|
45
|
+
rack (1.5.2)
|
46
|
+
rake (10.3.2)
|
47
|
+
rest-client (1.6.7)
|
48
|
+
mime-types (>= 1.16)
|
49
|
+
rspec (3.0.0)
|
50
|
+
rspec-core (~> 3.0.0)
|
51
|
+
rspec-expectations (~> 3.0.0)
|
52
|
+
rspec-mocks (~> 3.0.0)
|
53
|
+
rspec-core (3.0.0)
|
54
|
+
rspec-support (~> 3.0.0)
|
55
|
+
rspec-expectations (3.0.0)
|
56
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
57
|
+
rspec-support (~> 3.0.0)
|
58
|
+
rspec-mocks (3.0.0)
|
59
|
+
rspec-support (~> 3.0.0)
|
60
|
+
rspec-support (3.0.0)
|
61
|
+
simplecov (0.8.2)
|
62
|
+
docile (~> 1.1.0)
|
63
|
+
multi_json
|
64
|
+
simplecov-html (~> 0.8.0)
|
65
|
+
simplecov-html (0.8.0)
|
66
|
+
slop (3.5.0)
|
67
|
+
term-ansicolor (1.3.0)
|
68
|
+
tins (~> 1.0)
|
69
|
+
thor (0.19.1)
|
70
|
+
tins (1.3.0)
|
71
|
+
|
72
|
+
PLATFORMS
|
73
|
+
ruby
|
74
|
+
|
75
|
+
DEPENDENCIES
|
76
|
+
boletosimples!
|
77
|
+
codeclimate-test-reporter
|
78
|
+
coveralls
|
79
|
+
pry (= 0.9.12.6)
|
80
|
+
rake
|
81
|
+
rspec (~> 3.0.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Boleto Simples
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Boleto Simples
|
2
|
+
|
3
|
+
[![Gem Version](http://img.shields.io/gem/v/boletosimples.svg)][gem]
|
4
|
+
[![Build Status](http://img.shields.io/travis/BoletoSimples/boletosimples-ruby.svg)][travis]
|
5
|
+
[![Dependency Status](http://img.shields.io/gemnasium/BoletoSimples/boletosimples-ruby.svg)][gemnasium]
|
6
|
+
[![Code Climate](http://img.shields.io/codeclimate/github/BoletoSimples/boletosimples-ruby.svg)][codeclimate]
|
7
|
+
[![Coverage Status](http://img.shields.io/coveralls/BoletoSimples/boletosimples-ruby.svg)][coveralls]
|
8
|
+
|
9
|
+
[gem]: https://rubygems.org/gems/boletosimples
|
10
|
+
[travis]: http://travis-ci.org/BoletoSimples/boletosimples-ruby
|
11
|
+
[gemnasium]: https://gemnasium.com/BoletoSimples/boletosimples-ruby
|
12
|
+
[codeclimate]: https://codeclimate.com/github/BoletoSimples/boletosimples-ruby
|
13
|
+
[coveralls]: https://coveralls.io/r/BoletoSimples/boletosimples-ruby
|
14
|
+
|
15
|
+
Esta gem inclui todos os métodos disponíveis na [Boleto Simples JSON API](http://api.boletosimples.com.br).
|
16
|
+
|
17
|
+
Ela suporta Basic Auth e OAuth 2.0 para ações realizadas por parceiros.
|
18
|
+
|
19
|
+
## Instalação
|
20
|
+
|
21
|
+
Adicione a linha a baixo no seu Gemfile:
|
22
|
+
|
23
|
+
gem 'boletosimples'
|
24
|
+
|
25
|
+
Execute:
|
26
|
+
|
27
|
+
$ bundle install
|
28
|
+
|
29
|
+
Ou instale você mesmo:
|
30
|
+
|
31
|
+
$ gem install boletosimples
|
32
|
+
|
33
|
+
## Exemplos
|
34
|
+
|
35
|
+
Veja a [lista de métodos aqui](https://github.com/boletosimples/boletosimples-ruby/blob/master/example)
|
36
|
+
|
37
|
+
## OAuth 2.0 Authentication (para acessar as contas dos usuários)
|
38
|
+
|
39
|
+
Comece [solicitando um cadastro de OAuth 2.0 application](http://suporte.boletosimples.com.br)
|
40
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'boletosimples/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'boletosimples'
|
8
|
+
gem.version = BoletoSimples::VERSION
|
9
|
+
gem.authors = ['Kivanio Barbosa', 'Rafael Lima']
|
10
|
+
gem.email = ['kivanio@gmail.com', 'contato@rafael.adm.br']
|
11
|
+
gem.description = 'An easy way to charge by bank billet.'
|
12
|
+
gem.summary = 'An easy way to charge by bank billet.'
|
13
|
+
gem.homepage = 'http://api.boletosimples.com.br'
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
|
20
|
+
# Gems that must be installed for sift to compile and build
|
21
|
+
gem.add_development_dependency 'pry', '0.9.12.6'
|
22
|
+
gem.add_development_dependency 'rspec', '~> 3.0.0'
|
23
|
+
gem.add_development_dependency 'rake'
|
24
|
+
|
25
|
+
# Gems that must be intalled for sift to work
|
26
|
+
gem.add_dependency 'httparty', '>= 0.13.1'
|
27
|
+
gem.add_dependency 'multi_json', '>= 1.10.1'
|
28
|
+
gem.add_dependency 'oauth2', '~> 0.9.4'
|
29
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
$: << File.expand_path('../../lib', __FILE__)
|
2
|
+
require 'boletosimples'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
client = BoletoSimples::Client.new('seu email', 'sua senha', {user_agent: 'Meu e-Commerce (meuecommerce@example.com)'})
|
6
|
+
|
7
|
+
# pp client.userinfo
|
8
|
+
|
9
|
+
# pp client.transactions
|
10
|
+
|
11
|
+
# pp client.customers
|
12
|
+
|
13
|
+
# pp client.customer 2
|
14
|
+
#
|
15
|
+
# pp client.create_customer({:customer =>
|
16
|
+
# {
|
17
|
+
# person_name: "Joao da Silva",
|
18
|
+
# cnpj_cpf: "012.345.678-90",
|
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
|
+
# })
|
30
|
+
|
31
|
+
# pp client.bank_billets
|
32
|
+
|
33
|
+
# pp client.bank_billet 3
|
34
|
+
|
35
|
+
# pp client.create_bank_billet({bank_billet:
|
36
|
+
# {
|
37
|
+
# amount: 41.01,
|
38
|
+
# customer_address: 'Rua quinhentos',
|
39
|
+
# customer_address_complement: 'Sala 4',
|
40
|
+
# customer_address_number: '111',
|
41
|
+
# customer_city_name: 'Rio de Janeiro',
|
42
|
+
# customer_cnpj_cpf: '012.345.678-90',
|
43
|
+
# customer_email: 'cliente@bom.com',
|
44
|
+
# customer_neighborhood: 'Sao Francisco',
|
45
|
+
# customer_person_name: 'Joao da Silva',
|
46
|
+
# customer_person_type: 'individual',
|
47
|
+
# customer_phone_number: '2112123434',
|
48
|
+
# customer_state: 'RJ',
|
49
|
+
# customer_zipcode: '12312-123',
|
50
|
+
# description: 'Despesas do contrato 0012',
|
51
|
+
# expire_at: '2014-01-01',
|
52
|
+
# notification_url: 'http://example.com.br/notify',
|
53
|
+
# }
|
54
|
+
# })
|
55
|
+
|
56
|
+
|
57
|
+
# pp client.partner_create_user(
|
58
|
+
# {
|
59
|
+
# user: {
|
60
|
+
# email: 'email@example.com',
|
61
|
+
# notification_url: 'http://example.com.br/notify'
|
62
|
+
# }
|
63
|
+
# }
|
64
|
+
# )
|
65
|
+
#
|
66
|
+
|
67
|
+
|
@@ -0,0 +1,77 @@
|
|
1
|
+
$: << File.expand_path('../../lib', __FILE__)
|
2
|
+
require 'boletosimples'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
credentials = {
|
6
|
+
:token => 'access token'
|
7
|
+
}
|
8
|
+
client_options = {
|
9
|
+
user_agent: 'Meu e-Commerce (meuecommerce@example.com)'
|
10
|
+
}
|
11
|
+
|
12
|
+
client = BoletoSimples::OAuthClient.new('api id',
|
13
|
+
'api secret',
|
14
|
+
credentials,
|
15
|
+
client_options)
|
16
|
+
|
17
|
+
# pp client.userinfo
|
18
|
+
|
19
|
+
# pp client.transactions
|
20
|
+
|
21
|
+
# pp client.customers
|
22
|
+
|
23
|
+
# pp client.customer 2
|
24
|
+
#
|
25
|
+
# pp client.create_customer({:customer =>
|
26
|
+
# {
|
27
|
+
# person_name: "Joao da Silva",
|
28
|
+
# cnpj_cpf: "012.345.678-90",
|
29
|
+
# email: "cliente@bom.com",
|
30
|
+
# address: "Rua quinhentos",
|
31
|
+
# city_name: "Rio de Janeiro",
|
32
|
+
# state: "RJ",
|
33
|
+
# neighborhood: "bairro",
|
34
|
+
# zipcode: "12312-123",
|
35
|
+
# address_number: "111",
|
36
|
+
# address_complement: "Sala 4",
|
37
|
+
# phone_number: "2112123434"
|
38
|
+
# }
|
39
|
+
# })
|
40
|
+
|
41
|
+
# pp client.bank_billets
|
42
|
+
|
43
|
+
# pp client.bank_billet 3
|
44
|
+
|
45
|
+
# pp client.create_bank_billet({bank_billet:
|
46
|
+
# {
|
47
|
+
# amount: 41.01,
|
48
|
+
# customer_address: 'Rua quinhentos',
|
49
|
+
# customer_address_complement: 'Sala 4',
|
50
|
+
# customer_address_number: '111',
|
51
|
+
# customer_city_name: 'Rio de Janeiro',
|
52
|
+
# customer_cnpj_cpf: '012.345.678-90',
|
53
|
+
# customer_email: 'cliente@bom.com',
|
54
|
+
# customer_neighborhood: 'Sao Francisco',
|
55
|
+
# customer_person_name: 'Joao da Silva',
|
56
|
+
# customer_person_type: 'individual',
|
57
|
+
# customer_phone_number: '2112123434',
|
58
|
+
# customer_state: 'RJ',
|
59
|
+
# customer_zipcode: '12312-123',
|
60
|
+
# description: 'Despesas do contrato 0012',
|
61
|
+
# expire_at: '2014-01-01',
|
62
|
+
# notification_url: 'http://example.com.br/notify',
|
63
|
+
# }
|
64
|
+
# })
|
65
|
+
|
66
|
+
# pp client.partner_create_user(
|
67
|
+
# {
|
68
|
+
# user: {
|
69
|
+
# email: 'email@example.com',
|
70
|
+
# notification_url: 'http://example.com.br/notify'
|
71
|
+
# }
|
72
|
+
# }
|
73
|
+
# )
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'httparty'
|
3
|
+
require 'multi_json'
|
4
|
+
|
5
|
+
module BoletoSimples
|
6
|
+
class Client
|
7
|
+
include HTTParty
|
8
|
+
|
9
|
+
PRODUCTION_BASE_URI = 'https://boletosimples.com.br/api/v1'
|
10
|
+
SANDBOX_BASE_URI = 'https://sandbox.boletosimples.com.br/api/v1'
|
11
|
+
|
12
|
+
def initialize(username, password, options={})
|
13
|
+
@username = username
|
14
|
+
@password = password
|
15
|
+
|
16
|
+
# defaults
|
17
|
+
@production = options.delete(:production)
|
18
|
+
@base_uri = (@production ? PRODUCTION_BASE_URI : SANDBOX_BASE_URI)
|
19
|
+
@user_agent = options.delete(:user_agent)
|
20
|
+
|
21
|
+
options[:format] ||= :json
|
22
|
+
options.each do |k, v|
|
23
|
+
self.class.send k, v
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Users
|
28
|
+
|
29
|
+
def userinfo options={}
|
30
|
+
get '/userinfo', options
|
31
|
+
end
|
32
|
+
|
33
|
+
# Users
|
34
|
+
def partner_create_user options={}
|
35
|
+
post '/partner/users', options
|
36
|
+
end
|
37
|
+
|
38
|
+
# Transactions
|
39
|
+
|
40
|
+
def transactions page=1, options ={}
|
41
|
+
get '/transactions', {page: page}.merge(options)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Customers
|
45
|
+
def customers page=1, options ={}
|
46
|
+
get '/customers', {page: page}.merge(options)
|
47
|
+
end
|
48
|
+
|
49
|
+
def create_customer options ={}
|
50
|
+
post '/customers', options
|
51
|
+
end
|
52
|
+
|
53
|
+
def customer id=1, options ={}
|
54
|
+
get "/customers/#{id}", options
|
55
|
+
end
|
56
|
+
|
57
|
+
# Bank Billets
|
58
|
+
def bank_billets page=1, options ={}
|
59
|
+
get '/bank_billets', {page: page}.merge(options)
|
60
|
+
end
|
61
|
+
|
62
|
+
def create_bank_billet options ={}
|
63
|
+
post '/bank_billets', options
|
64
|
+
end
|
65
|
+
|
66
|
+
def bank_billet id=1, options ={}
|
67
|
+
get "/bank_billets/#{id}", options
|
68
|
+
end
|
69
|
+
|
70
|
+
# Wrappers for the main HTTP verbs
|
71
|
+
|
72
|
+
def get(path, options={})
|
73
|
+
http_verb :get, path, options
|
74
|
+
end
|
75
|
+
|
76
|
+
def post(path, options={})
|
77
|
+
http_verb :post, path, options
|
78
|
+
end
|
79
|
+
|
80
|
+
def put(path, options={})
|
81
|
+
http_verb :put, path, options
|
82
|
+
end
|
83
|
+
|
84
|
+
def delete(path, options={})
|
85
|
+
http_verb :delete, path, options
|
86
|
+
end
|
87
|
+
|
88
|
+
def http_verb(verb, path, options={})
|
89
|
+
request_options = {body: options.to_json}
|
90
|
+
request_options[:headers] = {
|
91
|
+
"Content-Type" => "application/json",
|
92
|
+
"User-Agent" => @user_agent
|
93
|
+
}
|
94
|
+
request_options[:basic_auth] = {:username => @username, :password => @password}
|
95
|
+
uri = "#{@base_uri}#{path}"
|
96
|
+
response = self.class.send(verb, uri, request_options)
|
97
|
+
return JSON.parse(response.body)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'oauth2'
|
3
|
+
|
4
|
+
module BoletoSimples
|
5
|
+
class OAuthClient < Client
|
6
|
+
# Initializes a BoletoSimples Client using OAuth 2.0 credentials
|
7
|
+
#
|
8
|
+
# @param [String] client_id this application's BoletoSimples OAuth2 CLIENT_ID
|
9
|
+
# @param [String] client_secret this application's BoletoSimples OAuth2 CLIENT_SECRET
|
10
|
+
# @param [Hash] user_credentials OAuth 2.0 credentials to use
|
11
|
+
# @option user_credentials [String] access_token Must pass either this or token
|
12
|
+
# @option user_credentials [String] token Must pass either this or access_token
|
13
|
+
# @option user_credentials [String] refresh_token Optional
|
14
|
+
# @option user_credentials [Integer] expires_at Optional
|
15
|
+
# @option user_credentials [Integer] expires_in Optional
|
16
|
+
#
|
17
|
+
# Please note access tokens will be automatically refreshed when expired
|
18
|
+
# Use the credentials method when finished with the client to retrieve up-to-date credentials
|
19
|
+
def initialize(client_id, client_secret, user_credentials, options={})
|
20
|
+
@production = options.delete(:production)
|
21
|
+
@base_uri = options[:base_uri] || (@production ? PRODUCTION_BASE_URI : SANDBOX_BASE_URI)
|
22
|
+
client_opts = {
|
23
|
+
:site => @base_uri,
|
24
|
+
:authorize_url => options[:authorize_url] || "#{@base_uri}/oauth/authorize",
|
25
|
+
:token_url => options[:token_url] || "#{@base_uri}/oauth/token",
|
26
|
+
:raise_errors => false
|
27
|
+
}
|
28
|
+
@user_agent = options.delete(:user_agent)
|
29
|
+
@oauth_client = OAuth2::Client.new(client_id, client_secret, client_opts)
|
30
|
+
token_hash = user_credentials.dup
|
31
|
+
token_hash[:access_token] ||= token_hash[:token]
|
32
|
+
token_hash.delete :expires
|
33
|
+
raise "No access token provided" unless token_hash[:access_token]
|
34
|
+
@oauth_token = OAuth2::AccessToken.from_hash(@oauth_client, token_hash)
|
35
|
+
end
|
36
|
+
|
37
|
+
def http_verb(verb, path, options={})
|
38
|
+
path = remove_leading_slash(path)
|
39
|
+
request_options = {headers: {
|
40
|
+
"Accept-Charset" => "UTF-8",
|
41
|
+
"Content-Type" => "application/json",
|
42
|
+
"User-Agent" => @user_agent
|
43
|
+
}, body: options.to_json}
|
44
|
+
|
45
|
+
response = oauth_token.request(verb, path, request_options)
|
46
|
+
return JSON.parse(response.body)
|
47
|
+
end
|
48
|
+
|
49
|
+
def refresh!
|
50
|
+
raise "Access token not initialized." unless @oauth_token
|
51
|
+
@oauth_token = @oauth_token.refresh!
|
52
|
+
end
|
53
|
+
|
54
|
+
def oauth_token
|
55
|
+
raise "Access token not initialized." unless @oauth_token
|
56
|
+
refresh! if @oauth_token.expired?
|
57
|
+
@oauth_token
|
58
|
+
end
|
59
|
+
|
60
|
+
def credentials
|
61
|
+
@oauth_token.to_hash
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def remove_leading_slash(path)
|
67
|
+
path.sub(/^\//, '')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/oauth2_patch.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module OAuth2
|
2
|
+
class Error < StandardError
|
3
|
+
attr_reader :response, :code, :description
|
4
|
+
|
5
|
+
# standard error values include:
|
6
|
+
# :invalid_request, :invalid_client, :invalid_token, :invalid_grant, :unsupported_grant_type, :invalid_scope
|
7
|
+
def initialize(response)
|
8
|
+
response.error = self
|
9
|
+
@response = response
|
10
|
+
|
11
|
+
message = []
|
12
|
+
|
13
|
+
if response.parsed.is_a?(Hash)
|
14
|
+
@code = response.parsed['error']
|
15
|
+
@description = response.parsed['error_description']
|
16
|
+
message << "#{@code}: #{@description}"
|
17
|
+
end
|
18
|
+
|
19
|
+
message << response.body.force_encoding("UTF-8")
|
20
|
+
|
21
|
+
super(message.join("\n"))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe BoletoSimples::Client do
|
5
|
+
describe :userinfo do
|
6
|
+
context :without_authentication do
|
7
|
+
let(:client) { BoletoSimples::Client.new(nil, nil, {user_agent: 'Meu e-Commerce (meuecommerce@example.com)'}) }
|
8
|
+
it { expect(client.userinfo).to eq({"error"=>"Você precisa se logar ou registrar antes de prosseguir."}) }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe BoletoSimples::OAuthClient do
|
5
|
+
describe :userinfo do
|
6
|
+
context :without_authentication do
|
7
|
+
let(:credentials) { { token: 'invalid-token' } }
|
8
|
+
let(:client_options) { {user_agent: 'Meu e-Commerce (meuecommerce@example.com)'} }
|
9
|
+
let(:client) { BoletoSimples::OAuthClient.new(nil, nil, credentials, client_options) }
|
10
|
+
it { expect(client.userinfo).to eq({"error"=>"Você precisa se logar ou registrar antes de prosseguir."}) }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear!
|
3
|
+
|
4
|
+
require 'codeclimate-test-reporter'
|
5
|
+
CodeClimate::TestReporter.start
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
8
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
9
|
+
require 'rspec'
|
10
|
+
require 'pry'
|
11
|
+
require 'boletosimples'
|
12
|
+
|
13
|
+
# Requires supporting files with custom matchers and macros, etc,
|
14
|
+
# in ./support/ and its subdirectories.
|
15
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: boletosimples
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kivanio Barbosa
|
8
|
+
- Rafael Lima
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-06-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: pry
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 0.9.12.6
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 0.9.12.6
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rspec
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 3.0.0
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 3.0.0
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: httparty
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.13.1
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.13.1
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: multi_json
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.10.1
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 1.10.1
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: oauth2
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 0.9.4
|
91
|
+
type: :runtime
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 0.9.4
|
98
|
+
description: An easy way to charge by bank billet.
|
99
|
+
email:
|
100
|
+
- kivanio@gmail.com
|
101
|
+
- contato@rafael.adm.br
|
102
|
+
executables: []
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- ".gitignore"
|
107
|
+
- ".ruby-gemset"
|
108
|
+
- ".ruby-version"
|
109
|
+
- ".travis.yml"
|
110
|
+
- Gemfile
|
111
|
+
- Gemfile.lock
|
112
|
+
- LICENSE.txt
|
113
|
+
- README.md
|
114
|
+
- Rakefile
|
115
|
+
- boletosimples.gemspec
|
116
|
+
- example/basic_auth_example.rb
|
117
|
+
- example/oauth_example.rb
|
118
|
+
- lib/boletosimples.rb
|
119
|
+
- lib/boletosimples/client.rb
|
120
|
+
- lib/boletosimples/oauth_client.rb
|
121
|
+
- lib/boletosimples/version.rb
|
122
|
+
- lib/oauth2_patch.rb
|
123
|
+
- spec/boletosimples/client_spec.rb
|
124
|
+
- spec/boletosimples/oauth_client_spec.rb
|
125
|
+
- spec/spec.opts
|
126
|
+
- spec/spec_helper.rb
|
127
|
+
homepage: http://api.boletosimples.com.br
|
128
|
+
licenses: []
|
129
|
+
metadata: {}
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 2.2.2
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: An easy way to charge by bank billet.
|
150
|
+
test_files:
|
151
|
+
- spec/boletosimples/client_spec.rb
|
152
|
+
- spec/boletosimples/oauth_client_spec.rb
|
153
|
+
- spec/spec.opts
|
154
|
+
- spec/spec_helper.rb
|