myfinance 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +24 -0
  3. data/.rubocop.yml +1156 -0
  4. data/.travis.yml +3 -3
  5. data/Gemfile.lock +7 -7
  6. data/README.md +309 -2
  7. data/lib/myfinance.rb +15 -0
  8. data/lib/myfinance/client.rb +20 -0
  9. data/lib/myfinance/entities/account.rb +26 -0
  10. data/lib/myfinance/entities/account_collection.rb +16 -0
  11. data/lib/myfinance/entities/category.rb +22 -0
  12. data/lib/myfinance/entities/category_collection.rb +16 -0
  13. data/lib/myfinance/entities/classification_center.rb +15 -0
  14. data/lib/myfinance/entities/classification_center_collection.rb +18 -0
  15. data/lib/myfinance/entities/deposit_account.rb +24 -0
  16. data/lib/myfinance/entities/deposit_account_collection.rb +16 -0
  17. data/lib/myfinance/entities/person.rb +38 -0
  18. data/lib/myfinance/entities/person_collection.rb +14 -0
  19. data/lib/myfinance/resources/account.rb +25 -0
  20. data/lib/myfinance/resources/category.rb +81 -0
  21. data/lib/myfinance/resources/classification_center.rb +103 -0
  22. data/lib/myfinance/resources/deposit_account.rb +93 -0
  23. data/lib/myfinance/resources/person.rb +97 -0
  24. data/lib/myfinance/version.rb +1 -1
  25. data/spec/lib/myfinance/client_spec.rb +40 -0
  26. data/spec/lib/myfinance/entities/account_collection_spec.rb +19 -0
  27. data/spec/lib/myfinance/entities/account_spec.rb +13 -0
  28. data/spec/lib/myfinance/entities/category_collection_spec.rb +47 -0
  29. data/spec/lib/myfinance/entities/category_spec.rb +12 -0
  30. data/spec/lib/myfinance/entities/classification_center_collection_spec.rb +23 -0
  31. data/spec/lib/myfinance/entities/classification_center_spec.rb +8 -0
  32. data/spec/lib/myfinance/entities/deposit_account_collection_spec.rb +23 -0
  33. data/spec/lib/myfinance/entities/deposit_account_spec.rb +11 -0
  34. data/spec/lib/myfinance/entities/person_collection_spec.rb +26 -0
  35. data/spec/lib/myfinance/entities/person_spec.rb +18 -0
  36. data/spec/lib/myfinance/resources/account_spec.rb +28 -0
  37. data/spec/lib/myfinance/resources/category_spec.rb +118 -0
  38. data/spec/lib/myfinance/resources/classification_center_spec.rb +147 -0
  39. data/spec/lib/myfinance/resources/deposit_account_spec.rb +123 -0
  40. data/spec/lib/myfinance/resources/person_spec.rb +139 -0
  41. metadata +50 -3
