myfinance 0.6.0 → 0.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ecda9fc35e75861ba16e84234727cfa22b373195
4
- data.tar.gz: 9b84355ad4ecfba37229a672881990f14392629f
3
+ metadata.gz: 0cc4a1064aa43f5ea804054f28615cca76b55736
4
+ data.tar.gz: 6c1865d21fb91219abcfd059ad6e7f90dccdc3d4
5
5
  SHA512:
6
- metadata.gz: 8e0a5874346c8d48b939caa538e287aa421774b58eac2d9f175abcd2330f5f9e2d2bb0f3197fc031f8f391376c37a93dfddf0aa6f078541d651164a384906b8f
7
- data.tar.gz: 989b52db753b0bf88c121001ea05090a8185b710a3de13213ae63aa6c8a1ea4fc22035e6019599aa7ec6c9761627faa0cc0bd786532158ad056937233655d028
6
+ metadata.gz: 2697a1a00cb82c86a0c0f0a1737e4179eb05b10ffd42740a2e70aa0c3d23c2e734593d881e76baf6506d96a3e4429b1e723a1f1b9cf48b972191e871b35a5c0c
7
+ data.tar.gz: c4ed5d1bf31c386dca979788f458aa4e4e86ec4f46dffb959c601767ffc94bb914347125f37c11555c8aa7cb89445559f433f12fb1fb69fdf8705894a49576c7
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  *.gem
2
2
  *.rbc
3
+ *.swp
3
4
  .bundle
4
5
  .config
5
6
  .DS_Store
data/.rubocop.yml CHANGED
@@ -716,7 +716,7 @@ Style/LineEndConcatenation:
716
716
  line end.
717
717
  Enabled: false
718
718
 
719
- Style/MethodCallParentheses:
719
+ Style/MethodCallWithoutArgsParentheses:
720
720
  Description: 'Do not use parentheses for method calls with no arguments.'
721
721
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-args-no-parens'
722
722
  Enabled: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- myfinance (0.6.0)
4
+ myfinance (0.7.0)
5
5
  mime-types (~> 2.99)
6
6
  multi_json (~> 1.11)
7
7
  typhoeus (~> 0.8)
@@ -10,13 +10,14 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- addressable (2.4.0)
14
- awesome_print (1.6.1)
13
+ addressable (2.5.0)
14
+ public_suffix (~> 2.0, >= 2.0.2)
15
+ awesome_print (1.7.0)
15
16
  axiom-types (0.1.1)
16
17
  descendants_tracker (~> 0.0.4)
17
18
  ice_nine (~> 0.11.0)
18
19
  thread_safe (~> 0.3, >= 0.3.1)
19
- codeclimate-test-reporter (0.5.0)
20
+ codeclimate-test-reporter (0.6.0)
20
21
  simplecov (>= 0.7.1, < 1.0.0)
21
22
  coderay (1.1.1)
22
23
  coercible (1.0.0)
@@ -25,41 +26,42 @@ GEM
25
26
  safe_yaml (~> 1.0.0)
26
27
  descendants_tracker (0.0.4)
27
28
  thread_safe (~> 0.3, >= 0.3.1)
28
- diff-lcs (1.2.5)
29
+ diff-lcs (1.3)
29
30
  docile (1.1.5)
30
31
  equalizer (0.0.11)
31
32
  ethon (0.10.1)
32
33
  ffi (>= 1.3.0)
33
34
  ffi (1.9.18)
34
35
  ice_nine (0.11.2)
35
- json (1.8.3)
36
+ json (2.0.3)
36
37
  method_source (0.8.2)
37
38
  mime-types (2.99.3)
38
39
  multi_json (1.12.1)
39
- pry (0.10.3)
40
+ pry (0.10.4)
40
41
  coderay (~> 1.1.0)
41
42
  method_source (~> 0.8.1)
42
43
  slop (~> 3.4)
43
44
  pry-nav (0.2.4)
44
45
  pry (>= 0.9.10, < 0.11.0)
46
+ public_suffix (2.0.5)
45
47
  rake (10.5.0)
