myfinance 0.4.0 → 0.5.0

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.
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,97 @@
1
+ module Myfinance
2
+ module Resources
3
+ #
4
+ # A wrapper to Myfinance people API
5
+ #
6
+ # [API]
7
+ # Documentation: https://app.myfinance.com.br/docs/api/people
8
+ #
9
+ class Person < Base
10
+ #
11
+ # List all people
12
+ #
13
+ # [API]
14
+ # Method: <tt>GET /people</tt>
15
+ #
16
+ # Documentation: https://app.myfinance.com.br/docs/api/people#get_index
17
+ #
18
+ def find_all
19
+ http.get("/people", body: {}) do |response|
20
+ respond_with_collection(response)
21
+ end
22
+ end
23
+
24
+ #
25
+ # Find people by attributtes
26
+ #
27
+ # [API]
28
+ # Method: <tt>GET /people</tt>
29
+ #
30
+ # Documentation: https://app.myfinance.com.br/docs/api/people#get_index
31
+ #
32
+ def find_by(params)
33
+ values = params.map { |k,v| "search[#{k}]=#{v}" }.join("&")
34
+
35
+ http.get("/people?#{values}", body: {}) do |response|
36
+ respond_with_collection(response)
37
+ end
38
+ end
39
+
40
+ #
41
+ # Show a person
42
+ #
43
+ # [API]
44
+ # Method: <tt>GET /people/:id</tt>
45
+ #
46
+ # Documentation: https://app.myfinance.com.br/docs/api/people#get_show
47
+ #
48
+ def find(id)
49
+ http.get("/people/#{id}", body: {}) do |response|
50
+ respond_with_object response, "person"
51
+ end
52
+ end
53
+
54
+ #
55
+ # Creates a person
56
+ #
57
+ # [API]
58
+ # Method: <tt>POST /people</tt>
59
+ #
60
+ # Documentation: https://app.myfinance.com.br/docs/api/people#post_create
61
+ #
62
+ def create(params)
63
+ http.post("/people", body: { person: params }) do |response|
64
+ respond_with_object response, "person"
65
+ end
66
+ end
67
+
68
+ #
69
+ # Updates a person
70
+ #
71
+ # [API]
72
+ # Method: <tt>PUT /people/:id</tt>
73
+ #
74
+ # Documentation: https://app.myfinance.com.br/docs/api/people#put_update
75
+ #
76
+ def update(id, params)
77
+ http.put("/people/#{id}", body: { person: params }) do |response|
78
+ respond_with_object response, "person"
79
+ end
80
+ end
81
+
82
+ #
83
+ # Destroy a person
84
+ #
85
+ # [API]
86
+ # Method: <tt>DELETE /people/:id</tt>
87
+ #
88
+ # Documentation: https://app.myfinance.com.br/docs/api/people#delete_destroy
89
+ #
90
+ def destroy(id)
91
+ http.delete("/people/#{id}", body: {}) do |response|
92
+ respond_with_object response, "person"
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -1,3 +1,3 @@
1
1
  module Myfinance
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -60,4 +60,44 @@ describe Myfinance::Client do
60
60
  subject.attachments
61
61
  end
62
62
  end