@@ -0,0 +1,147 @@
1
+ require "spec_helper"
2
+
3
+ describe Myfinance::Resources::ClassificationCenter, vcr: true do
4
+ let(:entity_klass) { Myfinance::Entities::ClassificationCenter }
5
+
6
+ let(:entity_collection) do
7
+ Myfinance::Entities::ClassificationCenterCollection
8
+ end
9
+
10
+ describe "#find_all" do
11
+ context "when success" do
12
+ subject { client.classification_centers.find_all }
13
+
14
+ it "show all classifications center" do
15
+ expect(subject).to be_a(entity_collection)
16
+ expect(subject.collection.first).to be_a(entity_klass)
17
+ expect(subject.collection.first.name).to eq("Centro de Custo Tal")
18
+ end
19
+ end
20
+
21
+ context "when error" do
22
+ let(:client) { Myfinance.client("") }
23
+
24
+ it "raises Myfinance::RequestError with 401 status code" do
25
+ expect {
26
+ client.classification_centers.find_all
27
+ }.to raise_error(Myfinance::RequestError) do |error|
28
+ expect(error.code).to eq(401)
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ describe "#find" do
35
+ context "when success" do
36
+ subject { client.classification_centers.find(17982) }
37
+
38
+ it "show a classification center successfully" do
39
+ expect(subject).to be_a(entity_klass)
40
+ expect(subject.name).to eq("Centro de Custo Tal")
41
+ end
42
+ end
43
+
44
+ context "when error" do
45
+ it "raises Myfinance::RequestError with 404 status code" do
46
+ expect {
47
+ client.classification_centers.find(888888)
48
+ }.to raise_error(Myfinance::RequestError) do |error|
49
+ expect(error.code).to eq(404)
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ describe "#find_by" do
56
+ context "when success" do
57
+ let(:params) do
58
+ { entity_id_equals: 3798, name_equals: "Centro de Custo Tal" }
59
+ end
60
+
61
+ it "find a classification centers by name successfully" do
62
+ result = client.classification_centers.find_by(params)
63
+ expect(result).to be_a(entity_collection)
64
+ expect(result.collection.first).to be_a(entity_klass)
65
+ expect(result.collection.first.name).to eq("Centro de Custo Tal")
66
+ end
67
+
68
+ it "returns a empty classification center successfully" do
69
+ result = client.classification_centers.find_by(
70
+ { entity_id_equals: 3798, name_equals: "Any" }
71
+ )
72
+ expect(result).to be_a(entity_collection)
73
+ expect(result.collection.first).to be_falsy
74
+ end
75
+ end
76
+ end
77
+
78
+ describe "#create" do
79
+ context "when success" do
80
+ let(:params) do
81
+ {
82
+ cost_center: true,
83
+ entity_id: 3798,
84
+ name: "Centro de custo 1",
85
+ revenu_center: false,
86
+ use_count: 0
87
+ }
88
+ end
89
+
90
+ it "creates a classification center" do
91
+ result = client.classification_centers.create(params)
92
+ expect(result).to be_a(entity_klass)
93
+ expect(result.name).to eq("Centro de custo 1")
94
+ end
95
+ end
96
+
97
+ context "when error" do
98
+ it "raises Myfinance::RequestError with 422 status code" do
99
+ expect {
100
+ client.classification_centers.create({})
101
+ }.to raise_error(Myfinance::RequestError) do |error|
102
+ expect(error.code).to eq(422)
103
+ end
104
+ end
105
+ end
106
+ end
107
+
108
+ describe "#update" do
109
+ context "when success" do
110
+ let(:params) { { name: "Centro de custo updated" } }
111
+
112
+ it "updates a classification center successfully" do
113
+ expect(
114
+ client.classification_centers.update(18744, params)
115
+ ).to be_a(entity_klass)
116
+ end
117
+ end
118
+
119
+ context "when error" do
120
+ it "raises Myfinance::RequestError with 422 status code" do
121
+ expect {
122
+ client.classification_centers.update(18744, { name: "" })
123
+ }.to raise_error(Myfinance::RequestError) do |error|
124
+ expect(error.code).to eq(422)
125
+ end
126
+ end
127
+ end
128
+ end
129
+
130
+ describe "#delete" do
131
+ context "when success" do
132
+ it "destroy a classification center successfully" do
133
+ expect(client.classification_centers.destroy(18744)).to be_truthy
134
+ end
135
+ end
136
+
137
+ context "when error" do
138
+ it "raises Myfinance::RequestError with 404 status code" do
139
+ expect {
140
+ client.classification_centers.destroy(888888)
141
+ }.to raise_error(Myfinance::RequestError) do |error|
142
+ expect(error.code).to eq(404)
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,123 @@
1
+ require "spec_helper"
2
+
3
+ describe Myfinance::Resources::DepositAccount, vcr: true do
4
+ let(:entity_klass) { Myfinance::Entities::DepositAccount }
5
+
6
+ describe "#find_all" do
7
+ context "when success" do
8
+ subject { client.deposit_accounts.find_all(3798) }
9
+
10
+ it "show all deposit accounts" do
11
+ subject.build
12
+ expect(subject).to be_a(Myfinance::Entities::DepositAccountCollection)
13
+ expect(subject.collection.first).to be_a(entity_klass)
14
+ expect(subject.collection.first.name).to eq("Carteira")
15
+ end
16
+ end
17
+
18
+ context "when error" do
19
+ let(:client) { Myfinance.client("") }
20
+
21
+ it "raises Myfinance::RequestError with 401 status code" do
22
+ expect {
23
+ client.deposit_accounts.find_all(3798)
24
+ }.to raise_error(Myfinance::RequestError) do |error|
25
+ expect(error.code).to eq(401)
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ describe "#find" do
32
+ context "when success" do
33
+ it "show a deposit account successfully" do
34
+ result = client.deposit_accounts.find(3798, 14268)
35
+ expect(result).to be_a(entity_klass)
36
+ expect(result.name).to eq("Carteira")
37
+ end
38
+ end
39
+
40
+ context "when error" do
41
+ it "raises Myfinance::RequestError with 404 status code" do
42
+ expect {
43
+ client.deposit_accounts.find(3798, 888888)
44
+ }.to raise_error(Myfinance::RequestError) do |error|
45
+ expect(error.code).to eq(404)
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ describe "#create" do
52
+ context "when success" do
53
+ let(:params) do
54
+ {
55
+ archive: false,
56
+ bank_account_id: 141,
57
+ currency_id: 1,
58
+ deposit_account_type_id: 2,
59
+ description: "Deposit account test",
60
+ entity_id: 3798,
61
+ force_destroy: false,
62
+ imported_from_sync: false,
63
+ name: "Caixa 18",
64
+ calculated_balance: "34290.11",
65
+ logo_image_url: "logos/logo-bank-bradesco.png"
66
+ }
67
+ end
68
+
69
+ it "creates a deposit account successfully" do
70
+ result = client.deposit_accounts.create(3798, params)
71
+ expect(result).to be_a(entity_klass)
72
+ end
73
+ end
74
+
75
+ context "when error" do
76
+ it "raises Myfinance::RequestError with 422 status code" do
77
+ expect {
78
+ client.deposit_accounts.create(3798, {})
79
+ }.to raise_error(Myfinance::RequestError) do |error|
80
+ expect(error.code).to eq(422)
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ describe "#update" do
87
+ context "when success" do
88
+ it "updates a deposit account successfully" do
89
+ expect(
90
+ client.deposit_accounts.update(3798, 14820, { name: "Name" })
91
+ ).to be_a(entity_klass)
92
+ end
93
+ end
94
+
95
+ context "when invalid" do
96
+ it "raises Myfinance::RequestError with 422 status code" do
97
+ expect {
98
+ client.deposit_accounts.update(3798, 14820, { name: "" })
99
+ }.to raise_error(Myfinance::RequestError) do |error|
100
+ expect(error.code).to eq(422)
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ describe "#delete" do
107
+ context "when success" do
108
+ it "destroy a deposit account successfully" do
109
+ expect(client.deposit_accounts.destroy(3798, 14820)).to be_truthy
110
+ end
111
+ end
112
+
113
+ context "when error" do
114
+ it "raises Myfinance::RequestError with 404 status code" do
115
+ expect {
116
+ client.deposit_accounts.destroy(3798, 888888)
117
+ }.to raise_error(Myfinance::RequestError) do |error|
118
+ expect(error.code).to eq(404)
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,139 @@
1
+ require 'spec_helper'
2
+
3
+ describe Myfinance::Resources::Person, vcr: true do
4
+ let(:entity_klass) { Myfinance::Entities::Person }
5
+
6
+ describe "#find_all" do
7
+ context "with success" do
8
+ subject { client.people.find_all }
9
+
10
+ it "show all people successfully" do
11
+ expect(subject).to be_a(Myfinance::Entities::PersonCollection)
12
+ expect(subject.collection.first).to be_a(entity_klass)
13
+ expect(subject.collection.first.name).to eq("Myfreecomm")
14
+ end
15
+ end
16
+
17
+ context "when not found" do
18
+ let(:client) { Myfinance.client("") }
19
+
20
+ it "raises Myfinance::RequestError with 401 status code" do
21
+ expect {
22
+ client.people.find_all
23
+ }.to raise_error(Myfinance::RequestError) do |error|
24
+ expect(error.code).to eq(401)
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ describe "#find_by" do
31
+ context "with success" do
32
+ let(:params) do
33
+ { name_equals: "Myfreecomm", person_type_in: "JuridicalPerson" }
34
+ end
35
+
36
+ it "find people by attributte" do
37
+ result = client.people.find_by(params)
38
+ expect(result).to be_a(Myfinance::Entities::PersonCollection)
39
+ expect(result.collection.first.name).to eq("Myfreecomm")
40
+ end
41
+ end
42
+
43
+ context "with error" do
44
+ let(:client) { Myfinance.client("") }
45
+
46
+ it "raises Myfinance::RequestError with 401 status code" do
47
+ expect {
48
+ client.people.find_by({ name_equals: "Myfreecomm" })
49
+ }.to raise_error(Myfinance::RequestError) do |error|
50
+ expect(error.code).to eq(401)
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ describe "#find" do
57
+ context "with success" do
58
+ subject { client.people.find(199424) }
59
+
60
+ it "show a person successfully" do
61
+ expect(subject).to be_a(entity_klass)
62
+ expect(subject.name).to eq("Myfreecomm")
63
+ expect(subject.person_type).to eq("JuridicalPerson")
64
+ end
65
+ end
66
+
67
+ context "when not found" do
68
+ it "raises Myfinance::RequestError with 404 status code" do
69
+ expect {
70
+ client.people.find(8888888)
71
+ }.to raise_error(Myfinance::RequestError) do |error|
72
+ expect(error.code).to eq(404)
73
+ end
74
+ end
75
+ end
76
+ end
77
+
78
+ describe "#create" do
79
+ context "with success" do
80
+ let(:person) { { name: "Person 1" } }
81
+
82
+ it "creates a person successfully" do
83
+ result = client.people.create(person)
84
+ expect(result).to be_a(entity_klass)
85
+ expect(result.name).to eq("Person 1")
86
+ end
87
+ end
88
+
89
+ context "with error" do
90
+ let(:person) { { name: "" } }
91
+
92
+ it "raises Myfinance::RequestError with 422 status code" do
93
+ expect {
94
+ client.people.create(person)
95
+ }.to raise_error(Myfinance::RequestError) do |error|
96
+ expect(error.code).to eq(422)
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ describe "#update" do
103
+ context "with success" do
104
+ it "updates a person successfully" do
105
+ expect(
106
+ client.people.update(207486, { name: "Person updated" })
107
+ ).to be_a(entity_klass)
108
+ end
109
+ end
110
+
111
+ context "with error" do
112
+ it "raises Myfinance::RequestError with 422 status code" do
113
+ expect {
114
+ client.people.update(207486, { name: "" })
115
+ }.to raise_error(Myfinance::RequestError) do |error|
116
+ expect(error.code).to eq(422)
117
+ end
118
+ end
119
+ end
120
+ end
121
+
122
+ describe "#destroy" do
123
+ context "with success" do
124
+ it "destroy a person successfully" do
125
+ expect(client.people.destroy(207486)).to be_truthy
126
+ end
127
+ end
128
+
129
+ context "with error" do
130
+ it "raises Myfinance::RequestError with 404 status code" do
131
+ expect {
132
+ client.people.destroy(123456)
133
+ }.to raise_error(Myfinance::RequestError) do |error|
134
+ expect(error.code).to eq(404)
135
+ end
136
+ end
137
+ end
138
+ end
139
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myfinance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Hertz
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2016-03-03 00:00:00.000000000 Z
14
+ date: 2017-03-13 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: typhoeus
@@ -221,10 +221,12 @@ executables:
221
221
  extensions: []
