myfinance 1.4.1 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -1
  3. data/Gemfile.lock +2 -2
  4. data/README.md +131 -0
  5. data/lib/myfinance/client.rb +8 -0
  6. data/lib/myfinance/entities/credit_card.rb +1 -0
  7. data/lib/myfinance/entities/credit_card_transaction.rb +1 -0
  8. data/lib/myfinance/entities/custom_classifier.rb +11 -0
  9. data/lib/myfinance/entities/custom_classifier_collection.rb +16 -0
  10. data/lib/myfinance/entities/custom_classifier_value.rb +11 -0
  11. data/lib/myfinance/entities/custom_classifier_value_collection.rb +16 -0
  12. data/lib/myfinance/entities/financial_account.rb +1 -0
  13. data/lib/myfinance/entities/financial_transaction.rb +1 -0
  14. data/lib/myfinance/entities/sale.rb +0 -1
  15. data/lib/myfinance/resources/custom_classifier.rb +83 -0
  16. data/lib/myfinance/resources/custom_classifier_value.rb +92 -0
  17. data/lib/myfinance/version.rb +1 -1
  18. data/spec/lib/myfinance/client_spec.rb +16 -113
  19. data/spec/lib/myfinance/entities/account_collection_spec.rb +1 -15
  20. data/spec/lib/myfinance/entities/attachment_collection_spec.rb +1 -16
  21. data/spec/lib/myfinance/entities/category_collection_spec.rb +1 -43
  22. data/spec/lib/myfinance/entities/classification_center_collection_spec.rb +1 -19
  23. data/spec/lib/myfinance/entities/credit_card_collection_spec.rb +1 -19
  24. data/spec/lib/myfinance/entities/credit_card_spec.rb +3 -3
  25. data/spec/lib/myfinance/entities/credit_card_transaction_collection_spec.rb +1 -17
  26. data/spec/lib/myfinance/entities/credit_card_transaction_spec.rb +5 -4
  27. data/spec/lib/myfinance/entities/custom_classifier_collection_spec.rb +5 -0
  28. data/spec/lib/myfinance/entities/custom_classifier_spec.rb +7 -0
  29. data/spec/lib/myfinance/entities/custom_classifier_value_collection_spec.rb +5 -0
  30. data/spec/lib/myfinance/entities/custom_classifier_value_spec.rb +7 -0
  31. data/spec/lib/myfinance/entities/deposit_account_collection_spec.rb +1 -19
  32. data/spec/lib/myfinance/entities/financial_transaction_collection_spec.rb +1 -19
  33. data/spec/lib/myfinance/entities/financial_transaction_spec.rb +8 -8
  34. data/spec/lib/myfinance/entities/payable_account_spec.rb +7 -7
  35. data/spec/lib/myfinance/entities/person_collection_spec.rb +1 -22
  36. data/spec/lib/myfinance/entities/receivable_account_spec.rb +7 -7
  37. data/spec/lib/myfinance/entities/reconcile_collection_spec.rb +1 -3
  38. data/spec/lib/myfinance/entities/tax_collection_spec.rb +1 -19
  39. data/spec/lib/myfinance/entities/webhook_collection_spec.rb +1 -44
  40. data/spec/lib/myfinance/resources/custom_classifier_spec.rb +90 -0
  41. data/spec/lib/myfinance/resources/custom_classifier_value_spec.rb +111 -0
  42. data/spec/lib/myfinance_spec.rb +14 -5
  43. metadata +20 -2
@@ -3,12 +3,12 @@ require 'spec_helper'
3
3
  describe Myfinance::Entities::PayableAccount do
4
4
  subject { described_class.new({}) }
5
5
 