46
- rspec (3.4.0)
47
- rspec-core (~> 3.4.0)
48
- rspec-expectations (~> 3.4.0)
49
- rspec-mocks (~> 3.4.0)
50
- rspec-core (3.4.3)
51
- rspec-support (~> 3.4.0)
52
- rspec-expectations (3.4.0)
48
+ rspec (3.5.0)
49
+ rspec-core (~> 3.5.0)
50
+ rspec-expectations (~> 3.5.0)
51
+ rspec-mocks (~> 3.5.0)
52
+ rspec-core (3.5.4)
53
+ rspec-support (~> 3.5.0)
54
+ rspec-expectations (3.5.0)
53
55
  diff-lcs (>= 1.2.0, < 2.0)
54
- rspec-support (~> 3.4.0)
55
- rspec-mocks (3.4.1)
56
+ rspec-support (~> 3.5.0)
57
+ rspec-mocks (3.5.0)
56
58
  diff-lcs (>= 1.2.0, < 2.0)
57
- rspec-support (~> 3.4.0)
58
- rspec-support (3.4.1)
59
+ rspec-support (~> 3.5.0)
60
+ rspec-support (3.5.0)
59
61
  safe_yaml (1.0.4)
60
- simplecov (0.11.2)
62
+ simplecov (0.13.0)
61
63
  docile (~> 1.1.0)
62
- json (~> 1.8)
64
+ json (>= 1.8, < 3)
63
65
  simplecov-html (~> 0.10.0)
64
66
  simplecov-html (0.10.0)
65
67
  slop (3.6.0)
@@ -93,4 +95,4 @@ DEPENDENCIES
93
95
  webmock (~> 1.9.3)
94
96
 
95
97
  BUNDLED WITH
96
- 1.13.6
98
+ 1.14.6
data/README.md CHANGED
@@ -33,9 +33,10 @@ Or install it yourself as:
33
33
  client = Myfinance.client("YOUR_TOKEN_HERE")