222
222
  extra_rdoc_files: []
223
223
  files:
224
+ - ".codeclimate.yml"
224
225
  - ".coveralls.yml"
225
226
  - ".gitignore"
226
227
  - ".hound.yml"
227
228
  - ".rspec"
229
+ - ".rubocop.yml"
228
230
  - ".travis.yml"
229
231
  - Gemfile
230
232
  - Gemfile.lock
@@ -236,42 +238,72 @@ files:
236
238
  - lib/myfinance.rb
237
239
  - lib/myfinance/client.rb
238
240
  - lib/myfinance/configuration.rb
241
+ - lib/myfinance/entities/account.rb
242
+ - lib/myfinance/entities/account_collection.rb
239
243
  - lib/myfinance/entities/attachment.rb
240
244
  - lib/myfinance/entities/attachment_collection.rb
241
245
  - lib/myfinance/entities/base.rb
246
+ - lib/myfinance/entities/category.rb
247
+ - lib/myfinance/entities/category_collection.rb
248
+ - lib/myfinance/entities/classification_center.rb
249
+ - lib/myfinance/entities/classification_center_collection.rb
242
250
  - lib/myfinance/entities/collection.rb
251
+ - lib/myfinance/entities/deposit_account.rb
252
+ - lib/myfinance/entities/deposit_account_collection.rb
243
253
  - lib/myfinance/entities/entity.rb
