myfinance 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +29 -0
- data/lib/myfinance/resources/deposit_account.rb +24 -17
- data/lib/myfinance/resources/entity.rb +19 -0
- data/lib/myfinance/version.rb +1 -1
- data/spec/lib/myfinance/resources/deposit_account_spec.rb +39 -11
- data/spec/lib/myfinance/resources/entity_spec.rb +25 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1eefa221205c3ed3d67d74d90c709f80dca6f4c
|
4
|
+
data.tar.gz: a4910d9b8d7af6d4c0f439a1f4a028557937b2cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38adecf14ed9cb00370f632ad44479be2f87b24147a91da63cc08e0c0843d9366c2dbaf9e0a0266adb726d957d1cb251faa37f632ee2b075ea57f46fc5fa0414
|
7
|
+
data.tar.gz: d55d18de0c4a758f2d2b5057e20f03483824fb3050251f423b31f97e5f688474133c84fb5af261469104f0ba80037de14d340bd6d88670e39afd0ce6905ce341
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -97,6 +97,18 @@ client = Myfinance.client("YOUR_TOKEN_HERE")
|
|
97
97
|
<code>client.entities.find</code>
|
98
98
|
</td>
|
99
99
|
</tr>
|
100
|
+
<tr>
|
101
|
+
<td><code>GET</code></td>
|
102
|
+
<td>
|
103
|
+
<a href="https://app.myfinance.com.br/docs/api/entities#get_show" target="_blank">
|
104
|
+
/entities
|
105
|
+
</a>
|
106
|
+
</td>
|
107
|
+
<td>
|
108
|
+
<code>client.entities.find_by</code>
|
109
|
+
</td>
|
110
|
+
</tr>
|
111
|
+
|
100
112
|
</table>
|
101
113
|
|
102
114
|
#### [FinancialTransactions](https://app.myfinance.com.br/docs/api/financial_transactions)
|
@@ -503,6 +515,17 @@ client = Myfinance.client("YOUR_TOKEN_HERE")
|
|
503
515
|
<code>client.deposit_accounts.find</code>
|
504
516
|
</td>
|
505
517
|
</tr>
|
518
|
+
<tr>
|
519
|
+
<td><code>GET</code></td>
|
520
|
+
<td>
|
521
|
+
<a href="https://app.myfinance.com.br/docs/api/deposit_accounts#get_show" target="_blank">
|
522
|
+
/entities/:entity_id/deposit_accounts
|
523
|
+
</a>
|
524
|
+
</td>
|
525
|
+
<td>
|
526
|
+
<code>client.deposit_accounts.find_by</code>
|
527
|
+
</td>
|
528
|
+
</tr>
|
506
529
|
<tr>
|
507
530
|
<td><code>POST</code></td>
|
508
531
|
<td>
|
@@ -1083,6 +1106,12 @@ To install this gem onto your local machine, run `bundle exec rake install`.
|
|
1083
1106
|
|
1084
1107
|
To release a new version, update the version number in `lib/myfinance/version.rb`, run `bundle install` and commit & push the changes to the repository. Then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). Make sure you have publishing rights for the gem on RubyGems beforehand, though.
|
1085
1108
|
|
1109
|
+
After publishing the new version, add a comment to each pull request that was included in this release like this:
|
1110
|
+
|
1111
|
+
```
|
1112
|
+
:shipit: released on [version x.y.z](https://rubygems.org/gems/myfinance/versions/x.y.z)
|
1113
|
+
```
|
1114
|
+
|
1086
1115
|
## Contributing
|
1087
1116
|
|
1088
1117
|
Bug reports and pull requests are welcome on GitHub at https://github.com/myfreecomm/myfinance-client-ruby. This project is intended to be a safe and welcoming space for collaboration.
|
@@ -16,9 +16,7 @@ module Myfinance
|
|
16
16
|
# Documentation: https://app.myfinance.com.br/docs/api/deposit_accounts#get_index
|
17
17
|
#
|
18
18
|
def find_all(entity_id)
|
19
|
-
http.get(
|
20
|
-
"/entities/#{entity_id}/deposit_accounts", body: {}
|
21
|
-
) do |response|
|
19
|
+
http.get("/entities/#{entity_id}/deposit_accounts", body: {}) do |response|
|
22
20
|
respond_with_collection(response)
|
23
21
|
end
|
24
22
|
end
|
@@ -32,13 +30,20 @@ module Myfinance
|
|
32
30
|
# Documentation: https://app.myfinance.com.br/docs/api/deposit_accounts#get_show
|
33
31
|
#
|
34
32
|
def find(entity_id, id)
|
35
|
-
http.get(
|
36
|
-
"/entities/#{entity_id}/deposit_accounts/#{id}", body: {}
|
37
|
-
) do |response|
|
33
|
+
http.get("/entities/#{entity_id}/deposit_accounts/#{id}", body: {}) do |response|
|
38
34
|
respond_with_object(response, "deposit_account")
|
39
35
|
end
|
40
36
|
end
|
41
37
|
|
38
|
+
def find_by(entity_id, params = {})
|
39
|
+
sanitized_params = search_params(params)
|
40
|
+
endpoint = encode_endpoint(entity_id, sanitized_params)
|
41
|
+
|
42
|
+
http.get(endpoint, body: {}) do |response|
|
43
|
+
respond_with_collection(response)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
42
47
|
#
|
43
48
|
# Creates a deposit account of entity
|
44
49
|
#
|
@@ -48,10 +53,7 @@ module Myfinance
|
|
48
53
|
# Documentation: https://app.myfinance.com.br/docs/api/deposit_accounts#post_create
|
49
54
|
#
|
50
55
|
def create(entity_id, params = {})
|
51
|
-
http.post(
|
52
|
-
"/entities/#{entity_id}/deposit_accounts",
|
53
|
-
body: { deposit_account: params }
|
54
|
-
) do |response|
|
56
|
+
http.post("/entities/#{entity_id}/deposit_accounts", body: { deposit_account: params }) do |response|
|
55
57
|
respond_with_object(response, "deposit_account")
|
56
58
|
end
|
57
59
|
end
|
@@ -65,10 +67,7 @@ module Myfinance
|
|
65
67
|
# Documentation: https://app.myfinance.com.br/docs/api/deposit_accounts#put_update
|
66
68
|
#
|
67
69
|
def update(entity_id, id, params = {})
|
68
|
-
http.put(
|
69
|
-
"/entities/#{entity_id}/deposit_accounts/#{id}",
|
70
|
-
body: { deposit_account: params }
|
71
|
-
) do |response|
|
70
|
+
http.put("/entities/#{entity_id}/deposit_accounts/#{id}", body: { deposit_account: params }) do |response|
|
72
71
|
respond_with_object(response, "deposit_account")
|
73
72
|
end
|
74
73
|
end
|
@@ -82,12 +81,20 @@ module Myfinance
|
|
82
81
|
# Documentation: https://app.myfinance.com.br/docs/api/deposit_accounts#delete_destroy
|
83
82
|
#
|
84
83
|
def destroy(entity_id, id)
|
85
|
-
http.delete(
|
86
|
-
"/entities/#{entity_id}/deposit_accounts/#{id}", body: {}
|
87
|
-
) do |response|
|
84
|
+
http.delete("/entities/#{entity_id}/deposit_accounts/#{id}", body: {}) do |response|
|
88
85
|
respond_with_object(response, "deposit_account")
|
89
86
|
end
|
90
87
|
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def search_params(params)
|
92
|
+
params.map { |key, value| "search[#{key}]=#{value}" }.join("&")
|
93
|
+
end
|
94
|
+
|
95
|
+
def encode_endpoint(entity_id, path)
|
96
|
+
URI.encode("/entities/#{entity_id}/deposit_accounts?#{path}")
|
97
|
+
end
|
91
98
|
end
|
92
99
|
end
|
93
100
|
end
|
@@ -34,6 +34,25 @@ module Myfinance
|
|
34
34
|
respond_with_object(response, 'entity')
|
35
35
|
end
|
36
36
|
end
|
37
|
+
|
38
|
+
def find_by(params = {})
|
39
|
+
sanitized_params = search_params(params)
|
40
|
+
endpoint = encode_endpoint(sanitized_params)
|
41
|
+
|
42
|
+
http.get(endpoint, body: {}) do |response|
|
43
|
+
respond_with_collection(response)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def search_params(params)
|
50
|
+
params.map { |key, value| "search[#{key}]=#{value}" }.join("&")
|
51
|
+
end
|
52
|
+
|
53
|
+
def encode_endpoint(path)
|
54
|
+
URI.encode("/entities?#{path}")
|
55
|
+
end
|
37
56
|
end
|
38
57
|
end
|
39
58
|
end
|
data/lib/myfinance/version.rb
CHANGED
@@ -2,10 +2,11 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Myfinance::Resources::DepositAccount, vcr: true do
|
4
4
|
let(:entity_klass) { Myfinance::Entities::DepositAccount }
|
5
|
+
let(:entity_id) { 3798 }
|
5
6
|
|
6
7
|
describe "#find_all" do
|
7
8
|
context "when success" do
|
8
|
-
subject { client.deposit_accounts.find_all(
|
9
|
+
subject { client.deposit_accounts.find_all(entity_id) }
|
9
10
|
|
10
11
|
it "show all deposit accounts" do
|
11
12
|
subject.build
|
@@ -20,7 +21,7 @@ describe Myfinance::Resources::DepositAccount, vcr: true do
|
|
20
21
|
|
21
22
|
it "raises Myfinance::RequestError with 401 status code" do
|
22
23
|
expect {
|
23
|
-
client.deposit_accounts.find_all(
|
24
|
+
client.deposit_accounts.find_all(entity_id)
|
24
25
|
}.to raise_error(Myfinance::RequestError) do |error|
|
25
26
|
expect(error.code).to eq(401)
|
26
27
|
end
|
@@ -31,7 +32,7 @@ describe Myfinance::Resources::DepositAccount, vcr: true do
|
|
31
32
|
describe "#find" do
|
32
33
|
context "when success" do
|
33
34
|
it "show a deposit account successfully" do
|
34
|
-
result = client.deposit_accounts.find(
|
35
|
+
result = client.deposit_accounts.find(entity_id, 14268)
|
35
36
|
expect(result).to be_a(entity_klass)
|
36
37
|
expect(result.name).to eq("Carteira")
|
37
38
|
end
|
@@ -40,7 +41,7 @@ describe Myfinance::Resources::DepositAccount, vcr: true do
|
|
40
41
|
context "when error" do
|
41
42
|
it "raises Myfinance::RequestError with 404 status code" do
|
42
43
|
expect {
|
43
|
-
client.deposit_accounts.find(
|
44
|
+
client.deposit_accounts.find(entity_id, 888888)
|
44
45
|
}.to raise_error(Myfinance::RequestError) do |error|
|
45
46
|
expect(error.code).to eq(404)
|
46
47
|
end
|
@@ -48,6 +49,33 @@ describe Myfinance::Resources::DepositAccount, vcr: true do
|
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
52
|
+
describe "#find_by" do
|
53
|
+
context "when succesful" do
|
54
|
+
subject { client.deposit_accounts.find_by(entity_id, name: "Carteira") }
|
55
|
+
|
56
|
+
it "returns a collection of DepositAccounts" do
|
57
|
+
expect(subject).to be_a(Myfinance::Entities::DepositAccountCollection)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "returns matched DepositAccount" do
|
61
|
+
da = subject.collection.first
|
62
|
+
expect(da.name).to eq("Carteira")
|
63
|
+
end
|
64
|
+
|
65
|
+
it "does not match other DepositAccounts" do
|
66
|
+
expect(subject.collection.size).to eq(1)
|
67
|
+
end
|
68
|
+
|
69
|
+
context "when not found" do
|
70
|
+
subject { client.deposit_accounts.find_by(entity_id, name: "NAO_EXISTE_ESSA_DEPOSIT_ACCOUNT_42") }
|
71
|
+
|
72
|
+
it "returns an empty collection" do
|
73
|
+
expect(subject.collection).to be_empty
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
51
79
|
describe "#create" do
|
52
80
|
context "when success" do
|
53
81
|
let(:params) do
|
@@ -57,7 +85,7 @@ describe Myfinance::Resources::DepositAccount, vcr: true do
|
|
57
85
|
currency_id: 1,
|
58
86
|
deposit_account_type_id: 2,
|
59
87
|
description: "Deposit account test",
|
60
|
-
entity_id:
|
88
|
+
entity_id: entity_id,
|
61
89
|
force_destroy: false,
|
62
90
|
imported_from_sync: false,
|
63
91
|
name: "Caixa 18",
|
@@ -67,7 +95,7 @@ describe Myfinance::Resources::DepositAccount, vcr: true do
|
|
67
95
|
end
|
68
96
|
|
69
97
|
it "creates a deposit account successfully" do
|
70
|
-
result = client.deposit_accounts.create(
|
98
|
+
result = client.deposit_accounts.create(entity_id, params)
|
71
99
|
expect(result).to be_a(entity_klass)
|
72
100
|
end
|
73
101
|
end
|
@@ -75,7 +103,7 @@ describe Myfinance::Resources::DepositAccount, vcr: true do
|
|
75
103
|
context "when error" do
|
76
104
|
it "raises Myfinance::RequestError with 422 status code" do
|
77
105
|
expect {
|
78
|
-
client.deposit_accounts.create(
|
106
|
+
client.deposit_accounts.create(entity_id, {})
|
79
107
|
}.to raise_error(Myfinance::RequestError) do |error|
|
80
108
|
expect(error.code).to eq(422)
|
81
109
|
end
|
@@ -87,7 +115,7 @@ describe Myfinance::Resources::DepositAccount, vcr: true do
|
|
87
115
|
context "when success" do
|
88
116
|
it "updates a deposit account successfully" do
|
89
117
|
expect(
|
90
|
-
client.deposit_accounts.update(
|
118
|
+
client.deposit_accounts.update(entity_id, 14820, { name: "Name" })
|
91
119
|
).to be_a(entity_klass)
|
92
120
|
end
|
93
121
|
end
|
@@ -95,7 +123,7 @@ describe Myfinance::Resources::DepositAccount, vcr: true do
|
|
95
123
|
context "when invalid" do
|
96
124
|
it "raises Myfinance::RequestError with 422 status code" do
|
97
125
|
expect {
|
98
|
-
client.deposit_accounts.update(
|
126
|
+
client.deposit_accounts.update(entity_id, 14820, { name: "" })
|
99
127
|
}.to raise_error(Myfinance::RequestError) do |error|
|
100
128
|
expect(error.code).to eq(422)
|
101
129
|
end
|
@@ -106,14 +134,14 @@ describe Myfinance::Resources::DepositAccount, vcr: true do
|
|
106
134
|
describe "#delete" do
|
107
135
|
context "when success" do
|
108
136
|
it "destroy a deposit account successfully" do
|
109
|
-
expect(client.deposit_accounts.destroy(
|
137
|
+
expect(client.deposit_accounts.destroy(entity_id, 14820)).to be_truthy
|
110
138
|
end
|
111
139
|
end
|
112
140
|
|
113
141
|
context "when error" do
|
114
142
|
it "raises Myfinance::RequestError with 404 status code" do
|
115
143
|
expect {
|
116
|
-
client.deposit_accounts.destroy(
|
144
|
+
client.deposit_accounts.destroy(entity_id, 888888)
|
117
145
|
}.to raise_error(Myfinance::RequestError) do |error|
|
118
146
|
expect(error.code).to eq(404)
|
119
147
|
end
|
@@ -60,4 +60,29 @@ describe Myfinance::Resources::Entity do
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
63
|
+
|
64
|
+
describe "#find_by", vcr: true do
|
65
|
+
context "when successful" do
|
66
|
+
subject { client.entities.find_by(name_contains: "Minhas") }
|
67
|
+
|
68
|
+
it "returns a collection of Entities" do
|
69
|
+
expect(subject).to be_a(Myfinance::Entities::EntityCollection)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "returns Entity that matches search params" do
|
73
|
+
entity = subject.collection.first
|
74
|
+
|
75
|
+
expect(entity.id).to eq(3798)
|
76
|
+
expect(entity.name).to eq("Minhas Finanças")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "when not found" do
|
81
|
+
subject { client.entities.find_by(name: "ENTIDADE_QUE_NAO_EXISTE_42") }
|
82
|
+
|
83
|
+
it "returns an empty colleciton" do
|
84
|
+
expect(subject.collection).to be_empty
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
63
88
|
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
|
+
version: 1.1.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-03-
|
14
|
+
date: 2017-03-27 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: typhoeus
|