bb_oauth 1.0.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 +7 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +71 -0
- data/README.md +85 -0
- data/Rakefile +8 -0
- data/bb_oauth.gemspec +26 -0
- data/config.json +9 -0
- data/docs/Body.md +8 -0
- data/docs/DefaultApi.md +57 -0
- data/docs/ResponseToken.md +9 -0
- data/lib/bb_oauth/api/default_api.rb +85 -0
- data/lib/bb_oauth/api_client.rb +378 -0
- data/lib/bb_oauth/api_error.rb +41 -0
- data/lib/bb_oauth/configuration.rb +184 -0
- data/lib/bb_oauth/models/base_model.rb +174 -0
- data/lib/bb_oauth/models/body.rb +36 -0
- data/lib/bb_oauth/models/response_token.rb +43 -0
- data/lib/bb_oauth/version.rb +3 -0
- data/lib/bb_oauth.rb +31 -0
- data/spec/api/default_api_spec.rb +12 -0
- data/spec/api_client_spec.rb +201 -0
- data/spec/models/body_spec.rb +13 -0
- data/spec/models/response_token_spec.rb +14 -0
- data/spec/spec_helper.rb +13 -0
- data/swagger_oauth_client_credentials.json +93 -0
- metadata +133 -0
@@ -0,0 +1,174 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module BancoBrasilClientCredentials
|
4
|
+
class BaseModel
|
5
|
+
# List of attributes with nullable: true
|
6
|
+
def self.openapi_nullable
|
7
|
+
Set.new([])
|
8
|
+
end
|
9
|
+
|
10
|
+
# Initializes the object
|
11
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
12
|
+
def initialize(attributes = {})
|
13
|
+
unless attributes.is_a?(Hash)
|
14
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `#{self.class.name}` initialize method"
|
15
|
+
end
|
16
|
+
|
17
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
18
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
19
|
+
unless self.class.attribute_map.key?(k.to_sym)
|
20
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `#{self.class.name}`."\
|
21
|
+
' Please check the name to make sure it\'s valid. List of attributes: '\
|
22
|
+
"#{self.class.attribute_map.keys.inspect}"
|
23
|
+
end
|
24
|
+
h[k.to_sym] = v
|
25
|
+
}
|
26
|
+
|
27
|
+
attributes.each { |key, value| self.send("#{key}=", value) }
|
28
|
+
end
|
29
|
+
|
30
|
+
def list_invalid_properties
|
31
|
+
Array.new
|
32
|
+
end
|
33
|
+
|
34
|
+
# Check to see if the all the properties in the model are valid
|
35
|
+
# @return true if the model is valid
|
36
|
+
def valid?
|
37
|
+
list_invalid_properties.empty?
|
38
|
+
end
|
39
|
+
|
40
|
+
# Checks equality by comparing each attribute.
|
41
|
+
# @param o [Object] Object to be compared
|
42
|
+
def ==(o)
|
43
|
+
return true if self.equal?(o)
|
44
|
+
|
45
|
+
self.class == o.class && self.class.attribute_map.keys.all? { |attr| self.send(attr) == o.send(attr) }
|
46
|
+
end
|
47
|
+
|
48
|
+
# @see the `==` method
|
49
|
+
# @param o [Object] Object to be compared
|
50
|
+
def eql?(o)
|
51
|
+
self == o
|
52
|
+
end
|
53
|
+
|
54
|
+
# Calculates hash code according to all attributes.
|
55
|
+
# @return [Integer] Hash code
|
56
|
+
def hash
|
57
|
+
self.class.attribute_map.keys.map { |attr| self.send(attr) }.hash
|
58
|
+
end
|
59
|
+
|
60
|
+
# Builds the object from hash
|
61
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
62
|
+
# @return [Object] Returns the model itself
|
63
|
+
def self.build_from_hash(attributes)
|
64
|
+
new.build_from_hash(attributes)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Builds the object from hash
|
68
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
69
|
+
# @return [Object] Returns the model itself
|
70
|
+
def build_from_hash(attributes)
|
71
|
+
return nil unless attributes.is_a?(Hash)
|
72
|
+
self.class.openapi_types.each_pair do |key, type|
|
73
|
+
if type =~ /\AArray<(.*)>/i
|
74
|
+
# check to ensure the input is an array given that the attribute
|
75
|
+
# is documented as an array but the input is not
|
76
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
77
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
|
78
|
+
end
|
79
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
80
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
81
|
+
elsif attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
|
82
|
+
self.send("#{key}=", nil)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
self
|
87
|
+
end
|
88
|
+
|
89
|
+
# Deserializes the data based on type
|
90
|
+
# @param type [String] Data type
|
91
|
+
# @param value [String] Value to be deserialized
|
92
|
+
# @return [Object] Deserialized data
|
93
|
+
def _deserialize(type, value)
|
94
|
+
case type.to_sym
|
95
|
+
when :DateTime
|
96
|
+
DateTime.parse(value)
|
97
|
+
when :Date
|
98
|
+
Date.parse(value)
|
99
|
+
when :NumberDate
|
100
|
+
Date.strptime(value.to_s.rjust(8, '0'), '%d%m%Y')
|
101
|
+
when :String
|
102
|
+
value.to_s
|
103
|
+
when :Integer
|
104
|
+
value.to_i
|
105
|
+
when :Float
|
106
|
+
value.to_f
|
107
|
+
when :Boolean
|
108
|
+
value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
109
|
+
when :Object
|
110
|
+
# generic object (usually a Hash), return directly
|
111
|
+
value
|
112
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
113
|
+
inner_type = Regexp.last_match[:inner_type]
|
114
|
+
value.map { |v| _deserialize(inner_type, v) }
|
115
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
116
|
+
k_type = Regexp.last_match[:k_type]
|
117
|
+
v_type = Regexp.last_match[:v_type]
|
118
|
+
{}.tap do |hash|
|
119
|
+
value.each do |k, v|
|
120
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
else # model
|
124
|
+
BancoBrasilClientCredentials.const_get(type).build_from_hash(value)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# Returns the string representation of the object
|
129
|
+
# @return [String] String presentation of the object
|
130
|
+
def to_s
|
131
|
+
to_hash.to_s
|
132
|
+
end
|
133
|
+
|
134
|
+
# to_body is an alias to to_hash (backward compatibility)
|
135
|
+
# @return [Hash] Returns the object in the form of hash
|
136
|
+
def to_body
|
137
|
+
to_hash
|
138
|
+
end
|
139
|
+
|
140
|
+
# Returns the object in the form of hash
|
141
|
+
# @return [Hash] Returns the object in the form of hash
|
142
|
+
def to_hash
|
143
|
+
hash = {}
|
144
|
+
self.class.attribute_map.each_pair do |attr, param|
|
145
|
+
value = self.send(attr)
|
146
|
+
if value.nil?
|
147
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
148
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
149
|
+
end
|
150
|
+
|
151
|
+
hash[param] = _to_hash(value)
|
152
|
+
end
|
153
|
+
hash
|
154
|
+
end
|
155
|
+
|
156
|
+
# Outputs non-array value in the form of hash
|
157
|
+
# For object, use to_hash. Otherwise, just return the value
|
158
|
+
# @param [Object] value Any valid value
|
159
|
+
# @return [Hash] Returns the value in the form of hash
|
160
|
+
def _to_hash(value)
|
161
|
+
if value.is_a?(Array)
|
162
|
+
value.compact.map { |v| _to_hash(v) }
|
163
|
+
elsif value.is_a?(Hash)
|
164
|
+
{}.tap do |hash|
|
165
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
166
|
+
end
|
167
|
+
elsif value.respond_to? :to_hash
|
168
|
+
value.to_hash
|
169
|
+
else
|
170
|
+
value
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module BancoBrasilClientCredentials
|
4
|
+
class Body < BaseModel
|
5
|
+
# Deverá ser informado: client_credentials
|
6
|
+
attr_accessor :grant_type
|
7
|
+
|
8
|
+
# Os escopos deverão ser informados separados por espaço.
|
9
|
+
attr_accessor :scope
|
10
|
+
|
11
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
12
|
+
def self.attribute_map
|
13
|
+
{ grant_type: :grant_type, scope: :scope }
|
14
|
+
end
|
15
|
+
|
16
|
+
# Attribute type mapping.
|
17
|
+
def self.openapi_types
|
18
|
+
{ grant_type: :Object, scope: :Object }
|
19
|
+
end
|
20
|
+
|
21
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
22
|
+
# @return Array for valid properties with the reasons
|
23
|
+
def list_invalid_properties
|
24
|
+
invalid_properties = Array.new
|
25
|
+
if @grant_type.nil?
|
26
|
+
invalid_properties.push('invalid value for "grant_type", grant_type cannot be nil.')
|
27
|
+
end
|
28
|
+
|
29
|
+
if @scope.nil?
|
30
|
+
invalid_properties.push('invalid value for "scope", scope cannot be nil.')
|
31
|
+
end
|
32
|
+
|
33
|
+
invalid_properties
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module BancoBrasilClientCredentials
|
4
|
+
class ResponseToken < BaseModel
|
5
|
+
# Token de Acesso
|
6
|
+
attr_accessor :access_token
|
7
|
+
|
8
|
+
# Tipo de token
|
9
|
+
attr_accessor :token_type
|
10
|
+
|
11
|
+
# Tempo de Expiração do token
|
12
|
+
attr_accessor :expires_in
|
13
|
+
|
14
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
15
|
+
def self.attribute_map
|
16
|
+
{ access_token: :access_token, token_type: :token_type, expires_in: :expires_in }
|
17
|
+
end
|
18
|
+
|
19
|
+
# Attribute type mapping.
|
20
|
+
def self.openapi_types
|
21
|
+
{ access_token: :Object, token_type: :Object, expires_in: :Object }
|
22
|
+
end
|
23
|
+
|
24
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
25
|
+
# @return Array for valid properties with the reasons
|
26
|
+
def list_invalid_properties
|
27
|
+
invalid_properties = Array.new
|
28
|
+
if @access_token.nil?
|
29
|
+
invalid_properties.push('invalid value for "access_token", access_token cannot be nil.')
|
30
|
+
end
|
31
|
+
|
32
|
+
if @token_type.nil?
|
33
|
+
invalid_properties.push('invalid value for "token_type", token_type cannot be nil.')
|
34
|
+
end
|
35
|
+
|
36
|
+
if @expires_in.nil?
|
37
|
+
invalid_properties.push('invalid value for "expires_in", expires_in cannot be nil.')
|
38
|
+
end
|
39
|
+
|
40
|
+
invalid_properties
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/bb_oauth.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Common files
|
2
|
+
require 'bb_oauth/api_client'
|
3
|
+
require 'bb_oauth/api_error'
|
4
|
+
require 'bb_oauth/version'
|
5
|
+
require 'bb_oauth/configuration'
|
6
|
+
|
7
|
+
# Models
|
8
|
+
require 'bb_oauth/models/base_model'
|
9
|
+
require 'bb_oauth/models/body'
|
10
|
+
require 'bb_oauth/models/response_token'
|
11
|
+
|
12
|
+
# APIs
|
13
|
+
require 'bb_oauth/api/default_api'
|
14
|
+
|
15
|
+
module BancoBrasilClientCredentials
|
16
|
+
class << self
|
17
|
+
# Customize default settings for the SDK using block.
|
18
|
+
# BancoBrasilClientCredentials.configure do |config|
|
19
|
+
# config.username = "xxx"
|
20
|
+
# config.password = "xxx"
|
21
|
+
# end
|
22
|
+
# If no block given, return the default Configuration object.
|
23
|
+
def configure
|
24
|
+
if block_given?
|
25
|
+
yield(Configuration.default)
|
26
|
+
else
|
27
|
+
Configuration.default
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
describe 'DefaultApi' do
|
5
|
+
before { @instance = BancoBrasilClientCredentials::DefaultApi.new }
|
6
|
+
|
7
|
+
describe 'test an instance of DefaultApi' do
|
8
|
+
it 'should create an instance of DefaultApi' do
|
9
|
+
expect(@instance).to be_instance_of(BancoBrasilClientCredentials::DefaultApi)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,201 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BancoBrasilClientCredentials::ApiClient do
|
4
|
+
context 'initialization' do
|
5
|
+
context 'URL stuff' do
|
6
|
+
context 'host' do
|
7
|
+
it 'removes http from host' do
|
8
|
+
BancoBrasilClientCredentials.configure { |c| c.host = 'http://example.com' }
|
9
|
+
expect(BancoBrasilClientCredentials::Configuration.default.host).to eq('example.com')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'removes https from host' do
|
13
|
+
BancoBrasilClientCredentials.configure { |c| c.host = 'https://wookiee.com' }
|
14
|
+
expect(BancoBrasilClientCredentials::ApiClient.default.config.host).to eq('wookiee.com')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'removes trailing path from host' do
|
18
|
+
BancoBrasilClientCredentials.configure { |c| c.host = 'hobo.com/v4' }
|
19
|
+
expect(BancoBrasilClientCredentials::Configuration.default.host).to eq('hobo.com')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'base_path' do
|
24
|
+
it "prepends a slash to base_path" do
|
25
|
+
BancoBrasilClientCredentials.configure { |c| c.base_path = 'v4/dog' }
|
26
|
+
expect(BancoBrasilClientCredentials::Configuration.default.base_path).to eq('/v4/dog')
|
27
|
+
end
|
28
|
+
|
29
|
+
it "doesn't prepend a slash if one is already there" do
|
30
|
+
BancoBrasilClientCredentials.configure { |c| c.base_path = '/v4/dog' }
|
31
|
+
expect(BancoBrasilClientCredentials::Configuration.default.base_path).to eq('/v4/dog')
|
32
|
+
end
|
33
|
+
|
34
|
+
it "ends up as a blank string if nil" do
|
35
|
+
BancoBrasilClientCredentials.configure { |c| c.base_path = nil }
|
36
|
+
expect(BancoBrasilClientCredentials::Configuration.default.base_path).to eq('')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'params_encoding in #build_request' do
|
43
|
+
let(:config) { BancoBrasilClientCredentials::Configuration.new }
|
44
|
+
let(:api_client) { BancoBrasilClientCredentials::ApiClient.new(config) }
|
45
|
+
|
46
|
+
it 'defaults to nil' do
|
47
|
+
expect(BancoBrasilClientCredentials::Configuration.default.params_encoding).to eq(nil)
|
48
|
+
expect(config.params_encoding).to eq(nil)
|
49
|
+
|
50
|
+
request = api_client.build_request(:get, '/test')
|
51
|
+
expect(request.options[:params_encoding]).to eq(nil)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'can be customized' do
|
55
|
+
config.params_encoding = :multi
|
56
|
+
request = api_client.build_request(:get, '/test')
|
57
|
+
expect(request.options[:params_encoding]).to eq(:multi)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'timeout in #build_request' do
|
62
|
+
let(:config) { BancoBrasilClientCredentials::Configuration.new }
|
63
|
+
let(:api_client) { BancoBrasilClientCredentials::ApiClient.new(config) }
|
64
|
+
|
65
|
+
it 'defaults to 0' do
|
66
|
+
expect(BancoBrasilClientCredentials::Configuration.default.timeout).to eq(0)
|
67
|
+
expect(config.timeout).to eq(0)
|
68
|
+
|
69
|
+
request = api_client.build_request(:get, '/test')
|
70
|
+
expect(request.options[:timeout]).to eq(0)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'can be customized' do
|
74
|
+
config.timeout = 100
|
75
|
+
request = api_client.build_request(:get, '/test')
|
76
|
+
expect(request.options[:timeout]).to eq(100)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#deserialize' do
|
81
|
+
it "handles Array<Integer>" do
|
82
|
+
api_client = BancoBrasilClientCredentials::ApiClient.new
|
83
|
+
headers = { 'Content-Type' => 'application/json' }
|
84
|
+
response = double('response', headers: headers, body: '[12, 34]')
|
85
|
+
data = api_client.deserialize(response, 'Array<Integer>')
|
86
|
+
expect(data).to be_instance_of(Array)
|
87
|
+
expect(data).to eq([12, 34])
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'handles Array<Array<Integer>>' do
|
91
|
+
api_client = BancoBrasilClientCredentials::ApiClient.new
|
92
|
+
headers = { 'Content-Type' => 'application/json' }
|
93
|
+
response = double('response', headers: headers, body: '[[12, 34], [56]]')
|
94
|
+
data = api_client.deserialize(response, 'Array<Array<Integer>>')
|
95
|
+
expect(data).to be_instance_of(Array)
|
96
|
+
expect(data).to eq([[12, 34], [56]])
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'handles Hash<String, String>' do
|
100
|
+
api_client = BancoBrasilClientCredentials::ApiClient.new
|
101
|
+
headers = { 'Content-Type' => 'application/json' }
|
102
|
+
response = double('response', headers: headers, body: '{"message": "Hello"}')
|
103
|
+
data = api_client.deserialize(response, 'Hash<String, String>')
|
104
|
+
expect(data).to be_instance_of(Hash)
|
105
|
+
expect(data).to eq(:message => 'Hello')
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '#build_collection_param' do
|
110
|
+
let(:param) { ['aa', 'bb', 'cc'] }
|
111
|
+
let(:api_client) { BancoBrasilClientCredentials::ApiClient.new }
|
112
|
+
|
113
|
+
it 'works for csv' do
|
114
|
+
expect(api_client.build_collection_param(param, :csv)).to eq('aa,bb,cc')
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'works for ssv' do
|
118
|
+
expect(api_client.build_collection_param(param, :ssv)).to eq('aa bb cc')
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'works for tsv' do
|
122
|
+
expect(api_client.build_collection_param(param, :tsv)).to eq("aa\tbb\tcc")
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'works for pipes' do
|
126
|
+
expect(api_client.build_collection_param(param, :pipes)).to eq('aa|bb|cc')
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'works for multi' do
|
130
|
+
expect(api_client.build_collection_param(param, :multi)).to eq(['aa', 'bb', 'cc'])
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'fails for invalid collection format' do
|
134
|
+
expect(proc { api_client.build_collection_param(param, :INVALID) }).to raise_error(RuntimeError, 'unknown collection format: :INVALID')
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe '#json_mime?' do
|
139
|
+
let(:api_client) { BancoBrasilClientCredentials::ApiClient.new }
|
140
|
+
|
141
|
+
it 'works' do
|
142
|
+
expect(api_client.json_mime?(nil)).to eq false
|
143
|
+
expect(api_client.json_mime?('')).to eq false
|
144
|
+
|
145
|
+
expect(api_client.json_mime?('application/json')).to eq true
|
146
|
+
expect(api_client.json_mime?('application/json; charset=UTF8')).to eq true
|
147
|
+
expect(api_client.json_mime?('APPLICATION/JSON')).to eq true
|
148
|
+
|
149
|
+
expect(api_client.json_mime?('application/xml')).to eq false
|
150
|
+
expect(api_client.json_mime?('text/plain')).to eq false
|
151
|
+
expect(api_client.json_mime?('application/jsonp')).to eq false
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe '#select_header_accept' do
|
156
|
+
let(:api_client) { BancoBrasilClientCredentials::ApiClient.new }
|
157
|
+
|
158
|
+
it 'works' do
|
159
|
+
expect(api_client.select_header_accept(nil)).to be_nil
|
160
|
+
expect(api_client.select_header_accept([])).to be_nil
|
161
|
+
|
162
|
+
expect(api_client.select_header_accept(['application/json'])).to eq('application/json')
|
163
|
+
expect(api_client.select_header_accept(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
|
164
|
+
expect(api_client.select_header_accept(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
|
165
|
+
|
166
|
+
expect(api_client.select_header_accept(['application/xml'])).to eq('application/xml')
|
167
|
+
expect(api_client.select_header_accept(['text/html', 'application/xml'])).to eq('text/html,application/xml')
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
describe '#select_header_content_type' do
|
172
|
+
let(:api_client) { BancoBrasilClientCredentials::ApiClient.new }
|
173
|
+
|
174
|
+
it 'works' do
|
175
|
+
expect(api_client.select_header_content_type(nil)).to eq('application/json')
|
176
|
+
expect(api_client.select_header_content_type([])).to eq('application/json')
|
177
|
+
|
178
|
+
expect(api_client.select_header_content_type(['application/json'])).to eq('application/json')
|
179
|
+
expect(api_client.select_header_content_type(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
|
180
|
+
expect(api_client.select_header_content_type(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
|
181
|
+
expect(api_client.select_header_content_type(['application/xml'])).to eq('application/xml')
|
182
|
+
expect(api_client.select_header_content_type(['text/plain', 'application/xml'])).to eq('text/plain')
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe '#sanitize_filename' do
|
187
|
+
let(:api_client) { BancoBrasilClientCredentials::ApiClient.new }
|
188
|
+
|
189
|
+
it 'works' do
|
190
|
+
expect(api_client.sanitize_filename('sun')).to eq('sun')
|
191
|
+
expect(api_client.sanitize_filename('sun.gif')).to eq('sun.gif')
|
192
|
+
expect(api_client.sanitize_filename('../sun.gif')).to eq('sun.gif')
|
193
|
+
expect(api_client.sanitize_filename('/var/tmp/sun.gif')).to eq('sun.gif')
|
194
|
+
expect(api_client.sanitize_filename('./sun.gif')).to eq('sun.gif')
|
195
|
+
expect(api_client.sanitize_filename('..\sun.gif')).to eq('sun.gif')
|
196
|
+
expect(api_client.sanitize_filename('\var\tmp\sun.gif')).to eq('sun.gif')
|
197
|
+
expect(api_client.sanitize_filename('c:\var\tmp\sun.gif')).to eq('sun.gif')
|
198
|
+
expect(api_client.sanitize_filename('.\sun.gif')).to eq('sun.gif')
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'json'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
describe 'Body' do
|
6
|
+
before { @instance = BancoBrasilClientCredentials::Body.new }
|
7
|
+
|
8
|
+
describe 'test an instance of Body' do
|
9
|
+
it 'should create an instance of Body' do
|
10
|
+
expect(@instance).to be_instance_of(BancoBrasilClientCredentials::Body)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'json'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
|
6
|
+
describe 'ResponseToken' do
|
7
|
+
before { @instance = BancoBrasilClientCredentials::ResponseToken.new }
|
8
|
+
|
9
|
+
describe 'test an instance of ResponseToken' do
|
10
|
+
it 'should create an instance of ResponseToken' do
|
11
|
+
expect(@instance).to be_instance_of(BancoBrasilClientCredentials::ResponseToken)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# load the gem
|
2
|
+
require 'bb_oauth'
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
|
6
|
+
config.expect_with :rspec do |expectations|
|
7
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
8
|
+
end
|
9
|
+
|
10
|
+
config.mock_with :rspec do |mocks|
|
11
|
+
mocks.verify_partial_doubles = true
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
{
|
2
|
+
"swagger": "2.0",
|
3
|
+
"info": {
|
4
|
+
"title": "Fluxo Client Credentials",
|
5
|
+
"version": "1.0.0"
|
6
|
+
},
|
7
|
+
"host": "oauth.bb.com.br",
|
8
|
+
"schemes": [
|
9
|
+
"https"
|
10
|
+
],
|
11
|
+
"consumes": [
|
12
|
+
"application/x-www-form-urlencoded"
|
13
|
+
],
|
14
|
+
"produces": [
|
15
|
+
"application/x-www-form-urlencoded"
|
16
|
+
],
|
17
|
+
"paths": {
|
18
|
+
"/oauth/token": {
|
19
|
+
"post": {
|
20
|
+
"parameters": [
|
21
|
+
{
|
22
|
+
"name": "grant_type",
|
23
|
+
"description": "Deverá ser informado: client_credentials",
|
24
|
+
"in": "formData",
|
25
|
+
"required": true,
|
26
|
+
"type": "string"
|
27
|
+
},
|
28
|
+
{
|
29
|
+
"name": "scope",
|
30
|
+
"description": "Os escopos deverão ser informados separados por espaço.",
|
31
|
+
"in": "formData",
|
32
|
+
"required": true,
|
33
|
+
"type": "string"
|
34
|
+
},
|
35
|
+
{
|
36
|
+
"name": "Content-Type",
|
37
|
+
"description": "Deverá ser informado: application/x-www-form-urlencoded\n",
|
38
|
+
"in": "header",
|
39
|
+
"required": true,
|
40
|
+
"type": "string"
|
41
|
+
}
|
42
|
+
],
|
43
|
+
"responses": {
|
44
|
+
"200": {
|
45
|
+
"schema": {
|
46
|
+
"$ref": "#/definitions/ResponseToken"
|
47
|
+
},
|
48
|
+
"description": "Geração de Access Token"
|
49
|
+
}
|
50
|
+
}
|
51
|
+
},
|
52
|
+
"parameters": [
|
53
|
+
{
|
54
|
+
"name": "Authorization",
|
55
|
+
"description": "Deverá ser informado no padrão: Basic {Base64(client_id:client_secret)}",
|
56
|
+
"in": "header",
|
57
|
+
"required": true,
|
58
|
+
"type": "string"
|
59
|
+
},
|
60
|
+
{
|
61
|
+
"name": "Content-Type",
|
62
|
+
"description": "Deverá ser informado: application/x-www-form-urlencoded\n",
|
63
|
+
"in": "header",
|
64
|
+
"required": true,
|
65
|
+
"type": "string"
|
66
|
+
}
|
67
|
+
]
|
68
|
+
}
|
69
|
+
},
|
70
|
+
"definitions": {
|
71
|
+
"ResponseToken": {
|
72
|
+
"description": "",
|
73
|
+
"required": [
|
74
|
+
"access_token",
|
75
|
+
"token_type",
|
76
|
+
"expires_in"
|
77
|
+
],
|
78
|
+
"type": "object",
|
79
|
+
"properties": {
|
80
|
+
"access_token": {
|
81
|
+
"description": "Token de Acesso"
|
82
|
+
},
|
83
|
+
"token_type": {
|
84
|
+
"description": "Tipo de token"
|
85
|
+
},
|
86
|
+
"expires_in": {
|
87
|
+
"description": "Tempo de Expiração do token"
|
88
|
+
}
|
89
|
+
},
|
90
|
+
"example": "{\n \"access_token\": \"Yyr_4-0c2bgPhzbH60SkEmMuJO77DI9ZESN-vZBZ_hMK8BNMOAvlw.6en65sKd2itKfRwqKEr\n 7nZPbT6C4S6AglgqDtDwaUsBgHlbLFzjgZevTxnyv1Zjh0SZQNMTngzw1E60vJkPSJQXWOam2\n EylIQ_-j7lOfWjLiLX6zdBF-4BC_9r2IqA5EQhKS\\eZxkN17FcPTwaOpzsOb6tMxvmg6hWVpx\n YKMoye64go1VOtPZprBEnjdu3xZIhDFYWcKSfaGJDpcvNXczSQZoK7i19FZetvDa-QX9AO1NK\n SQVQXSj-uSK3OnwUQXZySBotR5B_IklGV5oyguUN7ZA3wUMZohhhMTRh9CavKEEG1sf1L8Ygk\n vTpTVQv7W9xKhCzqm8Oyy25JrmOaeeI0BYVREc83BitfNKAp3Gf-7mfS6YOit8LWbdfJxxrRA\n AIRGhRmCDjahPd_fiRMR4nr-lDi0LHtmlKWVWeswFKdOj1uKsJ8adqL18ksdKfZBJWXh0XFb4\n EALjmojkE6t0L_7zrwdNySonkqKotGVwbm3n5j5Eyleqc2O7J11Y2bljHbdLWk7vtUpHmhGEL\n zjK-N66iLIhDKZmQEZKILBskWCq5jeSC-ZfF1dkJML-4Jl3nB1DtbyKVlB6Sv65_kJ-qNOCfT\n aiifV03VcFvx6cM5qKFozintpvxq8ht8M0M.fxPC5LQXbBSE9WNnHVBGY1qKfGDodeLNI4-qg\n 4jP5hLKIfLGzOo43zmqiABAToVLZyj3oJACKk-tyGGovpFd4Q\",\n \"token_type\": \"Bearer\",\n \"expires_in\": 600\n}"
|
91
|
+
}
|
92
|
+
}
|
93
|
+
}
|