244
254
  - lib/myfinance/entities/entity_collection.rb
245
255
  - lib/myfinance/entities/financial_account.rb
246
256
  - lib/myfinance/entities/payable_account.rb
257
+ - lib/myfinance/entities/person.rb
258
+ - lib/myfinance/entities/person_collection.rb
247
259
  - lib/myfinance/entities/receivable_account.rb
248
260
  - lib/myfinance/exception.rb
249
261
  - lib/myfinance/http.rb
250
262
  - lib/myfinance/request.rb
263
+ - lib/myfinance/resources/account.rb
251
264
  - lib/myfinance/resources/attachment.rb
252
265
  - lib/myfinance/resources/base.rb
266
+ - lib/myfinance/resources/category.rb
267
+ - lib/myfinance/resources/classification_center.rb
268
+ - lib/myfinance/resources/deposit_account.rb
253
269
  - lib/myfinance/resources/entity.rb
254
270
  - lib/myfinance/resources/financial_account.rb
255
271
  - lib/myfinance/resources/payable_account.rb
272
+ - lib/myfinance/resources/person.rb
256
273
  - lib/myfinance/resources/receivable_account.rb
257
274
  - lib/myfinance/response.rb
258
275
  - lib/myfinance/version.rb
259
276
  - myfinance.gemspec