34
34
  ```
35
35
 
36
- ##### Now you have access to every API endpoint:
36
+ ##### Now you have access to these API endpoints:
37
37
 
38
38
  * [Entities API](https://app.myfinance.com.br/docs/api/entities) as `client.entities`
39
+ * [FinancialTransactions API](https://app.myfinance.com.br/docs/api/financial_transactions) as `client.financial_transactions`
39
40
  * [PayableAccounts API](https://app.myfinance.com.br/docs/api/payable_accounts) as `client.payable_accounts`
40
41
  * [ReceivableAccounts API](https://app.myfinance.com.br/docs/api/receivable_accounts) as `client.receivable_accounts`
41
42
  * [Attachments API](https://app.myfinance.com.br/docs/api/attachments) as `client.attachments`
@@ -81,6 +82,83 @@ client = Myfinance.client("YOUR_TOKEN_HERE")
81
82
  </tr>
82
83
  </table>
83
84
 
85
+ #### [FinancialTransactions](https://app.myfinance.com.br/docs/api/financial_transactions)
86
+
87
+ <table>
88
+ <tr>
89
+ <th>HTTP method</th>
90
+ <th>Endpoint</th>
91
+ <th>Client method</th>
92
+ </tr>
93
+ <tr>
94
+ <td><code>GET</code></td>
95
+ <td>
96
+ <a href="https://app.myfinance.com.br/docs/api/financial_transactions#get_index" target="_blank">
97
+ /entities/:entity_id/deposit_accounts/:deposit_account_id/financial_transactions
98
+ </a>
99
+ </td>
100
+ <td>
101
+ <code>client.financial_transactions.find_all</code>
102
+ </td>
103
+ </tr>
104
+ <tr>
105
+ <td><code>GET</code></td>
106
+ <td>
107
+ <a href="https://app.myfinance.com.br/docs/api/financial_transactions#get_show" target="_blank">
108
+ /entities/:entity_id/deposit_accounts/:deposit_account_id/financial_transactions/:id
109
+ </a>
110
+ </td>
111
+ <td>
112
+ <code>client.financial_transactions.find</code>
113
+ </td>
114
+ </tr>
115
+ <tr>
116
+ <td><code>POST</code></td>
117
+ <td>
118
+ <a href="https://app.myfinance.com.br/docs/api/financial_transactions#post_create" target="_blank">
119
+ /entities/:entity_id/deposit_accounts/:deposit_account_id/financial_transactions
120
+ </a>
121
+ </td>
122
+ <td>
123
+ <code>client.financial_transactions.create</code>
124
+ </td>
125
+ </tr>
126
+ <tr>
127
+ <td><code>PUT</code></td>
128
+ <td>
129
+ <a href="https://app.myfinance.com.br/docs/api/financial_transactions#put_update" target="_blank">
130
+ /entities/:entity_id/deposit_accounts/:deposit_account_id/financial_transactions/:id
131
+ </a>
132
+ </td>
133
+ <td>
134
+ <code>client.financial_transactions.update</code>
135
+ </td>
136
+ </tr>
137
+ <tr>
138
+ <td><code>DELETE</code></td>
139
+ <td>
140
+ <a href="https://app.myfinance.com.br/docs/api/financial_transactions#delete_destroy" target="_blank">
141
+ /entities/:entity_id/deposit_accounts/:deposit_account_id/financial_transactions/:id
142
+ </a>
143
+ </td>
144
+ <td>
145
+ <code>client.financial_transactions.destroy</code>
146
+ </td>
147
+ </tr>
148
+ <tr>
149
+ <td><code>DELETE</code></td>
150
+ <td>
151
+ <a href="https://app.myfinance.com.br/docs/api/financial_transactions#delete_destroy_many" target="_blank">
152
+ /entities/:entity_id/deposit_accounts/:deposit_account_id/financial_transactions/destroy_many?selected_ids=:id1,id2,id3
153
+ </a>
154
+ </td>
155
+ <td>
156
+ <code>client.financial_transactions.destroy_many</code>
157
+ </td>
158
+ </tr>
159
+ </table>
160
+
161
+
84
162
  #### [PayableAccounts](https://app.myfinance.com.br/docs/api/payable_accounts)
85
163
 
86
164
  <table>
data/lib/myfinance.rb CHANGED
@@ -12,6 +12,8 @@ require "myfinance/entities/collection"
12
12
  require "myfinance/entities/entity"
13
13
  require "myfinance/entities/entity_collection"
14
14
  require "myfinance/entities/attachment_collection"
15
+ require "myfinance/entities/financial_transaction"
16
+ require "myfinance/entities/financial_transaction_collection"
15
17
  require "myfinance/entities/financial_account"
16
18
  require "myfinance/entities/payable_account"
17
19
  require "myfinance/entities/receivable_account"
@@ -33,6 +35,7 @@ require "myfinance/entities/tax_collection"
33
35
 
34
36
  require "myfinance/resources/base"
35
37
  require "myfinance/resources/entity"
38
+ require "myfinance/resources/financial_transaction"
36
39
  require "myfinance/resources/financial_account"
37
40
  require "myfinance/resources/payable_account"
38
41
  require "myfinance/resources/receivable_account"
@@ -20,6 +20,10 @@ module Myfinance
20
20
  Myfinance::Resources::Entity.new(http)
21
21
  end
22
22
 
23
+ def financial_transactions
24
+ Myfinance::Resources::FinancialTransaction.new(http)
25
+ end
26
+
23
27
  def payable_accounts
24
28
  Myfinance::Resources::PayableAccount.new(http)
25
29
  end
@@ -12,7 +12,7 @@ module Myfinance
12
12
  @response = response
13
13
  @collection = []
14
14
  @headers = response.headers['Link'].split(',') rescue []
15
- end
15
+ end
16
16
 
17
17
  def self.build(response)
18
18
  self.new(response).build
@@ -11,7 +11,7 @@ module Myfinance
11
11
  attribute :force_destroy, Boolean
12
12
  attribute :id, Integer
13
13
  attribute :imported_from_sync, Boolean
14
- attribute :initial_balance, String
14
+ attribute :initial_balance, Decimal
15
15
  attribute :last_transaction_date, Date
16
16
  attribute :name, String
17
17
  attribute :sync_response, String
@@ -0,0 +1,41 @@
1
+ module Myfinance
2
+ module Entities
3
+ class FinancialTransaction < Base
4
+ attribute :classification_center_id, Integer
5
+ attribute :deposit_account_id, Integer
6
+ attribute :person_id, Integer
7
+ attribute :parent_id, Integer
8
+ attribute :owner_id, Integer
9
+ attribute :currency_id, Integer
10
+ attribute :category_id, Integer
11
+ attribute :type, String
12
+ attribute :occurred_at, Date
13
+ attribute :document, String
14
+ attribute :original_description, String
15
+ attribute :user_description, String
16
+ attribute :notes, String
17
+ attribute :amount, Decimal
18
+ attribute :id, Integer
19
+ attribute :is_pending, Boolean
20
+ attribute :created_at, DateTime
21
+ attribute :updated_at, DateTime
22
+ attribute :guid, String
23
+ attribute :imported_from_sync, Boolean
24
+ attribute :transfer_id, Integer
25
+ attribute :absolute_amount, Decimal
26
+ attribute :bank_statement_id, Integer
27
+ attribute :balance_difference, Boolean
28
+ attribute :force_destroy, Boolean
29
+ attribute :divided, Boolean
30
+ attribute :attachments_count, Integer
31
+ attribute :duplicity_suspicion_id, Integer
32
+ attribute :excel_import_id, Integer
33
+ attribute :observation, String
34
+ attribute :api_related, Boolean
35
+ attribute :bank_slips_count, Integer
36
+ attribute :reconciled, Boolean
37
+ attribute :indexed_at, DateTime
38
+ attribute :automatic_rule_related, Boolean
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,14 @@
1
+ module Myfinance
2
+ module Entities
3
+ #
4
+ # A wrapper to Myfinance financial transactions collection
5
+ #
6
+ class FinancialTransactionCollection < Collection
7
+ def build_collection
8
+ response.parsed_body.each do |attributes|
9
+ collection.push(Myfinance::Entities::FinancialTransaction.new(attributes["financial_transaction"]))
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -25,7 +25,7 @@ module Myfinance
25
25
  body: body,
26
26
  headers: headers,
27
27
  accept_encoding: "gzip"
28
- }.reject { |k,v| v.nil? }
28
+ }.reject { |_k,v| v.nil? }
29
29
  end
30
30
 
31
31
  def headers
@@ -46,7 +46,7 @@ module Myfinance
46
46
  # Documentation: https://app.myfinance.com.br/docs/api/receivable_accounts#delete_destroy
47
47
  #
48
48
  def destroy(id, entity_id)
49
- http.delete(endpoint_for(id, entity_id, :destroy)) do |response|
49
+ http.delete(endpoint_for(id, entity_id, :destroy)) do |_response|
50
50
  true
51
51
  end
52
52
  end
@@ -0,0 +1,109 @@
1
+ module Myfinance
2
+ module Resources
3
+ class FinancialTransaction < Base
4
+ #
5
+ # A wrapper to Myfinance financial transaction API
6
+ #
7
+ # [API]
8
+ # Documentation: https://app.myfinance.com.br/docs/api/financial_transactions
9
+ #
10
+ def find_all(entity_id, deposit_account_id)
11
+ #
12
+ # List all financial transactions
13
+ #
14
+ # [API]
15
+ # Method: <tt>GET entities/:entity_id/deposit_accounts/:deposit_account_id/financial_transactions</tt>
16
+ #
17
+ # Documentation: https://app.myfinance.com.br/docs/api/financial_transactions#get_index
18
+ #
19
+ http.get(path(entity_id, deposit_account_id), body: {}) do |response|
20
+ respond_with_collection(response)
21
+ end
22
+ end
23
+
24
+ def find(entity_id, deposit_account_id, id)
25
+ #
26
+ # Show a financial transaction
27
+ #
28
+ # [API]
29
+ # Method: <tt>GET entities/:entity_id/deposit_accounts/:deposit_account_id/financial_transactions/:id</tt>
30
+ #
31
+ # Documentation: https://app.myfinance.com.br/docs/api/financial_transactions#get_show
32
+ #
33
+ ft_path = path(entity_id, deposit_account_id) + "/#{id}"
34
+ http.get(ft_path, body: {}) do |response|
35
+ respond_with_object(response, "financial_transaction")
36
+ end
37
+ end
38
+
39
+ def create(entity_id, deposit_account_id, params = {})
40
+ #
41
+ # Create a financial transaction
42
+ #
43
+ # [API]
44
+ # Method: <tt>POST entities/:entity_id/deposit_accounts/:deposit_account_id/financial_transactions</tt>
45
+ #
46
+ # Documentation: https://app.myfinance.com.br/docs/api/financial_transactions#post_create
47
+ #
48
+ body = { financial_transaction: params }
49
+ http.post(path(entity_id, deposit_account_id), { body: body }) do |response|
50
+ respond_with_object(response, "financial_transaction")
51
+ end
52
+ end
53
+
54
+ def update(entity_id, deposit_account_id, id, params = {})
55
+ # Update a financial transaction
56
+ #
57
+ # [API]
58
+ # Method: <tt>PUT entities/:entity_id/deposit_accounts/:deposit_account_id/financial_transactions/:id</tt>
59
+ #
60
+ # Documentation: https://app.myfinance.com.br/docs/api/financial_transactions#put_update
61
+ #
62
+ ft_path = path(entity_id, deposit_account_id) + "/#{id}"
63
+ body = { financial_transaction: params }
64
+ http.put(ft_path, { body: body }) do |response|
65
+ respond_with_object(response, "financial_transaction")
66
+ end
67
+ end
68
+
69
+ def destroy(entity_id, deposit_account_id, id)
70
+ # Delete a financial transaction
71
+ #
72
+ # [API]
73
+ # Method: <tt>DELETE entities/:entity_id/deposit_accounts/:deposit_account_id/financial_transactions/:id</tt>
74
+ #
75
+ # Documentation: https://app.myfinance.com.br/docs/api/financial_transactions#delete_destroy
76
+ #
77
+ ft_path = path(entity_id, deposit_account_id) + "/#{id}"
78
+ http.delete(ft_path, body: {}) do |response|
79
+ response
80
+ end
81
+ end
82
+
83
+ def destroy_many(entity_id, deposit_account_id, ids=[])
84
+ # Delete many financial transactions
85
+ #
86
+ # [API]
87
+ # Method: <tt>DELETE entities/:entity_id/deposit_accounts/:deposit_account_id/financial_transactions/destroy_many?selected_ids=:id1,id2,id3</tt>
88
+ #
89
+ # Documentation: https://app.myfinance.com.br/docs/api/financial_transactions#delete_destroy_many
90
+ #
91
+ ft_path = destroy_many_path(entity_id, deposit_account_id, ids)
92
+ http.delete(ft_path, body: {}) do |response|
93
+ response
94
+ end
95
+ end
96
+
97
+
98
+ private
99
+
100
+ def path(entity_id, deposit_account_id)
101
+ "/entities/#{entity_id}/deposit_accounts/#{deposit_account_id}/financial_transactions"
102
+ end
103
+
104
+ def destroy_many_path(entity_id, deposit_account_id, ids)
105
+ path(entity_id, deposit_account_id) + "/destroy_many?selected_ids=#{ids.join(",")}"
106
+ end
107
+ end
108
+ end
109
+ end
@@ -1,3 +1,3 @@
1
1
  module Myfinance
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -84,6 +84,16 @@ describe Myfinance::Client do
84
84
  end
85
85
  end
86
86
 
87
+ describe "#financial_transactions" do
88
+ it "instantiates a new Myfinance::Resources::FinancialTransaction" do
89
+ expect(
90
+ Myfinance::Resources::FinancialTransaction
91
+ ).to receive(:new).with(subject.http)
92
+
93
+ subject.financial_transactions
94
+ end
95
+ end
96
+
87
97
  describe "#deposit_accounts" do
88
98
  it "instantiates a new Myfinance::Resources::DepositAccount" do
89
99
  expect(
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ describe Myfinance::Entities::FinancialTransactionCollection 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::FinancialTransaction)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe Myfinance::Entities::FinancialTransaction do
4
+ it_behaves_like "entity_attributes", [:deposit_account_id, :person_id, :parent_id, :owner_id, :currency_id,
5
+ :category_id, :type, :occurred_at, :document, :original_description,
6
+ :user_description, :notes, :amount, :id, :is_pending, :created_at,
7
+ :updated_at, :guid, :imported_from_sync, :transfer_id, :absolute_amount,
8
+ :bank_statement_id, :balance_difference, :force_destroy, :divided,
9
+ :attachments_count, :duplicity_suspicion_id, :excel_import_id,
10
+ :observation, :api_related, :bank_slips_count, :reconciled, :indexed_at,
11
+ :automatic_rule_related, :classification_center_id]
12
+ end
@@ -0,0 +1,130 @@
1
+ require "spec_helper"
2
+
3
+ describe Myfinance::Resources::FinancialTransaction, vcr: true do
4
+ let(:da_id) { 14268 }
5
+ let(:ent_id) { 3798 }
6
+ let(:ft_id) { 1663920 }
7
+ let(:financial_transactions) { client.financial_transactions }
8
+ let(:params) { { amount: 68.5, occurred_at: "2011-07-15", type: "Debit" } }
9
+ let(:request_error) { Myfinance::RequestError }
10
+
11
+ describe "#find_all" do
12
+ context "when successful" do
13
+ subject { client.financial_transactions.find_all(ent_id, da_id) }
14
+ before :each do
15
+ subject.build
16
+ end
17
+
18
+ it "returns a 200 OK response code" do
19
+ expect(subject.response.code).to eq(200)
20
+ end
21
+
22
+ it "return collection of FinancialTransactions" do
23
+ expect(subject).to be_a(Myfinance::Entities::FinancialTransactionCollection)
24
+ end
25
+ end
26
+
27
+ context "when supplying invalid IDs" do
28
+ it "raises not found error with error 404" do
29
+ expect { financial_transactions.find_all(nil, nil) }.to raise_error(request_error) do |e|
30
+ expect(e.code).to eq(404)
31
+ expect(e.message).to eq("Not Found")
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "#find" do
38
+ context "when successful" do
39
+ subject { client.financial_transactions.find(ent_id, da_id, ft_id) }
40
+
41
+ it "returns a FinancialTransactions" do
42
+ expect(subject).to be_a(Myfinance::Entities::FinancialTransaction)
43
+ end
44
+ end
45
+
46
+ context "when supplying invalid IDs" do
47
+ it "raises not found error with error 404" do
48
+ expect { financial_transactions.find(nil, nil, nil) }.to raise_error(request_error) do |e|
49
+ expect(e.code).to eq(404)
50
+ expect(e.message).to eq("Not Found")
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ describe "#create" do
57
+ context "when successful" do
58
+ let(:ft) { client.financial_transactions.create(ent_id, da_id, params) }
59
+
60
+ it "returns created FT" do
61
+ expect(ft.type).to eq("Debit")
62
+ expect(ft.amount).to eq(-68.5)
63
+ expect(ft.occurred_at).to eq(Date.new(2011, 07, 15))
64
+ end
65
+ end
66
+
67
+ context "when supplying invalid params" do
68
+ it "raises error" do
69
+ params[:type] = "QUALQUER"
70
+ expect { financial_transactions.create(ent_id, da_id, params) }.to raise_error(request_error) do |e|
71
+ expect(e.code).to eq(500)
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ describe "#update" do
78
+ context "when successful" do
79
+ let(:params) { { id: ft_id, absolute_amount: BigDecimal.new(500), amount: BigDecimal.new(500) } }
80
+ let(:ft) { client.financial_transactions.update(ent_id, da_id, ft_id, params) }
81
+
82
+ it "returns updated FT" do
83
+ expect(ft).to be_a(Myfinance::Entities::FinancialTransaction)
84
+ end
85
+ end
86
+
87
+ context "when supplying invalid params" do
88
+ let(:params) {{ absolute_amount: BigDecimal.new(500), occurred_at: "2011-07-15", type: "QUALQUER"}}
89
+
90
+ it "raises error" do
91
+ expect { financial_transactions.update(ent_id, da_id, ft_id, params) }.to raise_error(request_error) do |e|
92
+ expect(e.code).to eq(500)
93
+ end
94
+ end
95
+ end
96
+ end
97
+
98
+ describe "#destroy" do
99
+ context "when successful" do
100
+ let(:ft) { client.financial_transactions.create(ent_id, da_id, params) }
101
+ subject { client.financial_transactions.destroy(ent_id, da_id, ft.id) }
102
+
103
+ it "returns 200 OK" do
104
+ expect(subject.code).to eq(200)
105
+ end
106
+
107
+ context "when supplying unknown ID" do
108
+ it "returns 404 not found" do
109
+ expect { financial_transactions.destroy(ent_id, da_id, 99999) }.to raise_error(request_error) do |e|
110
+ expect(e.code).to eq(404)
111
+ expect(e.message).to eq("Not Found")
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ describe "#destroy_many" do
119
+ context "when successful" do
120
+ let(:params) { { amount: 42.42, occurred_at: "2011-07-15", type: "Debit" } }
121
+ let(:ft) { client.financial_transactions.create(ent_id, da_id, params) }
122
+ let(:ft2) { client.financial_transactions.create(ent_id, da_id, params) }
123
+ subject { client.financial_transactions.destroy_many(ent_id, da_id, [ft.id, ft2.id]) }
124
+
125
+ it "returns 200 OK" do
126
+ expect(subject.code).to eq(200)
127
+ end
128
+ end
129
+ end
130
+ end
@@ -1,3 +1,3 @@
1
1
  def client
2
- Myfinance.client('b552dd5a8598ca089b91c5e355a83b86e4696aefac9eaa05')
2
+ Myfinance.client("b552dd5a8598ca089b91c5e355a83b86e4696aefac9eaa05")
3
3
  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.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Hertz
@@ -253,6 +253,8 @@ files:
253
253
  - lib/myfinance/entities/entity.rb
254
254
  - lib/myfinance/entities/entity_collection.rb
255
255
  - lib/myfinance/entities/financial_account.rb
256
+ - lib/myfinance/entities/financial_transaction.rb
257
+ - lib/myfinance/entities/financial_transaction_collection.rb
256
258
  - lib/myfinance/entities/payable_account.rb
257
259
  - lib/myfinance/entities/person.rb
258
260
  - lib/myfinance/entities/person_collection.rb
@@ -272,6 +274,7 @@ files:
272
274
  - lib/myfinance/resources/deposit_account.rb
273
275
  - lib/myfinance/resources/entity.rb
274
276
  - lib/myfinance/resources/financial_account.rb
277
+ - lib/myfinance/resources/financial_transaction.rb
275
278
  - lib/myfinance/resources/payable_account.rb
276
279
  - lib/myfinance/resources/person.rb
277
280
  - lib/myfinance/resources/receivable_account.rb
@@ -296,6 +299,8 @@ files:
296
299
  - spec/lib/myfinance/entities/deposit_account_spec.rb
297
300
  - spec/lib/myfinance/entities/entity_collection_spec.rb
298
301
  - spec/lib/myfinance/entities/entity_spec.rb
302
+ - spec/lib/myfinance/entities/financial_transaction_collection_spec.rb
303
+ - spec/lib/myfinance/entities/financial_transaction_spec.rb
299
304
  - spec/lib/myfinance/entities/payable_account_spec.rb
300
305
  - spec/lib/myfinance/entities/person_collection_spec.rb
301
306
  - spec/lib/myfinance/entities/person_spec.rb
@@ -312,6 +317,7 @@ files:
312
317
  - spec/lib/myfinance/resources/classification_center_spec.rb
313
318
  - spec/lib/myfinance/resources/deposit_account_spec.rb
314
319
  - spec/lib/myfinance/resources/entity_spec.rb
320
+ - spec/lib/myfinance/resources/financial_transaction_spec.rb
315
321
  - spec/lib/myfinance/resources/payable_account_spec.rb
316
322
  - spec/lib/myfinance/resources/person_spec.rb
317
323
  - spec/lib/myfinance/resources/receivable_account_spec.rb
@@ -368,6 +374,8 @@ test_files:
368
374
  - spec/lib/myfinance/entities/deposit_account_spec.rb
369
375
  - spec/lib/myfinance/entities/entity_collection_spec.rb
370
376
  - spec/lib/myfinance/entities/entity_spec.rb
377
+ - spec/lib/myfinance/entities/financial_transaction_collection_spec.rb
378
+ - spec/lib/myfinance/entities/financial_transaction_spec.rb
371
379
  - spec/lib/myfinance/entities/payable_account_spec.rb
372
380
  - spec/lib/myfinance/entities/person_collection_spec.rb
373
381
  - spec/lib/myfinance/entities/person_spec.rb
@@ -384,6 +392,7 @@ test_files:
384
392
  - spec/lib/myfinance/resources/classification_center_spec.rb
385
393
  - spec/lib/myfinance/resources/deposit_account_spec.rb
386
394
  - spec/lib/myfinance/resources/entity_spec.rb
395
+ - spec/lib/myfinance/resources/financial_transaction_spec.rb
387
396
  - spec/lib/myfinance/resources/payable_account_spec.rb
388
397
  - spec/lib/myfinance/resources/person_spec.rb
389
398
  - spec/lib/myfinance/resources/receivable_account_spec.rb