myfinance 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/Gemfile.lock +1 -1
- data/README.md +0 -45
- data/lib/myfinance/request.rb +2 -1
- data/lib/myfinance/resources/base.rb +12 -0
- data/lib/myfinance/resources/category.rb +10 -18
- data/lib/myfinance/resources/classification_center.rb +11 -21
- data/lib/myfinance/resources/deposit_account.rb +12 -16
- data/lib/myfinance/resources/entity.rb +6 -17
- data/lib/myfinance/resources/person.rb +11 -18
- data/lib/myfinance/version.rb +1 -1
- data/spec/lib/myfinance/request_spec.rb +4 -4
- data/spec/lib/myfinance/resources/category_spec.rb +36 -52
- data/spec/lib/myfinance/resources/classification_center_spec.rb +41 -30
- data/spec/lib/myfinance/resources/deposit_account_spec.rb +26 -28
- data/spec/lib/myfinance/resources/entity_spec.rb +25 -26
- data/spec/lib/myfinance/resources/person_spec.rb +34 -42
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd16eafab7c1a94cdb638ad2e9efa9c942029289
|
4
|
+
data.tar.gz: b71308b1b0e4cd9629698d185cbd9ae7a70d242d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c186bac4b437d5a1ace502f62985389aa0637cf9614886bc7805e5d6fc619f979e7c41e5810a63d2d113bb240b2ca3d2a88f4310aad64dd4a8b588ad882be856
|
7
|
+
data.tar.gz: 9eba0d8098e7be11dd9e2694d2f2e32a2c626987885437f41fdaad42b016d43bb4a4aa1a463f38fa3f856f471ac57d3106b163b35fede4d60d1a5261acfa140c
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v1.2.0
|
4
|
+
### Endpoints improvements
|
5
|
+
- The `#find_all` method of all endpoints that support filtering can now receive parameters to refine the results and paginate
|
6
|
+
### Deprecations
|
7
|
+
- No longer supports `#find_by`. Use `#find_all` instead, passing filters as a hash if needed.
|
8
|
+
### Fixes
|
9
|
+
- Params encoding set to Rack
|
10
|
+
|
11
|
+
## v1.1.0
|
12
|
+
|
13
|
+
### New Endpoints
|
14
|
+
- Add endpoint Deposit Accounts filtering
|
15
|
+
- Add endpoint Entities filtering
|
16
|
+
|
3
17
|
## v1.0.0
|
4
18
|
|
5
19
|
### New Endpoints
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -97,18 +97,6 @@ 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
|
-
|
112
100
|
</table>
|
113
101
|
|
114
102
|
#### [FinancialTransactions](https://app.myfinance.com.br/docs/api/financial_transactions)
|
@@ -515,17 +503,6 @@ client = Myfinance.client("YOUR_TOKEN_HERE")
|
|
515
503
|
<code>client.deposit_accounts.find</code>
|
516
504
|
</td>
|
517
505
|
</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>
|
529
506
|
<tr>
|
530
507
|
<td><code>POST</code></td>
|
531
508
|
<td>
|
@@ -656,17 +633,6 @@ client = Myfinance.client("YOUR_TOKEN_HERE")
|
|
656
633
|
<code>client.classification_centers.find</code>
|
657
634
|
</td>
|
658
635
|
</tr>
|
659
|
-
<tr>
|
660
|
-
<td><code>GET</code></td>
|
661
|
-
<td>
|
662
|
-
<a href="https://app.myfinance.com.br/docs/api/classification_centers#get_show" target="_blank">
|
663
|
-
/classification_centers
|
664
|
-
</a>
|
665
|
-
</td>
|
666
|
-
<td>
|
667
|
-
<code>client.classification_centers.find_by</code>
|
668
|
-
</td>
|
669
|
-
</tr>
|
670
636
|
<tr>
|
671
637
|
<td><code>POST</code></td>
|
672
638
|
<td>
|
@@ -721,17 +687,6 @@ client = Myfinance.client("YOUR_TOKEN_HERE")
|
|
721
687
|
<code>client.people.find_all</code>
|
722
688
|
</td>
|
723
689
|
</tr>
|
724
|
-
<tr>
|
725
|
-
<td><code>GET</code></td>
|
726
|
-
<td>
|
727
|
-
<a href="https://app.myfinance.com.br/docs/api/people" target="_blank">
|
728
|
-
/people
|
729
|
-
</a>
|
730
|
-
</td>
|
731
|
-
<td>
|
732
|
-
<code>client.people.find_by</code>
|
733
|
-
</td>
|
734
|
-
</tr>
|
735
690
|
<tr>
|
736
691
|
<td><code>GET</code></td>
|
737
692
|
<td>
|
data/lib/myfinance/request.rb
CHANGED
@@ -10,6 +10,18 @@ module Myfinance
|
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
|
+
def build_search_endpoint(params)
|
14
|
+
query_string = query(params).join("&")
|
15
|
+
URI.encode("#{endpoint}?#{query_string}")
|
16
|
+
end
|
17
|
+
|
18
|
+
def query(params)
|
19
|
+
page = params.delete(:page)
|
20
|
+
query = params.map { |key, value| "search[#{key}]=#{value}" }
|
21
|
+
query << "page=#{page}" if page
|
22
|
+
query
|
23
|
+
end
|
24
|
+
|
13
25
|
def respond_with_collection(response)
|
14
26
|
collection_klass = Myfinance::Entities.const_get("#{entity_klass_name}Collection")
|
15
27
|
collection_klass.build(response)
|
@@ -15,8 +15,10 @@ module Myfinance
|
|
15
15
|
#
|
16
16
|
# Documentation: https://sandbox.myfinance.com.br/docs/api/categories#get_index
|
17
17
|
#
|
18
|
-
def find_all
|
19
|
-
|
18
|
+
def find_all(params = {})
|
19
|
+
search_endpoint = build_search_endpoint(params)
|
20
|
+
|
21
|
+
http.get(search_endpoint) do |response|
|
20
22
|
respond_with_collection(response)
|
21
23
|
end
|
22
24
|
end
|
@@ -35,22 +37,6 @@ module Myfinance
|
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
38
|
-
#
|
39
|
-
# Find a category by attributes
|
40
|
-
#
|
41
|
-
# [API]
|
42
|
-
# Method: <tt>GET /categories/:id</tt>
|
43
|
-
#
|
44
|
-
# Documentation: https://sandbox.myfinance.com.br/docs/api/categories#get_show
|
45
|
-
#
|
46
|
-
def find_by(params = {})
|
47
|
-
path = params.map { |k, v| "search[#{k}]=#{v}" }.join("&")
|
48
|
-
|
49
|
-
http.get(URI.encode("/categories?#{path}"), body: {}) do |response|
|
50
|
-
respond_with_collection(response)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
40
|
#
|
55
41
|
# Creates a category
|
56
42
|
#
|
@@ -92,6 +78,12 @@ module Myfinance
|
|
92
78
|
respond_with_object response, "category"
|
93
79
|
end
|
94
80
|
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def endpoint
|
85
|
+
"/categories"
|
86
|
+
end
|
95
87
|
end
|
96
88
|
end
|
97
89
|
end
|
@@ -8,15 +8,17 @@ module Myfinance
|
|
8
8
|
#
|
9
9
|
class ClassificationCenter < Base
|
10
10
|
#
|
11
|
-
# List all classification centers
|
11
|
+
# List all classification centers, supplying optional params for refinement
|
12
12
|
#
|
13
13
|
# [API]
|
14
14
|
# Method: <tt>GET /classification_centers</tt>
|
15
15
|
#
|
16
16
|
# Documentation: https://app.myfinance.com.br/docs/api/classification_centers#get_index
|
17
17
|
#
|
18
|
-
def find_all
|
19
|
-
|
18
|
+
def find_all(params = {})
|
19
|
+
search_endpoint = build_search_endpoint(params)
|
20
|
+
|
21
|
+
http.get(search_endpoint) do |response|
|
20
22
|
respond_with_collection(response)
|
21
23
|
end
|
22
24
|
end
|
@@ -34,24 +36,6 @@ module Myfinance
|
|
34
36
|
respond_with_object response, "classification_center"
|
35
37
|
end
|
36
38
|
end
|
37
|
-
|
38
|
-
#
|
39
|
-
# Find classification centers by attributtes
|
40
|
-
#
|
41
|
-
# [API]
|
42
|
-
# Method: <tt>GET /classification_centers</tt>
|
43
|
-
#
|
44
|
-
# Documentation: https://app.myfinance.com.br/docs/api/classification_centers
|
45
|
-
#
|
46
|
-
def find_by(params)
|
47
|
-
values = params.map { |k,v| "search[#{k}]=#{v}" }.join("&")
|
48
|
-
http.get(
|
49
|
-
URI.encode("/classification_centers?#{values}"), body: {}
|
50
|
-
) do |response|
|
51
|
-
respond_with_collection(response)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
39
|
#
|
56
40
|
# Creates a classification center
|
57
41
|
#
|
@@ -98,6 +82,12 @@ module Myfinance
|
|
98
82
|
respond_with_object response, "classification_center"
|
99
83
|
end
|
100
84
|
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def endpoint
|
89
|
+
"/classification_centers"
|
90
|
+
end
|
101
91
|
end
|
102
92
|
end
|
103
93
|
end
|
@@ -8,15 +8,17 @@ module Myfinance
|
|
8
8
|
#
|
9
9
|
class DepositAccount < Base
|
10
10
|
#
|
11
|
-
# List all deposit accounts of entity
|
11
|
+
# List all deposit accounts of entity with optional filters for refinement
|
12
12
|
#
|
13
13
|
# [API]
|
14
14
|
# Method: <tt>GET /entities/:entity_id/deposit_accounts</tt>
|
15
15
|
#
|
16
16
|
# Documentation: https://app.myfinance.com.br/docs/api/deposit_accounts#get_index
|
17
17
|
#
|
18
|
-
def find_all(entity_id)
|
19
|
-
|
18
|
+
def find_all(entity_id, params = {})
|
19
|
+
search_endpoint = build_search_endpoint(entity_id, params)
|
20
|
+
|
21
|
+
http.get(search_endpoint) do |response|
|
20
22
|
respond_with_collection(response)
|
21
23
|
end
|
22
24
|
end
|
@@ -35,15 +37,6 @@ module Myfinance
|
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
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
|
-
|
47
40
|
#
|
48
41
|
# Creates a deposit account of entity
|
49
42
|
#
|
@@ -88,12 +81,15 @@ module Myfinance
|
|
88
81
|
|
89
82
|
private
|
90
83
|
|
91
|
-
def
|
92
|
-
|
84
|
+
def build_search_endpoint(entity_id, params)
|
85
|
+
query_string = query(params).join("&")
|
86
|
+
deposit_endpoint = endpoint(entity_id)
|
87
|
+
|
88
|
+
URI.encode("#{deposit_endpoint}?#{query_string}")
|
93
89
|
end
|
94
90
|
|
95
|
-
def
|
96
|
-
|
91
|
+
def endpoint(entity_id)
|
92
|
+
"/entities/#{entity_id}/deposit_accounts"
|
97
93
|
end
|
98
94
|
end
|
99
95
|
end
|
@@ -15,8 +15,10 @@ module Myfinance
|
|
15
15
|
#
|
16
16
|
# Documentation: https://app.myfinance.com.br/docs/api/entities#get_index
|
17
17
|
#
|
18
|
-
def find_all
|
19
|
-
|
18
|
+
def find_all(params = {})
|
19
|
+
search_endpoint = build_search_endpoint(params)
|
20
|
+
|
21
|
+
http.get(search_endpoint) do |response|
|
20
22
|
respond_with_collection(response)
|
21
23
|
end
|
22
24
|
end
|
@@ -35,23 +37,10 @@ module Myfinance
|
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
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
40
|
private
|
48
41
|
|
49
|
-
def
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
def encode_endpoint(path)
|
54
|
-
URI.encode("/entities?#{path}")
|
42
|
+
def endpoint
|
43
|
+
"/entities"
|
55
44
|
end
|
56
45
|
end
|
57
46
|
end
|
@@ -8,35 +8,22 @@ module Myfinance
|
|
8
8
|
#
|
9
9
|
class Person < Base
|
10
10
|
#
|
11
|
-
# List all people
|
11
|
+
# List all people with optional filters for refinement
|
12
12
|
#
|
13
13
|
# [API]
|
14
14
|
# Method: <tt>GET /people</tt>
|
15
15
|
#
|
16
16
|
# Documentation: https://app.myfinance.com.br/docs/api/people#get_index
|
17
17
|
#
|
18
|
-
def find_all
|
19
|
-
|
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("&")
|
18
|
+
def find_all(params = {})
|
19
|
+
search_endpoint = build_search_endpoint(params)
|
34
20
|
|
35
|
-
http.get(
|
21
|
+
http.get(search_endpoint) do |response|
|
36
22
|
respond_with_collection(response)
|
37
23
|
end
|
38
24
|
end
|
39
25
|
|
26
|
+
|
40
27
|
#
|
41
28
|
# Show a person
|
42
29
|
#
|
@@ -92,6 +79,12 @@ module Myfinance
|
|
92
79
|
respond_with_object response, "person"
|
93
80
|
end
|
94
81
|
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def endpoint
|
86
|
+
"/people"
|
87
|
+
end
|
95
88
|
end
|
96
89
|
end
|
97
90
|
end
|
data/lib/myfinance/version.rb
CHANGED
@@ -5,7 +5,7 @@ describe Myfinance::Request do
|
|
5
5
|
subject { described_class.new({ method: 'post', params: {}, url: Myfinance.configuration.url, user_agent: 'My Test User-Agent', token: 'my-auth-hash' }) }
|
6
6
|
|
7
7
|
it "does a request using Typhoeus::Request" do
|
8
|
-
expect(Typhoeus::Request).to receive(:new).with("https://sandbox.myfinance.com.br", { method: "post", params: {}, headers: { "Accept" => "application/json", "Content-Type" => "application/json", "User-Agent" => "My Test User-Agent", "Authorization" => "Basic bXktYXV0aC1oYXNoOlg=" }, accept_encoding: "gzip" }).and_return(double(run: true, response: true))
|
8
|
+
expect(Typhoeus::Request).to receive(:new).with("https://sandbox.myfinance.com.br", { method: "post", params: {}, headers: { "Accept" => "application/json", "Content-Type" => "application/json", "User-Agent" => "My Test User-Agent", "Authorization" => "Basic bXktYXV0aC1oYXNoOlg=" }, accept_encoding: "gzip", params_encoding: :rack }).and_return(double(run: true, response: true))
|
9
9
|
subject.run
|
10
10
|
end
|
11
11
|
|
@@ -30,7 +30,7 @@ describe Myfinance::Request do
|
|
30
30
|
subject { described_class.new({ method: 'post', params: {}, url: Myfinance.configuration.url, user_agent: 'My Test User-Agent', token: 'my-auth-hash', account_id: "" }) }
|
31
31
|
|
32
32
|
it "does not add ACCOUNT_ID on headers" do
|
33
|
-
expect(Typhoeus::Request).to receive(:new).with("https://sandbox.myfinance.com.br", { method: "post", params: {}, headers: { "Accept" => "application/json", "Content-Type" => "application/json", "User-Agent" => "My Test User-Agent", "Authorization" => "Basic bXktYXV0aC1oYXNoOlg=" }, accept_encoding: "gzip" }).and_return(double(run: true, response: true))
|
33
|
+
expect(Typhoeus::Request).to receive(:new).with("https://sandbox.myfinance.com.br", { method: "post", params: {}, headers: { "Accept" => "application/json", "Content-Type" => "application/json", "User-Agent" => "My Test User-Agent", "Authorization" => "Basic bXktYXV0aC1oYXNoOlg=" }, accept_encoding: "gzip", params_encoding: :rack }).and_return(double(run: true, response: true))
|
34
34
|
subject.run
|
35
35
|
end
|
36
36
|
end
|
@@ -39,7 +39,7 @@ describe Myfinance::Request do
|
|
39
39
|
subject { described_class.new({ method: 'post', params: {}, url: Myfinance.configuration.url, user_agent: 'My Test User-Agent', token: 'my-auth-hash', account_id: nil }) }
|
40
40
|
|
41
41
|
it "does not add ACCOUNT_ID on headers" do
|
42
|
-
expect(Typhoeus::Request).to receive(:new).with("https://sandbox.myfinance.com.br", { method: "post", params: {}, headers: { "Accept" => "application/json", "Content-Type" => "application/json", "User-Agent" => "My Test User-Agent", "Authorization" => "Basic bXktYXV0aC1oYXNoOlg=" }, accept_encoding: "gzip" }).and_return(double(run: true, response: true))
|
42
|
+
expect(Typhoeus::Request).to receive(:new).with("https://sandbox.myfinance.com.br", { method: "post", params: {}, headers: { "Accept" => "application/json", "Content-Type" => "application/json", "User-Agent" => "My Test User-Agent", "Authorization" => "Basic bXktYXV0aC1oYXNoOlg=" }, accept_encoding: "gzip", params_encoding: :rack }).and_return(double(run: true, response: true))
|
43
43
|
subject.run
|
44
44
|
end
|
45
45
|
end
|
@@ -48,7 +48,7 @@ describe Myfinance::Request do
|
|
48
48
|
subject { described_class.new({ method: 'post', params: {}, url: Myfinance.configuration.url, user_agent: 'My Test User-Agent', token: 'my-auth-hash', account_id: 12 }) }
|
49
49
|
|
50
50
|
it "does not add ACCOUNT_ID on headers" do
|
51
|
-
expect(Typhoeus::Request).to receive(:new).with("https://sandbox.myfinance.com.br", { method: "post", params: {}, headers: { "Accept" => "application/json", "Content-Type" => "application/json", "User-Agent" => "My Test User-Agent", "Authorization" => "Basic bXktYXV0aC1oYXNoOlg=", "ACCOUNT_ID" => 12 }, accept_encoding: "gzip" }).and_return(double(run: true, response: true))
|
51
|
+
expect(Typhoeus::Request).to receive(:new).with("https://sandbox.myfinance.com.br", { method: "post", params: {}, headers: { "Accept" => "application/json", "Content-Type" => "application/json", "User-Agent" => "My Test User-Agent", "Authorization" => "Basic bXktYXV0aC1oYXNoOlg=", "ACCOUNT_ID" => 12 }, accept_encoding: "gzip", params_encoding: :rack }).and_return(double(run: true, response: true))
|
52
52
|
subject.run
|
53
53
|
end
|
54
54
|
end
|
@@ -10,83 +10,73 @@ describe Myfinance::Resources::Category, vcr: true do
|
|
10
10
|
it "show all categories successfully" do
|
11
11
|
expect(subject.class).to eq(Myfinance::Entities::CategoryCollection)
|
12
12
|
expect(subject.collection.first.class).to eq(entity_klass)
|
13
|
-
expect(subject.collection.first.full_name).to eq("
|
13
|
+
expect(subject.collection.first.full_name).to eq("Moradia / Água e Esgoto")
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
it "find categories by attributes" do
|
18
|
+
params = { name: "Alimentação" }
|
19
|
+
result = client.categories.find_all(params)
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
expect(result).to be_a(Myfinance::Entities::CategoryCollection)
|
22
|
+
expect(result.collection.first).to be_a(entity_klass)
|
23
|
+
expect(result.collection.first.name).to eql("Alimentação")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when error" do
|
28
|
+
let(:client) { Myfinance.client("") }
|
29
|
+
|
30
|
+
it "raises Myfinance::RequestError with 401 status code" do
|
31
|
+
expect { client.categories.find_all({}) }.to raise_error(Myfinance::RequestError) do |error|
|
32
|
+
expect(error.code).to eql(401)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when not found" do
|
38
|
+
let(:client) { Myfinance.client("") }
|
39
|
+
|
40
|
+
it "raises Myfinance::RequestError with 401 status code" do
|
41
|
+
expect { client.categories.find_all }.to raise_error(Myfinance::RequestError) do |error|
|
42
|
+
expect(error.code).to eql(401)
|
26
43
|
end
|
27
44
|
end
|
28
45
|
end
|
29
46
|
|
30
47
|
describe "#find" do
|
31
48
|
context "with success" do
|
32
|
-
subject { client.categories.find(
|
49
|
+
subject { client.categories.find(532323) }
|
33
50
|
|
34
51
|
it "returns a category successfully" do
|
35
52
|
expect(subject.class).to eql(entity_klass)
|
36
|
-
expect(subject.id).to eql(
|
53
|
+
expect(subject.id).to eql(532323)
|
37
54
|
end
|
38
55
|
end
|
39
56
|
|
40
57
|
context "with error" do
|
41
58
|
it "raises Myfinance::RequestError with 404 status code" do
|
42
|
-
expect {
|
43
|
-
client.categories.find(88888888)
|
44
|
-
}.to raise_error(Myfinance::RequestError) do |error|
|
59
|
+
expect { client.categories.find(88888888) }.to raise_error(Myfinance::RequestError) do |error|
|
45
60
|
expect(error.code).to eql(404)
|
46
61
|
end
|
47
62
|
end
|
48
63
|
end
|
49
64
|
end
|
50
65
|
|
51
|
-
describe "#find_by" do
|
52
|
-
context "when success" do
|
53
|
-
it "find categories by attributes" do
|
54
|
-
result = client.categories.find_by({ name: "Alimentação" })
|
55
|
-
expect(result).to be_a(Myfinance::Entities::CategoryCollection)
|
56
|
-
expect(result.collection.first).to be_a(entity_klass)
|
57
|
-
expect(result.collection.first.name).to eql("Alimentação")
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context "when error" do
|
62
|
-
let(:client) { Myfinance.client("") }
|
63
|
-
|
64
|
-
it "raises Myfinance::RequestError with 401 status code" do
|
65
|
-
expect {
|
66
|
-
client.categories.find_by({})
|
67
|
-
}.to raise_error(Myfinance::RequestError) do |error|
|
68
|
-
expect(error.code).to eql(401)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
66
|
describe "#create" do
|
75
|
-
let(:params) { { name: "
|
67
|
+
let(:params) { { name: "Categoria 42 do Marvin" } }
|
76
68
|
|
77
69
|
context "with success" do
|
78
70
|
it "creates a category successfully" do
|
79
71
|
result = client.categories.create(params)
|
80
72
|
expect(result).to be_a(entity_klass)
|
81
|
-
expect(result.name).to eql("
|
73
|
+
expect(result.name).to eql("Categoria 42 do Marvin")
|
82
74
|
end
|
83
75
|
end
|
84
76
|
|
85
77
|
context "with error" do
|
86
78
|
it "raises Myfinance::RequestError with 422 status code" do
|
87
|
-
expect {
|
88
|
-
client.categories.create({})
|
89
|
-
}.to raise_error(Myfinance::RequestError) do |error|
|
79
|
+
expect { client.categories.create({}) }.to raise_error(Myfinance::RequestError) do |error|
|
90
80
|
expect(error.code).to eql(422)
|
91
81
|
end
|
92
82
|
end
|
@@ -96,17 +86,13 @@ describe Myfinance::Resources::Category, vcr: true do
|
|
96
86
|
describe "#update" do
|
97
87
|
context "with success" do
|
98
88
|
it "updates a category successfully" do
|
99
|
-
expect(
|
100
|
-
client.categories.update(548083, { name: "Category updated" })
|
101
|
-
).to be_a(entity_klass)
|
89
|
+
expect(client.categories.update(548083, { name: "Category updated" })).to be_a(entity_klass)
|
102
90
|
end
|
103
91
|
end
|
104
92
|
|
105
93
|
context "with error" do
|
106
94
|
it "raises Myfinance::RequestError with 404 status code" do
|
107
|
-
expect {
|
108
|
-
client.categories.update(88888888, {})
|
109
|
-
}.to raise_error(Myfinance::RequestError) do |error|
|
95
|
+
expect { client.categories.update(88888888, {}) }.to raise_error(Myfinance::RequestError) do |error|
|
110
96
|
expect(error.code).to eql(404)
|
111
97
|
end
|
112
98
|
end
|
@@ -122,15 +108,13 @@ describe Myfinance::Resources::Category, vcr: true do
|
|
122
108
|
describe "#destroy" do
|
123
109
|
context "with success" do
|
124
110
|
it "destroy a category successfully" do
|
125
|
-
expect(client.categories.destroy(
|
111
|
+
expect(client.categories.destroy(532350)).to be_truthy
|
126
112
|
end
|
127
113
|
end
|
128
114
|
|
129
115
|
context "with error" do
|
130
116
|
it "raises Myfinance::RequestError with 404 status code" do
|
131
|
-
expect {
|
132
|
-
client.categories.destroy(88888888)
|
133
|
-
}.to raise_error(Myfinance::RequestError) do |error|
|
117
|
+
expect { client.categories.destroy(88888888) }.to raise_error(Myfinance::RequestError) do |error|
|
134
118
|
expect(error.code).to eql(404)
|
135
119
|
end
|
136
120
|
end
|
@@ -2,6 +2,7 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Myfinance::Resources::ClassificationCenter, vcr: true do
|
4
4
|
let(:entity_klass) { Myfinance::Entities::ClassificationCenter }
|
5
|
+
let(:page) { 2 }
|
5
6
|
|
6
7
|
let(:entity_collection) do
|
7
8
|
Myfinance::Entities::ClassificationCenterCollection
|
@@ -16,6 +17,46 @@ describe Myfinance::Resources::ClassificationCenter, vcr: true do
|
|
16
17
|
expect(subject.collection.first).to be_a(entity_klass)
|
17
18
|
expect(subject.collection.first.name).to eq("Centro de Custo Tal")
|
18
19
|
end
|
20
|
+
|
21
|
+
context "with params" do
|
22
|
+
let(:params) { { entity_id_equals: 3798 } }
|
23
|
+
|
24
|
+
it "find by name successfully" do
|
25
|
+
params[:name_equals] = "Centro de Custo Tal"
|
26
|
+
outcome = client.classification_centers.find_all(params)
|
27
|
+
|
28
|
+
expect(outcome).to be_a(entity_collection)
|
29
|
+
expect(outcome.collection.first).to be_a(entity_klass)
|
30
|
+
expect(outcome.collection.first.name).to eq("Centro de Custo Tal")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "find with special characters" do
|
34
|
+
params[:name_equals] = "Socialização 2"
|
35
|
+
outcome = client.classification_centers.find_all(params)
|
36
|
+
|
37
|
+
expect(outcome).to be_a(entity_collection)
|
38
|
+
expect(outcome.collection.first).to be_a(entity_klass)
|
39
|
+
expect(outcome.collection.first.name).to eq("Socialização 2")
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns a empty classification center successfully" do
|
43
|
+
params[:name_equals] = "Any"
|
44
|
+
outcome = client.classification_centers.find_all(params)
|
45
|
+
|
46
|
+
expect(outcome).to be_a(entity_collection)
|
47
|
+
expect(outcome.collection.first).to be_falsy
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "when paging" do
|
52
|
+
let(:search_params) { { page: page, entity_id_equals: 3798, name_contains: "Centro" } }
|
53
|
+
subject { client.classification_centers.find_all(search_params) }
|
54
|
+
|
55
|
+
it "returns paginated url" do
|
56
|
+
url = subject.response.request.base_url
|
57
|
+
expect(url).to include("page=#{page}")
|
58
|
+
end
|
59
|
+
end
|
19
60
|
end
|
20
61
|
|
21
62
|
context "when error" do
|
@@ -52,36 +93,6 @@ describe Myfinance::Resources::ClassificationCenter, vcr: true do
|
|
52
93
|
end
|
53
94
|
end
|
54
95
|
|
55
|
-
describe "#find_by" do
|
56
|
-
context "when success" do
|
57
|
-
it "find a classification centers by name successfully" do
|
58
|
-
result = client.classification_centers.find_by(
|
59
|
-
{ entity_id_equals: 3798, name_equals: "Centro de Custo Tal" }
|
60
|
-
)
|
61
|
-
expect(result).to be_a(entity_collection)
|
62
|
-
expect(result.collection.first).to be_a(entity_klass)
|
63
|
-
expect(result.collection.first.name).to eq("Centro de Custo Tal")
|
64
|
-
end
|
65
|
-
|
66
|
-
it "find a classification centers with special characters" do
|
67
|
-
result = client.classification_centers.find_by(
|
68
|
-
{ entity_id_equals: 3798, name_equals: "Socialização 2" }
|
69
|
-
)
|
70
|
-
expect(result).to be_a(entity_collection)
|
71
|
-
expect(result.collection.first).to be_a(entity_klass)
|
72
|
-
expect(result.collection.first.name).to eq("Socialização 2")
|
73
|
-
end
|
74
|
-
|
75
|
-
it "returns a empty classification center successfully" do
|
76
|
-
result = client.classification_centers.find_by(
|
77
|
-
{ entity_id_equals: 3798, name_equals: "Any" }
|
78
|
-
)
|
79
|
-
expect(result).to be_a(entity_collection)
|
80
|
-
expect(result.collection.first).to be_falsy
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
96
|
describe "#create" do
|
86
97
|
context "when success" do
|
87
98
|
let(:params) do
|
@@ -12,7 +12,32 @@ describe Myfinance::Resources::DepositAccount, vcr: true do
|
|
12
12
|
subject.build
|
13
13
|
expect(subject).to be_a(Myfinance::Entities::DepositAccountCollection)
|
14
14
|
expect(subject.collection.first).to be_a(entity_klass)
|
15
|
-
expect(subject.collection.first.name).to eq("
|
15
|
+
expect(subject.collection.first.name).to eq("Caixa Grande")
|
16
|
+
end
|
17
|
+
|
18
|
+
context "with params" do
|
19
|
+
subject { client.deposit_accounts.find_all(entity_id, name: "Carteira") }
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns a collection of DepositAccounts" do
|
23
|
+
expect(subject).to be_a(Myfinance::Entities::DepositAccountCollection)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns matched DepositAccount" do
|
27
|
+
da = subject.collection.first
|
28
|
+
expect(da.name).to eq("Caixa Grande")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "does not match other DepositAccounts" do
|
32
|
+
expect(subject.collection.size).to eq(3)
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when not found" do
|
36
|
+
subject { client.deposit_accounts.find_all(entity_id, name: "NAO_EXISTE_ESSA_DEPOSIT_ACCOUNT_42") }
|
37
|
+
|
38
|
+
it "returns an empty collection" do
|
39
|
+
expect(subject.collection).to be_empty
|
40
|
+
end
|
16
41
|
end
|
17
42
|
end
|
18
43
|
|
@@ -49,33 +74,6 @@ describe Myfinance::Resources::DepositAccount, vcr: true do
|
|
49
74
|
end
|
50
75
|
end
|
51
76
|
|
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
|
-
|
79
77
|
describe "#create" do
|
80
78
|
context "when success" do
|
81
79
|
let(:params) do
|
@@ -18,7 +18,31 @@ describe Myfinance::Resources::Entity do
|
|
18
18
|
expect(subject.collection.first.federation_subscription_number).to eq("")
|
19
19
|
expect(subject.collection.first.imported_from_sync_at).to be_nil
|
20
20
|
expect(subject.collection.first.updated_at).to eq(DateTime.parse("2015-07-29T14:30:36-03:00"))
|
21
|
-
expect(subject.collection.count).to eq(
|
21
|
+
expect(subject.collection.count).to eq(2)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "with params" do
|
26
|
+
let(:params) { { name_contains: "Minhas" } }
|
27
|
+
subject { client.entities.find_all(params) }
|
28
|
+
|
29
|
+
it "returns a collection of Entities" do
|
30
|
+
expect(subject).to be_a(Myfinance::Entities::EntityCollection)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns Entity that matches search params" do
|
34
|
+
entity = subject.collection.first
|
35
|
+
|
36
|
+
expect(entity.id).to eq(3798)
|
37
|
+
expect(entity.name).to eq("Minhas Finanças")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "when not found" do
|
42
|
+
subject { client.entities.find_all(name: "ENTIDADE_QUE_NAO_EXISTE_42") }
|
43
|
+
|
44
|
+
it "returns an empty collection" do
|
45
|
+
expect(subject.collection).to be_empty
|
22
46
|
end
|
23
47
|
end
|
24
48
|
|
@@ -60,29 +84,4 @@ describe Myfinance::Resources::Entity do
|
|
60
84
|
end
|
61
85
|
end
|
62
86
|
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
|
88
87
|
end
|
@@ -10,57 +10,49 @@ describe Myfinance::Resources::Person, vcr: true do
|
|
10
10
|
it "show all people successfully" do
|
11
11
|
expect(subject).to be_a(Myfinance::Entities::PersonCollection)
|
12
12
|
expect(subject.collection.first).to be_a(entity_klass)
|
13
|
-
expect(subject.collection.first.name).to eq("
|
13
|
+
expect(subject.collection.first.name).to eq("João das neves")
|
14
14
|
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context "when not found" do
|
18
|
-
let(:client) { Myfinance.client("") }
|
19
15
|
|
20
|
-
|
21
|
-
|
22
|
-
client.people.find_all
|
23
|
-
|
24
|
-
expect(
|
16
|
+
context "with params" do
|
17
|
+
it "find people by attributte name_equals" do
|
18
|
+
result = client.people.find_all( name_equals: "Myfreecomm", person_type_in: "JuridicalPerson")
|
19
|
+
expect(result).to be_a(Myfinance::Entities::PersonCollection)
|
20
|
+
expect(result.collection.first.name).to eq("Myfreecomm")
|
25
21
|
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "#find_by" do
|
31
|
-
context "with success" do
|
32
|
-
it "find people by attributte name_equals" do
|
33
|
-
result = client.people.find_by(
|
34
|
-
{ name_equals: "Myfreecomm", person_type_in: "JuridicalPerson" }
|
35
|
-
)
|
36
|
-
expect(result).to be_a(Myfinance::Entities::PersonCollection)
|
37
|
-
expect(result.collection.first.name).to eq("Myfreecomm")
|
38
|
-
end
|
39
22
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
23
|
+
it "find people by attributte with special characters" do
|
24
|
+
result = client.people.find_all(name_equals: "João das neves")
|
25
|
+
expect(result).to be_a(Myfinance::Entities::PersonCollection)
|
26
|
+
expect(result.collection.first.name).to eq("João das neves")
|
27
|
+
end
|
45
28
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
29
|
+
it "find people by attributte federation_subscription_number_equals" do
|
30
|
+
result = client.people.find_all(
|
31
|
+
{ federation_subscription_number_equals: "42.308.611/0001-41" }
|
32
|
+
)
|
33
|
+
expect(result).to be_a(Myfinance::Entities::PersonCollection)
|
34
|
+
expect(result.collection.first.name).to eq("Myfreecomm")
|
35
|
+
end
|
36
|
+
context "with error" do
|
37
|
+
let(:client) { Myfinance.client("") }
|
38
|
+
|
39
|
+
it "raises Myfinance::RequestError with 401 status code" do
|
40
|
+
params = { name_equals: "Myfreecomm" }
|
41
|
+
expect { client.people.find_all(params) }.to raise_error(Myfinance::RequestError) do |error|
|
42
|
+
expect(error.code).to eq(401)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
52
46
|
end
|
53
47
|
end
|
48
|
+
end
|
54
49
|
|
55
|
-
|
56
|
-
|
50
|
+
context "when not found" do
|
51
|
+
let(:client) { Myfinance.client("") }
|
57
52
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
}.to raise_error(Myfinance::RequestError) do |error|
|
62
|
-
expect(error.code).to eq(401)
|
63
|
-
end
|
53
|
+
it "raises Myfinance::RequestError with 401 status code" do
|
54
|
+
expect { client.people.find_all }.to raise_error(Myfinance::RequestError) do |error|
|
55
|
+
expect(error.code).to eq(401)
|
64
56
|
end
|
65
57
|
end
|
66
58
|
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.2.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-28 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: typhoeus
|
@@ -376,7 +376,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
376
376
|
version: '0'
|
377
377
|
requirements: []
|
378
378
|
rubyforge_project:
|
379
|
-
rubygems_version: 2.
|
379
|
+
rubygems_version: 2.6.8
|
380
380
|
signing_key:
|
381
381
|
specification_version: 4
|
382
382
|
summary: A Ruby client for the Myfinance REST API
|