260
277
  - spec/lib/myfinance/client_spec.rb
261
278
  - spec/lib/myfinance/configuration_spec.rb
279
+ - spec/lib/myfinance/entities/account_collection_spec.rb
280
+ - spec/lib/myfinance/entities/account_spec.rb
262
281
  - spec/lib/myfinance/entities/attachment_collection_spec.rb
263
282
  - spec/lib/myfinance/entities/attachment_spec.rb
264
283
  - spec/lib/myfinance/entities/base_spec.rb
284
+ - spec/lib/myfinance/entities/category_collection_spec.rb
285
+ - spec/lib/myfinance/entities/category_spec.rb
286
+ - spec/lib/myfinance/entities/classification_center_collection_spec.rb
287
+ - spec/lib/myfinance/entities/classification_center_spec.rb
265
288
  - spec/lib/myfinance/entities/collection_spec.rb
289
+ - spec/lib/myfinance/entities/deposit_account_collection_spec.rb
290
+ - spec/lib/myfinance/entities/deposit_account_spec.rb
266
291
  - spec/lib/myfinance/entities/entity_collection_spec.rb
267
292
  - spec/lib/myfinance/entities/entity_spec.rb
268
293
  - spec/lib/myfinance/entities/payable_account_spec.rb
294
+ - spec/lib/myfinance/entities/person_collection_spec.rb
295
+ - spec/lib/myfinance/entities/person_spec.rb
269
296
  - spec/lib/myfinance/entities/receivable_account_spec.rb
