charging-client 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,71 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Charging::ServiceAccount, :vcr do
5
+ describe '.current' do
6
+ it 'should return current service account' do
7
+ VCR.use_cassette('ServiceAccount/valid request for get current service account') do
8
+ expect { described_class.current }.to_not raise_error
9
+ end
10
+ end
11
+ end
12
+
13
+ describe '.find_by_token' do
14
+ context 'with an invalid application token' do
15
+ it 'should raise a last response error' do
16
+ VCR.use_cassette('ServiceAccount/invalid token for a service account') do
17
+ error = [Charging::Http::LastResponseError, /401 Unauthorized/]
18
+
19
+ expect { described_class.find_by_token('invalid-token') }.to raise_error(*error)
20
+ end
21
+ end
22
+ end
23
+
24
+ context 'with a valid application token' do
25
+ before do
26
+ VCR.use_cassette('ServiceAccount/valid token for a service account') do
27
+ @result = described_class.find_by_token('AwdhihciTgORGUjnkuk1vg==')
28
+ end
29
+ end
30
+
31
+ it 'should return a ServiceAccount instance' do
32
+ expect(@result).to be_an_instance_of(Charging::ServiceAccount)
33
+ end
34
+
35
+ context 'with current service account' do
36
+ subject { @result }
37
+
38
+ describe '#plan' do
39
+ subject { super().plan }
40
+ it { is_expected.to eq 'full' }
41
+ end
42
+
43
+ describe '#name' do
44
+ subject { super().name }
45
+ it { is_expected.to eq 'Teste cliente Ruby' }
46
+ end
47
+
48
+ describe '#uri' do
49
+ subject { super().uri }
50
+ it { is_expected.to eq 'http://sandbox.app.passaporteweb.com.br/organizations/api/accounts/3a0676fb-6639-466a-ac35-9ea7c5f67386/' }
51
+ end
52
+
53
+ describe '#uuid' do
54
+ subject { super().uuid }
55
+ it { is_expected.to eq '3a0676fb-6639-466a-ac35-9ea7c5f67386' }
56
+ end
57
+
58
+ describe '#application_token' do
59
+ subject { super().application_token }
60
+ it { is_expected.to eq 'AwdhihciTgORGUjnkuk1vg==' }
61
+ end
62
+ end
63
+
64
+ it 'should return ok (200) response at last response' do
65
+ last_response = @result.last_response
66
+
67
+ expect(last_response.code).to eql 200
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Charging do
5
+
6
+ it 'should have a version number' do
7
+ expect(Charging::VERSION).not_to be_nil
8
+ end
9
+
10
+ describe '.configuration' do
11
+ it 'should user a singleton object for the configuration values' do
12
+ expect(Charging.configuration).to eql Charging.configuration
13
+ end
14
+ end
15
+
16
+ describe '.configure' do
17
+ subject { Charging.configuration }
18
+
19
+ before do
20
+ Charging.configure do |c|
21
+ c.application_token = 'AppToken=='
22
+ c.url = 'https://some.host'
23
+ c.user_agent = 'Testing with RSpec'
24
+ end
25
+ end
26
+
27
+ describe '#application_token' do
28
+ subject { super().application_token }
29
+ it { is_expected.to eq 'AppToken==' }
30
+ end
31
+
32
+ describe '#url' do
33
+ subject { super().url }
34
+ it { is_expected.to eq 'https://some.host' }
35
+ end
36
+
37
+ describe '#user_agent' do
38
+ subject { super().user_agent }
39
+ it { is_expected.to eq 'Testing with RSpec'}
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,8 @@
1
+ {
2
+ "supplier_name" : "Acme Elétrica Ltda",
3
+ "national_identifier" : "73.331.840/0001-00",
4
+ "address" : "Av. Nelson Cardoso, 123 - Jacarepaguá",
5
+ "city_state" : "Rio de Janeiro / RJ",
6
+ "zipcode" : "20211-360",
7
+ "description" : "Descrição incrível sobre a Acme Elétrica"
8
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "supplier_name" : "Acme Elétrica Ltda",
3
+ "national_identifier" : "73.331.840/0001-00",
4
+ "address" : "Av. Nelson Cardoso, 123 - Jacarepaguá",
5
+ "city_state" : "Rio de Janeiro / RJ",
6
+ "zipcode" : "20211-360",
7
+ "description" : "Descrição incrível sobre a Acme Elétrica",
8
+ "uuid" : "154932d8-66b8-4e6b-82f5-ebb1d32fe85d"
9
+ }
@@ -0,0 +1,69 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
+ SimpleCov::Formatter::HTMLFormatter,
5
+ Coveralls::SimpleCov::Formatter
6
+ ]
7
+ SimpleCov.start
8
+
9
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
10
+ require 'charging'
11
+
12
+ require 'vcr'
13
+ require 'pry'
14
+
15
+ # Load all support files
16
+ Dir[File.join(File.dirname(__FILE__), 'support/*.rb')].each do |file|
17
+ require file
18
+ end
19
+
20
+ VCR.configure do |c|
21
+ c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
22
+ c.hook_into :webmock
23
+ c.ignore_localhost = true
24
+ c.default_cassette_options = { :record => :once }
25
+ c.configure_rspec_metadata!
26
+ end
27
+
28
+ RSpec.configure do |c|
29
+ c.mock_with :rspec
30
+
31
+ c.filter_run focus: true
32
+ c.run_all_when_everything_filtered = true
33
+
34
+ # so we can use :vcr rather than :vcr => true;
35
+ # in RSpec 3 this will no longer be necessary.
36
+ c.treat_symbols_as_metadata_keys_with_true_values = true
37
+
38
+ c.before(:vcr => true) do
39
+ Charging.configure do |config|
40
+ config.url = 'http://sandbox.charging.financeconnect.com.br:8080'
41
+ config.application_token = 'AwdhihciTgORGUjnkuk1vg=='
42
+ end
43
+
44
+ # uncomment below lines to turn off VCR
45
+ # WebMock.allow_net_connect!
46
+ # VCR.eject_cassette
47
+ # VCR.turn_off!(ignore_cassettes: true)
48
+ end
49
+
50
+ def current_account
51
+ @current_account ||= Charging::ServiceAccount.current
52
+ end
53
+
54
+ def create_domain(account, national_identifier, attributes = {})
55
+ Factory.create_resource(
56
+ Charging::Domain,
57
+ account,
58
+ Factory.domain_attributes(national_identifier).merge(attributes)
59
+ )
60
+ end
61
+
62
+ def create_charge_account(domain, attributes = {})
63
+ Factory.create_resource(
64
+ Charging::ChargeAccount,
65
+ domain,
66
+ Factory.charge_account_attributes.merge(attributes)
67
+ )
68
+ end
69
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+
3
+ module Factory
4
+ module_function
5
+
6
+ def domain_attributes(national_identifier)
7
+ {
8
+ supplier_name: 'Springfield Elemenary School',
9
+ address: '1608 Florida Avenue',
10
+ city_state: 'Greenwood/SC',
11
+ zipcode: '29646',
12
+ national_identifier: national_identifier,
13
+ description: 'The mission of Greenwood School District 50 is to educate all students to become responsible and productive citizens.',
14
+ }
15
+ end
16
+
17
+ def charge_account_attributes
18
+ {
19
+ bank: '237',
20
+ name: 'Conta de cobrança',
21
+ agreement_code: '12345',
22
+ portfolio_code: '25',
23
+ account: {number: '12345', digit: '6'},
24
+ agency: {number: '12345', digit: '6'},
25
+ currency: 9
26
+ }
27
+ end
28
+
29
+ def create_resource(klass, parent, attributes)
30
+ klass.new(attributes, parent).create!
31
+ end
32
+ end
@@ -0,0 +1,56 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ # Based on https://github.com/bernardo/cpf_faker
5
+ module Faker
6
+ module_function
7
+
8
+ def cnpj_generator(cnpj_base = nil)
9
+ cnpj_root = cnpj_base.nil? ? Array.new(12) { rand(10) } : cnpj_base.split('').map(&:to_i)
10
+
11
+ # calculate first digit
12
+ factor = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
13
+
14
+ sum = (0..11).inject(0) do |sum, i|
15
+ sum + cnpj_root[i] * factor[i]
16
+ end
17
+
18
+ first_validator = sum % 11
19
+ cnpj_root << first_validator = first_validator < 2 ? 0 : 11 - first_validator
20
+
21
+ # calculate second digit
22
+ factor.unshift 6
23
+
24
+ sum = (0..12).inject(0) do |sum, i|
25
+ sum + cnpj_root[i] * factor[i]
26
+ end
27
+
28
+ second_validator = sum % 11
29
+ (cnpj_root << second_validator = second_validator < 2 ? 0 : 11 - second_validator).join
30
+ end
31
+
32
+ def cpf_generator(cpf_base = nil)
33
+
34
+ cpf_root = cpf_base.nil? ? Array.new(9) { rand(10) } : cpf_base.split('').map(&:to_i)
35
+
36
+ # calculate first digit
37
+ sum = (0..8).inject(0) do |sum, i|
38
+ sum + cpf_root[i] * (10 - i)
39
+ end
40
+
41
+ first_validator = sum % 11
42
+ first_validator = first_validator < 2 ? 0 : 11 - first_validator
43
+ cpf_root << first_validator
44
+
45
+ # calculate second digit
46
+ sum = (0..8).inject(0) do |sum, i|
47
+ sum + cpf_root[i] * (11 - i)
48
+ end
49
+
50
+ sum += first_validator * 2
51
+
52
+ second_validator = sum % 11
53
+ second_validator = second_validator < 2 ? 0 : 11 - second_validator
54
+ (cpf_root << second_validator).join
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,283 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: charging-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Rodrigo Tassinari de Oliveira
8
+ - Celestino Gomes
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-06-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 1.6.7
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 1.6.7
28
+ - !ruby/object:Gem::Dependency
29
+ name: multi_json
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.11'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.11'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">"
47
+ - !ruby/object:Gem::Version
48
+ version: 1.3.2
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">"
54
+ - !ruby/object:Gem::Version
55
+ version: 1.3.2
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '10.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '10.0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rdoc
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '4.0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '4.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '2.13'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '2.13'
98
+ - !ruby/object:Gem::Dependency
99
+ name: vcr
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '2.4'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '2.4'
112
+ - !ruby/object:Gem::Dependency
113
+ name: webmock
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: 1.9.3
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: 1.9.3
126
+ - !ruby/object:Gem::Dependency
127
+ name: pry
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '0.9'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '0.9'
140
+ - !ruby/object:Gem::Dependency
141
+ name: pry-nav
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - "~>"
145
+ - !ruby/object:Gem::Version
146
+ version: '0.2'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: '0.2'
154
+ - !ruby/object:Gem::Dependency
155
+ name: awesome_print
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - "~>"
159
+ - !ruby/object:Gem::Version
160
+ version: '1.1'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - "~>"
166
+ - !ruby/object:Gem::Version
167
+ version: '1.1'
168
+ - !ruby/object:Gem::Dependency
169
+ name: simplecov
170
+ requirement: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - "~>"
173
+ - !ruby/object:Gem::Version
174
+ version: '0.7'
175
+ type: :development
176
+ prerelease: false
177
+ version_requirements: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - "~>"
180
+ - !ruby/object:Gem::Version
181
+ version: '0.7'
182
+ - !ruby/object:Gem::Dependency
183
+ name: coveralls
184
+ requirement: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - "~>"
187
+ - !ruby/object:Gem::Version
188
+ version: '0.6'
189
+ type: :development
190
+ prerelease: false
191
+ version_requirements: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - "~>"
194
+ - !ruby/object:Gem::Version
195
+ version: '0.6'
196
+ description: A Ruby client for the Charging REST API
197
+ email:
198
+ - rodrigo@pittlandia.net
199
+ - rodrigo.tassinari@myfreecomm.com.br
200
+ - tinorj@gmail.com
201
+ - celestino.gomes@myfreecomm.com.br
202
+ executables: []
203
+ extensions: []
204
+ extra_rdoc_files: []
205
+ files:
206
+ - ".coveralls.yml"
207
+ - ".gitignore"
208
+ - ".rspec"
209
+ - ".travis.yml"
210
+ - Gemfile
211
+ - Gemfile.lock
212
+ - LICENSE
213
+ - README.rdoc
214
+ - Rakefile
215
+ - charging-client.gemspec
216
+ - lib/charging.rb
217
+ - lib/charging/base.rb
218
+ - lib/charging/charge_account.rb
219
+ - lib/charging/collection.rb
220
+ - lib/charging/configuration.rb
221
+ - lib/charging/domain.rb
222
+ - lib/charging/helpers.rb
223
+ - lib/charging/http.rb
224
+ - lib/charging/invoice.rb
225
+ - lib/charging/service_account.rb
226
+ - lib/charging/version.rb
227
+ - spec/charging/charge_account_collection_spec.rb
228
+ - spec/charging/charge_account_spec.rb
229
+ - spec/charging/configuration_spec.rb
230
+ - spec/charging/domain_collection_spec.rb
231
+ - spec/charging/domain_spec.rb
232
+ - spec/charging/helpers_spec.rb
233
+ - spec/charging/http_last_response_error_spec.rb
234
+ - spec/charging/http_spec.rb
235
+ - spec/charging/invoice_spec.rb
236
+ - spec/charging/service_account_spec.rb
237
+ - spec/charging_spec.rb
238
+ - spec/fixtures/new_user.json
239
+ - spec/fixtures/recreate_user.json
240
+ - spec/spec_helper.rb
241
+ - spec/support/factory.rb
242
+ - spec/support/faker.rb
243
+ homepage: https://github.com/myfreecomm/charging-client-ruby
244
+ licenses:
245
+ - Apache-v2
246
+ metadata: {}
247
+ post_install_message:
248
+ rdoc_options: []
249
+ require_paths:
250
+ - lib
251
+ required_ruby_version: !ruby/object:Gem::Requirement
252
+ requirements:
253
+ - - ">="
254
+ - !ruby/object:Gem::Version
255
+ version: '0'
256
+ required_rubygems_version: !ruby/object:Gem::Requirement
257
+ requirements:
258
+ - - ">="
259
+ - !ruby/object:Gem::Version
260
+ version: '0'
261
+ requirements: []
262
+ rubyforge_project:
263
+ rubygems_version: 2.5.1
264
+ signing_key:
265
+ specification_version: 4
266
+ summary: A Ruby client for the Charging REST API
267
+ test_files:
268
+ - spec/charging/charge_account_collection_spec.rb
269
+ - spec/charging/charge_account_spec.rb
270
+ - spec/charging/configuration_spec.rb
271
+ - spec/charging/domain_collection_spec.rb
272
+ - spec/charging/domain_spec.rb
273
+ - spec/charging/helpers_spec.rb
274
+ - spec/charging/http_last_response_error_spec.rb
275
+ - spec/charging/http_spec.rb
276
+ - spec/charging/invoice_spec.rb
277
+ - spec/charging/service_account_spec.rb
278
+ - spec/charging_spec.rb
279
+ - spec/fixtures/new_user.json
280
+ - spec/fixtures/recreate_user.json
281
+ - spec/spec_helper.rb
282
+ - spec/support/factory.rb
283
+ - spec/support/faker.rb