6
- it_behaves_like "entity_attributes", [
7
- :id, :entity_id, :status, :status_name, :due_date, :occurred_at, :ticket_amount, :interest_amount, :amount,
8
- :discount_amount, :total_amount, :description, :document, :document_emission_date, :observation, :remind,
9
- :reminded_at, :income_tax_relevant, :category_id, :classification_center_id, :expected_deposit_account_id,
10
- :recurrence_id, :person_id, :recurrent, :parcelled, :recurrence_period, :number_of_parcels, :current_parcel,
11
- :competency_month, :financial_account_taxes_attributes, :tax_charges, :reconciliations,
12
- :links, :created_at, :updated_at
6
+ it_behaves_like "entity_attributes", %i[
7
+ id entity_id status status_name due_date occurred_at ticket_amount interest_amount amount
8
+ discount_amount total_amount description document document_emission_date observation remind
9
+ reminded_at income_tax_relevant category_id classification_center_id expected_deposit_account_id
10
+ recurrence_id person_id recurrent parcelled recurrence_period number_of_parcels current_parcel
11
+ competency_month financial_account_taxes_attributes tax_charges reconciliations
12
+ links created_at updated_at custom_classifications
13
13
  ]
14
14
  end
@@ -1,26 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Myfinance::Entities::PersonCollection do
4
- let(:response) do
5
- double(
6
- headers: {},
7
- parsed_body: [
8
- {}
9
- ]
10
- )
11
- end
12
-
13
- subject { described_class.new(response) }
14
-
15
- describe "#build" do
16
- it "returns order collection" do
17
- expect(subject.build.class).to eql(Myfinance::Entities::PersonCollection)
18
- end
19
-
20
- it "returns order" do
21
- subject.build
22
- expect(subject.collection.count).to eq(1)
23
- expect(subject.collection.first.class).to eq(Myfinance::Entities::Person)
24
- end
25
- end
4
+ it_behaves_like :entity_collection, Myfinance::Entities::Person
26
5
  end
@@ -3,12 +3,12 @@ require 'spec_helper'
3
3
  describe Myfinance::Entities::ReceivableAccount do
4
4
  subject { described_class.new({}) }
5
5
 
6
- it_behaves_like "entity_attributes", [
7
- :id, :entity_id, :status, :status_name, :due_date, :occurred_at, :ticket_amount, :interest_amount, :amount,
8
- :discount_amount, :total_amount, :description, :document, :document_emission_date, :observation, :remind,
9
- :reminded_at, :income_tax_relevant, :category_id, :classification_center_id, :expected_deposit_account_id,
10
- :recurrence_id, :person_id, :recurrent, :parcelled, :recurrence_period, :number_of_parcels, :current_parcel,
11
- :competency_month, :financial_account_taxes_attributes, :tax_charges, :reconciliations,
12
- :links, :created_at, :updated_at
6
+ it_behaves_like "entity_attributes", %i[
7
+ id entity_id status status_name due_date occurred_at ticket_amount interest_amount amount
8
+ discount_amount total_amount description document document_emission_date observation remind
9
+ reminded_at income_tax_relevant category_id classification_center_id expected_deposit_account_id
10
+ recurrence_id person_id recurrent parcelled recurrence_period number_of_parcels current_parcel
11
+ competency_month financial_account_taxes_attributes tax_charges reconciliations
12
+ links created_at updated_at custom_classifications
13
13
  ]
14
14
  end
@@ -1,15 +1,13 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Myfinance::Entities::ReconcileCollection do
4
- let(:entity_klass) { described_class }
5
-
6
4
  let(:params) { double(headers: {}, parsed_body: [{}]) }
7
5
 
8
6
  subject { described_class.new(params) }
9
7
 
10
8
  context "#build" do
11
9
  it "returns order collection" do
12
- expect(subject.build).to be_a(entity_klass)
10
+ expect(subject.build).to be_a(described_class)
13
11
  end
14
12
 
15
13
  it "returns order" do
@@ -1,23 +1,5 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Myfinance::Entities::TaxCollection do
4
- let(:entity_klass) { described_class }
5
-
6
- let(:params) { double(headers: {}, parsed_body: [{}]) }
7
-
8
- subject { described_class.new(params) }
9
-
10
- context "#build" do
11
- it "returns order collection" do
12
- expect(subject.build).to be_a(entity_klass)
13
- end
14
-
15
- it "returns order" do
16
- subject.build
17
- expect(subject.collection.count).to eq(1)
18
- expect(
19
- subject.collection.first
20
- ).to be_a(Myfinance::Entities::Tax)
21
- end
22
- end
4
+ it_behaves_like :entity_collection, Myfinance::Entities::Tax
23
5
  end
@@ -1,48 +1,5 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Myfinance::Entities::WebhookCollection do
4
- let(:response) do
5
- double(
6
- headers: {},
7
- parsed_body: [
8
- {
9
- "webhook" => {
10
- "account_id" => 3613,
11
- "created_at" => "2015-09-21T15:41:05-03:00",
12
- "description" => "Webhook test",
13
- "entity_id" => 3798,
14
- "healthy_check_code" => "200",
15
- "id" => 76,
16
- "updated_at" => "2015-09-21T16:08:48-03:00",
17
- "url" => "https://sandbox.myfinance.com.br/docs/api/webhooks"
18
- }
19
- },{
20
- "webhook" => {
21
- "account_id" => 3613,
22
- "created_at" => "2015-09-21T16:15:22-03:00",
23
- "description" => "Webhook 1",
24
- "entity_id" => 3798,
25
- "healthy_check_code" => "200",
26
- "id" => 77,
27
- "updated_at" => "2015-09-21T16:15:35-03:00",
28
- "url" => "https://sandbox.myfinance.com.br/docs/api/webhooks"
29
- }
30
- }
31
- ]
32
- )
33
- end
34
-
35
- subject { Myfinance::Entities::WebhookCollection.new(response) }
36
-
37
- describe "#build" do
38
- it "returns order collection" do
39
- expect(subject.build).to be_a(Myfinance::Entities::WebhookCollection)
40
- end
41
-
42
- it "returns order" do
43
- subject.build
44
- expect(subject.collection.count).to eq(2)
45
- expect(subject.collection.first).to be_a(Myfinance::Entities::Webhook)
46
- end
47
- end
4
+ it_behaves_like :entity_collection, Myfinance::Entities::Webhook
48
5
  end
@@ -0,0 +1,90 @@
1
+ require "spec_helper"
2
+
3
+ describe Myfinance::Resources::CustomClassifier, vcr: true do
4
+ let(:entity_klass) { Myfinance::Entities::CustomClassifier }
5
+
6
+ describe "#find_all" do
7
+ context "with success" do
8
+ subject { client.custom_classifiers.find_all }
9
+
10
+ it "show all custom_classifiers successfully" do
11
+ expect(subject.class).to eq(Myfinance::Entities::CustomClassifierCollection)
12
+ expect(subject.collection.first.class).to eq(entity_klass)
13
+ expect(subject.collection.first.name).to eq("Produto")
14
+ end
15
+ end
16
+ end
17
+
18
+ describe "#find" do
19
+ context "with success" do
20
+ subject { client.custom_classifiers.find(20) }
21
+
22
+ it "returns a custom_classifier successfully" do
23
+ expect(subject.class).to eql(entity_klass)
24
+ expect(subject.id).to eq(20)
25
+ end
26
+ end
27
+
28
+ context "with error" do
29
+ it "raises Myfinance::RequestError with 404 status code" do
30
+ expect { client.custom_classifiers.find(88_888_888) }.to raise_error(Myfinance::RequestError) do |error|
31
+ expect(error.code).to eql(404)
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "#create" do
38
+ let(:params) { { name: "Classificador 42" } }
39
+
40
+ context "with success" do
41
+ it "creates a custom_classifier successfully" do
42
+ result = client.custom_classifiers.create(params)
43
+ expect(result).to be_a(entity_klass)
44
+ expect(result.name).to eql("Classificador 42")
45
+ end
46
+ end
47
+
48
+ context "with error" do
49
+ it "raises Myfinance::RequestError with 422 status code" do
50
+ expect { client.custom_classifiers.create(name: {}) }.to raise_error(Myfinance::RequestError) do |error|
51
+ expect(error.code).to eql(422)
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ describe "#update" do
58
+ context "with success" do
59
+ it "updates a custom_classifier successfully" do
60
+ expect(client.custom_classifiers.update(25, name: "Classificador alterado")).to be_a(entity_klass)
61
+ end
62
+ end
63
+
64
+ context "with error" do
65
+ it "raises Myfinance::RequestError with 404 status code" do
66
+ expect { client.custom_classifiers.update(88_888_888, {}) }.to raise_error(Myfinance::RequestError) do |error|
67
+ expect(error.code).to eql(404)
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ describe "#destroy" do
74
+ let(:params) { { name: "Nome qualquer" } }
75
+ context "with success" do
76
+ it "destroy a custom_classifier successfully" do
77
+ cc_id = client.custom_classifiers.create(params).id
78
+ expect(client.custom_classifiers.destroy(cc_id)).to be_truthy
79
+ end
80
+ end
81
+
82
+ context "with error" do
83
+ it "raises Myfinance::RequestError with 404 status code" do
84
+ expect { client.custom_classifiers.destroy(88_888_888) }.to raise_error(Myfinance::RequestError) do |error|
85
+ expect(error.code).to eql(404)
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,111 @@
1
+ require "spec_helper"
2
+
3
+ describe Myfinance::Resources::CustomClassifierValue, vcr: true do
4
+ let(:entity_klass) { Myfinance::Entities::CustomClassifierValue }
5
+ let(:custom_classifier_id) { 20 }
6
+ let(:custom_classifier_value_id) { 36 }
7
+
8
+ describe "#find_all" do
9
+ context "with success" do
10
+ subject { client.custom_classifier_values.find_all(custom_classifier_id) }
11
+
12
+ it "show all custom_classifier_values successfully" do
13
+ expect(subject.class).to eq(Myfinance::Entities::CustomClassifierValueCollection)
14
+ expect(subject.collection.first.class).to eq(entity_klass)
15
+ expect(subject.collection.first.value).to eq("Classificador 42")
16
+ end
17
+ end
18
+ end
19
+
20
+ describe "#find" do
21
+ context "with success" do
22
+ subject { client.custom_classifier_values.find(custom_classifier_id, custom_classifier_value_id) }
23
+
24
+ it "returns a custom_classifier_value successfully" do
25
+ expect(subject.class).to eql(entity_klass)
26
+ expect(subject.id).to eq(custom_classifier_value_id)
27
+ end
28
+ end
29
+
30
+ context "with error" do
31
+ it "raises Myfinance::RequestError with 404 status code" do
32
+ expectation = expect do
33
+ client.custom_classifier_values.find(custom_classifier_id, 88_888_888)
34
+ end
35
+
36
+ expectation.to raise_error(Myfinance::RequestError) do |error|
37
+ expect(error.code).to eql(404)
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ describe "#create" do
44
+ let(:params) { { value: "Valor 42" } }
45
+
46
+ context "with success" do
47
+ it "creates a custom_classifier_value successfully" do
48
+ result = client.custom_classifier_values.create(custom_classifier_id, params)
49
+ expect(result).to be_a(entity_klass)
50
+ expect(result.value).to eql("Valor 42")
51
+ end
52
+ end
53
+
54
+ context "with error" do
55
+ it "raises Myfinance::RequestError with 422 status code" do
56
+ expectation = expect do
57
+ client.custom_classifier_values.create(custom_classifier_id, value: {})
58
+ end
59
+
60
+ expectation.to raise_error(Myfinance::RequestError) do |error|
61
+ expect(error.code).to eql(422)
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ describe "#update" do
68
+ context "with success" do
69
+ it "updates a custom_classifier_value successfully" do
70
+ updated = client.custom_classifier_values.update(
71
+ custom_classifier_id, custom_classifier_value_id, value: "Valor alterado"
72
+ )
73
+ expect(updated).to be_a(entity_klass)
74
+ end
75
+ end
76
+
77
+ context "with error" do
78
+ it "raises Myfinance::RequestError with 404 status code" do
79
+ expectation = expect do
80
+ client.custom_classifier_values.update(custom_classifier_id, 88_888_888, {})
81
+ end
82
+
83
+ expectation.to raise_error(Myfinance::RequestError) do |error|
84
+ expect(error.code).to eql(404)
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ describe "#destroy" do
91
+ let(:params) { { value: "Nome qualquer" } }
92
+ context "with success" do
93
+ it "destroy a custom_classifier_value successfully" do
94
+ cc_id = client.custom_classifier_values.create(custom_classifier_id, params).id
95
+ expect(client.custom_classifier_values.destroy(custom_classifier_id, cc_id)).to be_truthy
96
+ end
97
+ end
98
+
99
+ context "with error" do
100
+ it "raises Myfinance::RequestError with 404 status code" do
101
+ expectation = expect do
102
+ client.custom_classifier_values.destroy(custom_classifier_id, 88_888_888)
103
+ end
104
+
105
+ expectation.to raise_error(Myfinance::RequestError) do |error|
106
+ expect(error.code).to eql(404)
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
@@ -1,12 +1,12 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Myfinance do
4
- it 'has a version number' do
4
+ it "has a version number" do
5
5
  expect(Myfinance::VERSION).to_not be_nil
6
6
  end
7
7
 
8
- describe 'configuration' do
9
- it 'should be done via block initialization' do
8
+ describe "configuration" do
9
+ it "should be done via block initialization" do
10
10
  Myfinance.configure do |c|
11
11
  c.user_agent = "My App v1.0"
12
12
  c.url = "https://sandbox.myfinance.com.br"
@@ -16,7 +16,7 @@ describe Myfinance do
16
16
  expect(Myfinance.configuration.url).to eq("https://sandbox.myfinance.com.br")
17
17
  end
18
18
 
19
- it 'uses a singleton object for the configuration values' do
19
+ it "uses a singleton object for the configuration values" do
20
20
  config1 = Myfinance.configuration
21
21
  config2 = Myfinance.configuration
22
22
  expect(config1).to eq(config2)
@@ -28,5 +28,14 @@ describe Myfinance do
28
28
  expect(Myfinance::Client).to receive(:new).with("abc", 12).and_call_original
29
29
  Myfinance.client("abc", 12)
30
30
  end
31
+
32
+ context "with invalid authentication token", vcr: true do
33
+ it "raises error when using some endpoint" do
34
+ client = Myfinance.client("42424242424242")
35
+ expect { client.custom_classifiers.find_all }.to raise_error(Myfinance::RequestError) do |error|
36
+ expect(error.code).to eq(401)
37
+ end
38
+ end
39
+ end
31
40
  end
32
41
  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: 1.4.1
4
+ version: 1.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: 2017-07-11 00:00:00.000000000 Z
14
+ date: 2017-07-20 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: typhoeus
@@ -271,6 +271,10 @@ files:
271
271
  - lib/myfinance/entities/credit_card_collection.rb
272
272
  - lib/myfinance/entities/credit_card_transaction.rb
273
273
  - lib/myfinance/entities/credit_card_transaction_collection.rb
274
+ - lib/myfinance/entities/custom_classifier.rb
275
+ - lib/myfinance/entities/custom_classifier_collection.rb
276
+ - lib/myfinance/entities/custom_classifier_value.rb
277
+ - lib/myfinance/entities/custom_classifier_value_collection.rb
274
278
  - lib/myfinance/entities/deposit_account.rb
275
279
  - lib/myfinance/entities/deposit_account_collection.rb
276
280
  - lib/myfinance/entities/entity.rb
@@ -306,6 +310,8 @@ files:
306
310
  - lib/myfinance/resources/classification_center.rb
307
311
  - lib/myfinance/resources/credit_card.rb
308
312
  - lib/myfinance/resources/credit_card_transaction.rb
313
+ - lib/myfinance/resources/custom_classifier.rb
314
+ - lib/myfinance/resources/custom_classifier_value.rb
309
315
  - lib/myfinance/resources/deposit_account.rb
310
316
  - lib/myfinance/resources/entity.rb
311
317
  - lib/myfinance/resources/financial_account.rb
@@ -338,6 +344,10 @@ files:
338
344
  - spec/lib/myfinance/entities/credit_card_spec.rb
339
345
  - spec/lib/myfinance/entities/credit_card_transaction_collection_spec.rb
340
346
  - spec/lib/myfinance/entities/credit_card_transaction_spec.rb
347
+ - spec/lib/myfinance/entities/custom_classifier_collection_spec.rb
348
+ - spec/lib/myfinance/entities/custom_classifier_spec.rb
349
+ - spec/lib/myfinance/entities/custom_classifier_value_collection_spec.rb
350
+ - spec/lib/myfinance/entities/custom_classifier_value_spec.rb
341
351
  - spec/lib/myfinance/entities/deposit_account_collection_spec.rb
342
352
  - spec/lib/myfinance/entities/deposit_account_spec.rb
343
353
  - spec/lib/myfinance/entities/entity_collection_spec.rb
@@ -368,6 +378,8 @@ files:
368
378
  - spec/lib/myfinance/resources/classification_center_spec.rb
369
379
  - spec/lib/myfinance/resources/credit_card_spec.rb
370
380
  - spec/lib/myfinance/resources/credit_card_transaction_spec.rb
381
+ - spec/lib/myfinance/resources/custom_classifier_spec.rb
382
+ - spec/lib/myfinance/resources/custom_classifier_value_spec.rb
371
383
  - spec/lib/myfinance/resources/deposit_account_spec.rb
372
384
  - spec/lib/myfinance/resources/entity_spec.rb
373
385
  - spec/lib/myfinance/resources/financial_transaction_spec.rb
@@ -434,6 +446,10 @@ test_files:
434
446
  - spec/lib/myfinance/entities/credit_card_spec.rb
435
447
  - spec/lib/myfinance/entities/credit_card_transaction_collection_spec.rb
436
448
  - spec/lib/myfinance/entities/credit_card_transaction_spec.rb
449
+ - spec/lib/myfinance/entities/custom_classifier_collection_spec.rb
450
+ - spec/lib/myfinance/entities/custom_classifier_spec.rb
451
+ - spec/lib/myfinance/entities/custom_classifier_value_collection_spec.rb
452
+ - spec/lib/myfinance/entities/custom_classifier_value_spec.rb
437
453
  - spec/lib/myfinance/entities/deposit_account_collection_spec.rb
438
454
  - spec/lib/myfinance/entities/deposit_account_spec.rb
439
455
  - spec/lib/myfinance/entities/entity_collection_spec.rb
@@ -464,6 +480,8 @@ test_files:
464
480
  - spec/lib/myfinance/resources/classification_center_spec.rb
465
481
  - spec/lib/myfinance/resources/credit_card_spec.rb
466
482
  - spec/lib/myfinance/resources/credit_card_transaction_spec.rb
483
+ - spec/lib/myfinance/resources/custom_classifier_spec.rb
484
+ - spec/lib/myfinance/resources/custom_classifier_value_spec.rb
467
485
  - spec/lib/myfinance/resources/deposit_account_spec.rb
468
486
  - spec/lib/myfinance/resources/entity_spec.rb
469
487
  - spec/lib/myfinance/resources/financial_transaction_spec.rb