270
297
  - spec/lib/myfinance/http_spec.rb
271
298
  - spec/lib/myfinance/request_spec.rb
299
+ - spec/lib/myfinance/resources/account_spec.rb
272
300
  - spec/lib/myfinance/resources/attachment_spec.rb
301
+ - spec/lib/myfinance/resources/category_spec.rb
302
+ - spec/lib/myfinance/resources/classification_center_spec.rb
303
+ - spec/lib/myfinance/resources/deposit_account_spec.rb
273
304
  - spec/lib/myfinance/resources/entity_spec.rb
274
305
  - spec/lib/myfinance/resources/payable_account_spec.rb
306
+ - spec/lib/myfinance/resources/person_spec.rb
275
307
  - spec/lib/myfinance/resources/receivable_account_spec.rb
276
308
  - spec/lib/myfinance/response_spec.rb
277
309
  - spec/lib/myfinance_spec.rb
@@ -303,26 +335,41 @@ required_rubygems_version: !ruby/object:Gem::Requirement
303
335
  version: '0'
304
336
  requirements: []
305
337
  rubyforge_project:
306
- rubygems_version: 2.4.5.1
338
+ rubygems_version: 2.5.1
307
339
  signing_key:
308
340
  specification_version: 4
309
341
  summary: A Ruby client for the Myfinance REST API
310
342
  test_files:
311
343
  - spec/lib/myfinance/client_spec.rb
312
344
  - spec/lib/myfinance/configuration_spec.rb
345
+ - spec/lib/myfinance/entities/account_collection_spec.rb
346
+ - spec/lib/myfinance/entities/account_spec.rb
313
347
  - spec/lib/myfinance/entities/attachment_collection_spec.rb
314
348
  - spec/lib/myfinance/entities/attachment_spec.rb
315
349
  - spec/lib/myfinance/entities/base_spec.rb
350
+ - spec/lib/myfinance/entities/category_collection_spec.rb
351
+ - spec/lib/myfinance/entities/category_spec.rb
352
+ - spec/lib/myfinance/entities/classification_center_collection_spec.rb
353
+ - spec/lib/myfinance/entities/classification_center_spec.rb
316
354
  - spec/lib/myfinance/entities/collection_spec.rb
355
+ - spec/lib/myfinance/entities/deposit_account_collection_spec.rb
356
+ - spec/lib/myfinance/entities/deposit_account_spec.rb
317
357
  - spec/lib/myfinance/entities/entity_collection_spec.rb
318
358
  - spec/lib/myfinance/entities/entity_spec.rb
319
359
  - spec/lib/myfinance/entities/payable_account_spec.rb
360
+ - spec/lib/myfinance/entities/person_collection_spec.rb
361
+ - spec/lib/myfinance/entities/person_spec.rb
320
362
  - spec/lib/myfinance/entities/receivable_account_spec.rb
321
363
  - spec/lib/myfinance/http_spec.rb
322
364
  - spec/lib/myfinance/request_spec.rb
365
+ - spec/lib/myfinance/resources/account_spec.rb
323
366
  - spec/lib/myfinance/resources/attachment_spec.rb
367
+ - spec/lib/myfinance/resources/category_spec.rb
368
+ - spec/lib/myfinance/resources/classification_center_spec.rb
369
+ - spec/lib/myfinance/resources/deposit_account_spec.rb
324
370
  - spec/lib/myfinance/resources/entity_spec.rb
325
371
  - spec/lib/myfinance/resources/payable_account_spec.rb
372
+ - spec/lib/myfinance/resources/person_spec.rb
326
373
  - spec/lib/myfinance/resources/receivable_account_spec.rb
327
374
  - spec/lib/myfinance/response_spec.rb
328
375
  - spec/lib/myfinance_spec.rb