63
+
64
+ describe "#classification_centers" do
65
+ it "instantiates a new Myfinance::Resources::ClassificationCenter" do
66
+ expect(
67
+ Myfinance::Resources::ClassificationCenter
68
+ ).to receive(:new).with(subject.http)
69
+ subject.classification_centers
70
+ end
71
+ end
72
+
73
+ describe "#categories" do
74
+ it "instantiates a new Myfinance::Resources::Category" do
75
+ expect(Myfinance::Resources::Category).to receive(:new).with(subject.http)
76
+ subject.categories
77
+ end
78
+ end
79
+
80
+ describe "#accounts" do
81
+ it "instantiates a new Myfinance::Resources::Account" do
82
+ expect(Myfinance::Resources::Account).to receive(:new).with(subject.http)
83
+ subject.accounts
84
+ end
85
+ end
86
+
87
+ describe "#deposit_accounts" do
88
+ it "instantiates a new Myfinance::Resources::DepositAccount" do
89
+ expect(
90
+ Myfinance::Resources::DepositAccount
91
+ ).to receive(:new).with(subject.http)
92
+
93
+ subject.deposit_accounts
94
+ end
95
+ end
96
+
97
+ describe "#people" do
98
+ it "instantiates a new Myfinance::Resources::Person" do
99
+ expect(Myfinance::Resources::Person).to receive(:new).with(subject.http)
100
+ subject.people
101
+ end
102
+ end
63
103
  end
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+
3
+ describe Myfinance::Entities::AccountCollection do
4
+ let(:response) { double(headers: {}, parsed_body: [{}]) }
5
+
6
+ subject { described_class.new(response) }
7
+
8
+ describe "#build" do
9
+ it "returns orders collection" do
10
+ expect(subject.build).to be_a(Myfinance::Entities::AccountCollection)
11
+ end
12
+
13
+ it "returns orders" do
14
+ subject.build
15
+ expect(subject.collection.count).to eq(1)
16
+ expect(subject.collection.first.class).to eq(Myfinance::Entities::Account)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ describe Myfinance::Entities::Account do
4
+ subject { described_class.new({}) }
5
+
6
+ it_behaves_like "entity_attributes", [
7
+ :beta, :canceled_at, :cancellation_reason, :charging_uuid,
8
+ :created_at, :default_currency_id, :ecommerce_response,
9
+ :expires_on, :id, :invite, :is_trial, :name, :owner_id,
10
+ :payment_method, :plan_slug, :referral_code, :referrer_id,
11
+ :updated_at, :uuid, :waiting_payment
12
+ ]
13
+ end
@@ -0,0 +1,47 @@
1
+ require "spec_helper"
2
+
3
+ describe Myfinance::Entities::CategoryCollection do
4
+ let(:entity_klass) { Myfinance::Entities::Category }
5
+
6
+ let(:response) do
7
+ double(
8
+ headers: {},
9
+ parsed_body: [
10
+ {
11
+ "category" => {
12
+ "account_id" => 3613,
13
+ "cost" => true,
14
+ "created_at" => "2015-07-29T11:04:50-03:00",
15
+ "excel_import_id" => nil,
16
+ "force_destroy" => false,
17
+ "full_name" => "Alimentação",
18
+ "guid" => nil,
19
+ "id" => 532314,
20
+ "imported_from_sync" => false,
21
+ "interested_users_ids" => [],
22
+ "modified_by_sync" => false,
23
+ "name" => "Alimentação",
24
+ "parent_id" => nil,
25
+ "revenue" => true,
26
+ "updated_at" => "2015-07-29T11:04:50-03:00",
27
+ "use_count" => 0
28
+ }
29
+ }
30
+ ]
31
+ )
32
+ end
33
+
34
+ subject { Myfinance::Entities::CategoryCollection.new(response) }
35
+
36
+ describe "#build" do
37
+ it "returns order collection" do
38
+ expect(subject.build.class).to eq(Myfinance::Entities::CategoryCollection)
39
+ end
40
+
41
+ it "returns order" do
42
+ subject.build
43
+ expect(subject.collection.count).to eq(1)
44
+ expect(subject.collection.first.class).to eq(entity_klass)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Myfinance::Entities::Category do
4
+ subject { described_class.new({}) }
5
+
6
+ it_behaves_like 'entity_attributes', [
7
+ :account_id, :cost, :created_at, :excel_import_id,
8
+ :force_destroy, :full_name, :guid, :id, :imported_from_sync,
9
+ :interested_users_ids, :modified_by_sync, :name, :parent_id,
10
+ :revenue, :updated_at, :use_count
11
+ ]
12
+ end
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ describe Myfinance::Entities::ClassificationCenterCollection 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::ClassificationCenter)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,8 @@
1
+ require "spec_helper"
2
+
3
+ describe Myfinance::Entities::ClassificationCenter do
4
+ it_behaves_like "entity_attributes", [
5
+ :cost_center, :created_at, :entity_id, :excel_import_id,
6
+ :id, :name, :revenue_center, :updated_at, :use_count
7
+ ]
8
+ end
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ describe Myfinance::Entities::DepositAccountCollection do
4
+ let(:entity_klass) { described_class }
5
+
6
+ let(:params) { double(headers: {}, parsed_body: [{}]) }
7
+
8
+ subject { entity_klass.new(params) }
9
+
10
+ describe "#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(subject.collection.first).to be_a(
19
+ Myfinance::Entities::DepositAccount
20
+ )
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ require "spec_helper"
2
+
3
+ describe Myfinance::Entities::DepositAccount do
4
+ it_behaves_like "entity_attributes", [
5
+ :archive, :bank_account_id, :created_at, :currency_id,
6
+ :deposit_account_type_id, :description, :entity_id,
7
+ :force_destroy, :id, :imported_from_sync, :initial_balance,
8
+ :last_transaction_date, :name, :sync_response, :updated_at,
9
+ :calculated_balance, :logo_image_url, :links
10
+ ]
11
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
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
26
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Myfinance::Entities::Person do
4
+ subject { described_class.new({}) }
5
+
6
+ it_behaves_like "entity_attributes", [
7
+ :account_id, :address, :address_number, :city, :complement,
8
+ :country, :created_at, :customer, :email, :excel_import_id,
9
+ :febraban_favored_code, :febraban_name,
10
+ :federation_subscription_number,
11
+ :federation_subscription_number_only_numbers,
12
+ :federation_subscription_type_id, :force_destroy, :guid,
13
+ :id, :imported_from_sync, :interested_users_ids,
14
+ :modified_by_sync, :name, :neighborhood, :note,
15
+ :person_type, :phone, :site, :state, :supplier, :updated_at,
16
+ :use_count, :zip_code
17
+ ]
18
+ end
@@ -0,0 +1,28 @@
1
+ require "spec_helper"
2
+
3
+ describe Myfinance::Resources::Account, vcr: true do
4
+ let(:entity_klass) { described_class }
5
+
6
+ describe "#find_all" do
7
+ context "with success" do
8
+ subject { client.accounts.find_all }
9
+
10
+ it "show all accounts successfully" do
11
+ expect(subject).to be_a(Myfinance::Entities::AccountCollection)
12
+ expect(subject.collection.first).to be_a(Myfinance::Entities::Account)
13
+ end
14
+ end
15
+
16
+ context "with error" do
17
+ let(:client) { Myfinance.client("") }
18
+
19
+ it "raises Myfinance::RequestError with 401 status code" do
20
+ expect {
21
+ client.accounts.find_all
22
+ }.to raise_error(Myfinance::RequestError) do |error|
23
+ expect(error.code).to eq(401)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,118 @@
1
+ require 'spec_helper'
2
+
3
+ describe Myfinance::Resources::Category, vcr: true do
4
+ let(:entity_klass) { Myfinance::Entities::Category }
5
+
6
+ describe "#find_all" do
7
+ context "with success" do
8
+ subject { client.categories.find_all }
9
+
10
+ it "show all categories successfully" do
11
+ expect(subject.class).to eq(Myfinance::Entities::CategoryCollection)
12
+ expect(subject.collection.first.class).to eq(entity_klass)
13
+ expect(subject.collection.first.full_name).to eq("Alimentação")
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.categories.find_all
23
+ }.to raise_error(Myfinance::RequestError) do |error|
24
+ expect(error.code).to eql(401)
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ describe "#find" do
31
+ context "with success" do
32
+ subject { client.categories.find(532314) }
33
+
34
+ it "returns a category successfully" do
35
+ expect(subject.class).to eql(entity_klass)
36
+ expect(subject.id).to eql(532314)
37
+ end
38
+ end
39
+
40
+ context "with error" do
41
+ it "raises Myfinance::RequestError with 404 status code" do
42
+ expect {
43
+ client.categories.find(88888888)
44
+ }.to raise_error(Myfinance::RequestError) do |error|
45
+ expect(error.code).to eql(404)
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ describe "#create" do
52
+ let(:params) { { name: "Category 1" } }
53
+
54
+ context "with success" do
55
+ it "creates a category successfully" do
56
+ result = client.categories.create(params)
57
+ expect(result).to be_a(entity_klass)
58
+ expect(result.name).to eql("Category 1")
59
+ end
60
+ end
61
+
62
+ context "with error" do
63
+ it "raises Myfinance::RequestError with 422 status code" do
64
+ expect {
65
+ client.categories.create({})
66
+ }.to raise_error(Myfinance::RequestError) do |error|
67
+ expect(error.code).to eql(422)
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ describe "#update" do
74
+ context "with success" do
75
+ it "updates a category successfully" do
76
+ expect(
77
+ client.categories.update(548083, { name: "Category updated" })
78
+ ).to be_a(entity_klass)
79
+ end
80
+ end
81
+
82
+ context "with error" do
83
+ it "raises Myfinance::RequestError with 404 status code" do
84
+ expect {
85
+ client.categories.update(88888888, {})
86
+ }.to raise_error(Myfinance::RequestError) do |error|
87
+ expect(error.code).to eql(404)
88
+ end
89
+ end
90
+
91
+ it "raises Myfinance::RequestError with 422 status core" do
92
+ expect {
93
+ result = client.categories.update(548083, { name: "" })
94
+ }.to raise_error(Myfinance::RequestError) do |error|
95
+ expect(error.code).to eql(422)
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ describe "#destroy" do
102
+ context "with success" do
103
+ it "destroy a category successfully" do
104
+ expect(client.categories.destroy(532314)).to be_truthy
105
+ end
106
+ end
107
+
108
+ context "with error" do
109
+ it "raises Myfinance::RequestError with 404 status code" do
110
+ expect {
111
+ client.categories.destroy(88888888)
112
+ }.to raise_error(Myfinance::RequestError) do |error|
113
+ expect(error.code).to eql(404)
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end