myfinance 0.3.3 → 0.4.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 +12 -10
- data/README.md +55 -0
- data/lib/myfinance.rb +4 -0
- data/lib/myfinance/client.rb +4 -0
- data/lib/myfinance/entities/attachment.rb +15 -0
- data/lib/myfinance/entities/attachment_collection.rb +14 -0
- data/lib/myfinance/request.rb +6 -3
- data/lib/myfinance/resources/attachment.rb +60 -0
- data/lib/myfinance/version.rb +1 -1
- data/myfinance.gemspec +1 -0
- data/spec/lib/myfinance/client_spec.rb +7 -0
- data/spec/lib/myfinance/entities/attachment_collection_spec.rb +20 -0
- data/spec/lib/myfinance/entities/attachment_spec.rb +11 -0
- data/spec/lib/myfinance/resources/attachment_spec.rb +127 -0
- data/spec/support/attachments/attachment.png +0 -0
- metadata +27 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 424d6b9f9c5e9b92218406695fc5123b74a5eb83
|
4
|
+
data.tar.gz: 590a80f04ef75b7f3d2e8267240cca236a3f14eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12219c212fac0258f999773a8ad9b4ff1c152a9500d3511d390de1e1f369e14c3ed742f5ed9a231981a3bb72892ed4e138f2ded2f88f4cb777d689ad69048055
|
7
|
+
data.tar.gz: 086cc0d0389d02a0aaf8734f3170ea3d5edf6279b566a2f9b607f8e1bf0d8f8dbb31c500812774f9396ce208bd93b71272ecc478eadf0f0a37c85de79165b280
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
myfinance (0.
|
4
|
+
myfinance (0.4.0)
|
5
|
+
mime-types (~> 2.99)
|
5
6
|
multi_json (~> 1.11)
|
6
7
|
typhoeus (~> 0.8)
|
7
8
|
virtus (~> 1.0.5)
|
@@ -15,9 +16,9 @@ GEM
|
|
15
16
|
descendants_tracker (~> 0.0.4)
|
16
17
|
ice_nine (~> 0.11.0)
|
17
18
|
thread_safe (~> 0.3, >= 0.3.1)
|
18
|
-
codeclimate-test-reporter (0.
|
19
|
+
codeclimate-test-reporter (0.5.0)
|
19
20
|
simplecov (>= 0.7.1, < 1.0.0)
|
20
|
-
coderay (1.1.
|
21
|
+
coderay (1.1.1)
|
21
22
|
coercible (1.0.0)
|
22
23
|
descendants_tracker (~> 0.0.1)
|
23
24
|
crack (0.4.3)
|
@@ -27,12 +28,13 @@ GEM
|
|
27
28
|
diff-lcs (1.2.5)
|
28
29
|
docile (1.1.5)
|
29
30
|
equalizer (0.0.11)
|
30
|
-
ethon (0.8.
|
31
|
+
ethon (0.8.1)
|
31
32
|
ffi (>= 1.3.0)
|
32
33
|
ffi (1.9.10)
|
33
|
-
ice_nine (0.11.
|
34
|
+
ice_nine (0.11.2)
|
34
35
|
json (1.8.3)
|
35
36
|
method_source (0.8.2)
|
37
|
+
mime-types (2.99.1)
|
36
38
|
multi_json (1.11.2)
|
37
39
|
pry (0.10.3)
|
38
40
|
coderay (~> 1.1.0)
|
@@ -40,22 +42,22 @@ GEM
|
|
40
42
|
slop (~> 3.4)
|
41
43
|
pry-nav (0.2.4)
|
42
44
|
pry (>= 0.9.10, < 0.11.0)
|
43
|
-
rake (10.
|
45
|
+
rake (10.5.0)
|
44
46
|
rspec (3.4.0)
|
45
47
|
rspec-core (~> 3.4.0)
|
46
48
|
rspec-expectations (~> 3.4.0)
|
47
49
|
rspec-mocks (~> 3.4.0)
|
48
|
-
rspec-core (3.4.
|
50
|
+
rspec-core (3.4.3)
|
49
51
|
rspec-support (~> 3.4.0)
|
50
52
|
rspec-expectations (3.4.0)
|
51
53
|
diff-lcs (>= 1.2.0, < 2.0)
|
52
54
|
rspec-support (~> 3.4.0)
|
53
|
-
rspec-mocks (3.4.
|
55
|
+
rspec-mocks (3.4.1)
|
54
56
|
diff-lcs (>= 1.2.0, < 2.0)
|
55
57
|
rspec-support (~> 3.4.0)
|
56
58
|
rspec-support (3.4.1)
|
57
59
|
safe_yaml (1.0.4)
|
58
|
-
simplecov (0.11.
|
60
|
+
simplecov (0.11.2)
|
59
61
|
docile (~> 1.1.0)
|
60
62
|
json (~> 1.8)
|
61
63
|
simplecov-html (~> 0.10.0)
|
@@ -91,4 +93,4 @@ DEPENDENCIES
|
|
91
93
|
webmock (~> 1.9.3)
|
92
94
|
|
93
95
|
BUNDLED WITH
|
94
|
-
1.
|
96
|
+
1.11.2
|
data/README.md
CHANGED
@@ -38,6 +38,7 @@ client = Myfinance.client("YOUR_TOKEN_HERE")
|
|
38
38
|
* [Entities API](https://app.myfinance.com.br/docs/api/entities) as `client.entities`
|
39
39
|
* [PayableAccounts API](https://app.myfinance.com.br/docs/api/payable_accounts) as `client.payable_accounts`
|
40
40
|
* [ReceivableAccounts API](https://app.myfinance.com.br/docs/api/receivable_accounts) as `client.receivable_accounts`
|
41
|
+
* [Attachments API](https://app.myfinance.com.br/docs/api/attachments) as `client.attachments`
|
41
42
|
|
42
43
|
### Endpoints
|
43
44
|
|
@@ -203,6 +204,60 @@ client = Myfinance.client("YOUR_TOKEN_HERE")
|
|
203
204
|
</tr>
|
204
205
|
</table>
|
205
206
|
|
207
|
+
#### [Attachments](https://app.myfinance.com.br/docs/api/attachments)
|
208
|
+
|
209
|
+
<table>
|
210
|
+
<tr>
|
211
|
+
<th>HTTP method</th>
|
212
|
+
<th>Endpoint</th>
|
213
|
+
<th>Client method</th>
|
214
|
+
</tr>
|
215
|
+
<tr>
|
216
|
+
<td><code>GET</code></td>
|
217
|
+
<td>
|
218
|
+
<a href="https://app.myfinance.com.br/docs/api/attachments#get_index" target="_blank">
|
219
|
+
/entities/:entity_id/attachments
|
220
|
+
</a>
|
221
|
+
</td>
|
222
|
+
<td>
|
223
|
+
<code>client.attachments.find_all</code>
|
224
|
+
</td>
|
225
|
+
</tr>
|
226
|
+
<tr>
|
227
|
+
<td><code>GET</code></td>
|
228
|
+
<td>
|
229
|
+
<a href="https://app.myfinance.com.br/docs/api/attachments#get_show" target="_blank">
|
230
|
+
/entities/:entity_id/attachments/:id
|
231
|
+
</a>
|
232
|
+
</td>
|
233
|
+
<td>
|
234
|
+
<code>client.attachments.find</code>
|
235
|
+
</td>
|
236
|
+
</tr>
|
237
|
+
<tr>
|
238
|
+
<td><code>POST</code></td>
|
239
|
+
<td>
|
240
|
+
<a href="https://app.myfinance.com.br/docs/api/attachments#post_create" target="_blank">
|
241
|
+
/entities/:entity_id/attachments
|
242
|
+
</a>
|
243
|
+
</td>
|
244
|
+
<td>
|
245
|
+
<code>client.attachments.create</code>
|
246
|
+
</td>
|
247
|
+
</tr>
|
248
|
+
<tr>
|
249
|
+
<td><code>DELETE</code></td>
|
250
|
+
<td>
|
251
|
+
<a href="https://app.myfinance.com.br/docs/api/attachments#delete_destroy" target="_blank">
|
252
|
+
/entities/:entity_id/attachments/:id
|
253
|
+
</a>
|
254
|
+
</td>
|
255
|
+
<td>
|
256
|
+
<code>client.attachments.destroy</code>
|
257
|
+
</td>
|
258
|
+
</tr>
|
259
|
+
</table>
|
260
|
+
|
206
261
|
### Configuration
|
207
262
|
|
208
263
|
```ruby
|
data/lib/myfinance.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "typhoeus"
|
2
2
|
require "multi_json"
|
3
|
+
require 'mime/types'
|
3
4
|
|
4
5
|
require "myfinance/version"
|
5
6
|
require "myfinance/configuration"
|
@@ -10,15 +11,18 @@ require "myfinance/entities/base"
|
|
10
11
|
require "myfinance/entities/collection"
|
11
12
|
require "myfinance/entities/entity"
|
12
13
|
require "myfinance/entities/entity_collection"
|
14
|
+
require "myfinance/entities/attachment_collection"
|
13
15
|
require "myfinance/entities/financial_account"
|
14
16
|
require "myfinance/entities/payable_account"
|
15
17
|
require "myfinance/entities/receivable_account"
|
18
|
+
require "myfinance/entities/attachment"
|
16
19
|
|
17
20
|
require "myfinance/resources/base"
|
18
21
|
require "myfinance/resources/entity"
|
19
22
|
require "myfinance/resources/financial_account"
|
20
23
|
require "myfinance/resources/payable_account"
|
21
24
|
require "myfinance/resources/receivable_account"
|
25
|
+
require "myfinance/resources/attachment"
|
22
26
|
|
23
27
|
module Myfinance
|
24
28
|
def self.configuration
|
data/lib/myfinance/client.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Myfinance
|
2
|
+
module Entities
|
3
|
+
class Attachment < Base
|
4
|
+
[:id, :entity_id, :attachment_file_size].each { |k| attribute k, Integer }
|
5
|
+
|
6
|
+
[:title, :attachment_file_name, :download_url,
|
7
|
+
:attachment_content_type].each { |k| attribute k, String }
|
8
|
+
|
9
|
+
[:created_at, :updated_at].each { |k| attribute k, DateTime }
|
10
|
+
|
11
|
+
attribute :attachables, Array[Hash]
|
12
|
+
attribute :links, Array[Hash[String => String]]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Myfinance
|
2
|
+
module Entities
|
3
|
+
#
|
4
|
+
# A wrapper to Myfinance attachments collection
|
5
|
+
#
|
6
|
+
class AttachmentCollection < Collection
|
7
|
+
def build_collection
|
8
|
+
response.parsed_body.each do |attributes|
|
9
|
+
collection.push(Myfinance::Entities::Attachment.new(attributes['attachment']))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/myfinance/request.rb
CHANGED
@@ -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
|
@@ -33,7 +33,7 @@ module Myfinance
|
|
33
33
|
|
34
34
|
{
|
35
35
|
"Accept" => "application/json",
|
36
|
-
"Content-Type" =>
|
36
|
+
"Content-Type" => content_type,
|
37
37
|
"User-Agent" => args[:user_agent],
|
38
38
|
"Authorization" => "Basic #{authorization_hash}",
|
39
39
|
"ACCOUNT_ID" => args[:account_id]
|
@@ -42,7 +42,7 @@ module Myfinance
|
|
42
42
|
|
43
43
|
def body
|
44
44
|
body = args[:body]
|
45
|
-
body = MultiJson.dump(body) if body.is_a?(Hash)
|
45
|
+
body = MultiJson.dump(body) if body.is_a?(Hash) && !args[:multipart]
|
46
46
|
body
|
47
47
|
end
|
48
48
|
|
@@ -50,5 +50,8 @@ module Myfinance
|
|
50
50
|
::Base64.strict_encode64("#{args[:token]}:X")
|
51
51
|
end
|
52
52
|
|
53
|
+
def content_type
|
54
|
+
args[:multipart] ? nil : "application/json"
|
55
|
+
end
|
53
56
|
end
|
54
57
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Myfinance
|
2
|
+
module Resources
|
3
|
+
class Attachment < Base
|
4
|
+
#
|
5
|
+
# List all attachments of the entity
|
6
|
+
#
|
7
|
+
# [API]
|
8
|
+
# Method: <tt>GET /entities/:entity_id/attachments</tt>
|
9
|
+
#
|
10
|
+
# Documentation: https://sandbox.myfinance.com.br/docs/api/attachments#get_index
|
11
|
+
#
|
12
|
+
def find_all(entity_id, params = { page: 1 })
|
13
|
+
http.get("/entities/#{entity_id}/attachments", body: params) do |response|
|
14
|
+
respond_with_collection(response)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
19
|
+
# Show attachment details
|
20
|
+
#
|
21
|
+
# [API]
|
22
|
+
# Method: <tt>GET /entities/:entity_id/attachments/:id</tt>
|
23
|
+
#
|
24
|
+
# Documentation: https://sandbox.myfinance.com.br/docs/api/attachments#get_show
|
25
|
+
#
|
26
|
+
def find(entity_id, attachment_id)
|
27
|
+
http.get("/entities/#{entity_id}/attachments/#{attachment_id}") do |response|
|
28
|
+
respond_with_object(response, 'attachment')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# Create an attachment
|
34
|
+
#
|
35
|
+
# [API]
|
36
|
+
# Method: <tt>POST /entities/:entity_id/attachments</tt>
|
37
|
+
#
|
38
|
+
# Documentation: https://sandbox.myfinance.com.br/docs/api/attachments#post_create
|
39
|
+
#
|
40
|
+
def create(entity_id, file, params = {})
|
41
|
+
params.merge!(attachment: file)
|
42
|
+
http.post("/entities/#{entity_id}/attachments", { body: { attachment: params }, multipart: true }) do |response|
|
43
|
+
respond_with_object(response, 'attachment')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Destroy an attachment
|
49
|
+
#
|
50
|
+
# [API]
|
51
|
+
# Method: <tt>DELETE /entities/:entity_id/attachments/:attachment_id</tt>
|
52
|
+
#
|
53
|
+
# Documentation: https://sandbox.myfinance.com.br/docs/api/attachments#delete_destroy
|
54
|
+
#
|
55
|
+
def destroy(entity_id, attachment_id)
|
56
|
+
http.delete("/entities/#{entity_id}/attachments/#{attachment_id}")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/myfinance/version.rb
CHANGED
data/myfinance.gemspec
CHANGED
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_dependency "typhoeus", "~> 0.8"
|
33
33
|
spec.add_dependency "multi_json", "~> 1.11"
|
34
34
|
spec.add_dependency "virtus", '~> 1.0.5'
|
35
|
+
spec.add_dependency "mime-types", '~> 2.99'
|
35
36
|
|
36
37
|
spec.add_development_dependency "bundler", "~> 1.10"
|
37
38
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -53,4 +53,11 @@ describe Myfinance::Client do
|
|
53
53
|
subject.receivable_accounts
|
54
54
|
end
|
55
55
|
end
|
56
|
+
|
57
|
+
describe "#attachments" do
|
58
|
+
it "instantiates a new Myfinance::Resources::Attachment" do
|
59
|
+
expect(Myfinance::Resources::Attachment).to receive(:new).with(subject.http)
|
60
|
+
subject.attachments
|
61
|
+
end
|
62
|
+
end
|
56
63
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Myfinance::Entities::AttachmentCollection do
|
4
|
+
let(:response) { double(headers: { "Link" => "<https://sandbox.myfinance.com.br/entities?page=3>; rel=next, <http://https://sandbox.myfinance.com.br/entities?page=1>; rel=prev, <http://https://sandbox.myfinance.com.br/entities?page=3>; rel=last, <http://https://sandbox.myfinance.com.br/entities?page=1>; rel=first" },
|
5
|
+
parsed_body: [{"attachment" => {"id" => 12,"entity_id" => 1,"title" => "","attachment_file_name" => "extratoPoup.ofx","attachment_content_type" => "application/octet-stream","attachment_file_size" => 5517,"created_at" => "2011-11-10T15:52:59-02:00","updated_at" => "2011-11-10T15:52:59-02:00","download_url" => "https://app.myfinance.com.br/entities/1/attachments/12/download","attachables" => [],"links" => []}}]) }
|
6
|
+
|
7
|
+
subject { Myfinance::Entities::AttachmentCollection.new(response) }
|
8
|
+
|
9
|
+
describe '#build' do
|
10
|
+
it 'returns order collection' do
|
11
|
+
expect(subject.build.class).to eq(Myfinance::Entities::AttachmentCollection)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns orders" do
|
15
|
+
subject.build
|
16
|
+
expect(subject.collection.count).to eq(1)
|
17
|
+
expect(subject.collection.first.class).to eq(Myfinance::Entities::Attachment)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Myfinance::Entities::Attachment do
|
4
|
+
subject { described_class.new({}) }
|
5
|
+
|
6
|
+
it_behaves_like "entity_attributes", [
|
7
|
+
:id, :entity_id, :attachment_file_size, :created_at, :updated_at,
|
8
|
+
:title, :attachment_file_name, :download_url, :attachment_content_type,
|
9
|
+
:attachables, :links
|
10
|
+
]
|
11
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Myfinance::Resources::Attachment, vcr: true do
|
4
|
+
let!(:entity_id) { 3798 }
|
5
|
+
let(:file) { File.open('spec/support/attachments/attachment.png', 'r') }
|
6
|
+
|
7
|
+
describe "#find_all" do
|
8
|
+
context "when success" do
|
9
|
+
subject { client.attachments.find_all(3798) }
|
10
|
+
|
11
|
+
it "returns a list of attachments" do
|
12
|
+
expect(subject.class).to eq(Myfinance::Entities::AttachmentCollection)
|
13
|
+
expect(subject.collection.count).to eq(2)
|
14
|
+
expect(subject.collection.first.class).to eq(Myfinance::Entities::Attachment)
|
15
|
+
expect(subject.collection.first.id).to eq(1305)
|
16
|
+
expect(subject.collection.first.attachment_content_type).to eq("application/octet-stream")
|
17
|
+
expect(subject.collection.first.attachment_file_name).to eq("Mensalidade_MyFinance_15-07-2015.oxps")
|
18
|
+
expect(subject.collection.first.attachment_file_size).to eq(135328)
|
19
|
+
expect(subject.collection.first.download_url).to eq("https://sandbox.myfinance.com.br/entities/3798/attachments/1305/download")
|
20
|
+
expect(subject.collection.first.title).to be_nil
|
21
|
+
expect(subject.collection.first.created_at).to eq(DateTime.parse("2015-11-11T11:04:15-02:00"))
|
22
|
+
expect(subject.collection.first.updated_at).to eq(DateTime.parse("2015-11-11T11:04:15-02:00"))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when not found" do
|
27
|
+
let(:client) { Myfinance.client('') }
|
28
|
+
subject { client.attachments.find_all(3798) }
|
29
|
+
|
30
|
+
it "raises NotFound" do
|
31
|
+
expect{ subject }.to raise_error(Myfinance::RequestError)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#find" do
|
37
|
+
context "when success" do
|
38
|
+
subject { client.attachments.find(3798, 1305) }
|
39
|
+
|
40
|
+
it "returns a list of attachments" do
|
41
|
+
expect(subject.class).to eq(Myfinance::Entities::Attachment)
|
42
|
+
expect(subject.class).to eq(Myfinance::Entities::Attachment)
|
43
|
+
expect(subject.id).to eq(1305)
|
44
|
+
expect(subject.attachment_content_type).to eq("application/octet-stream")
|
45
|
+
expect(subject.attachment_file_name).to eq("Mensalidade_MyFinance_15-07-2015.oxps")
|
46
|
+
expect(subject.attachment_file_size).to eq(135328)
|
47
|
+
expect(subject.download_url).to eq("https://sandbox.myfinance.com.br/entities/3798/attachments/1305/download")
|
48
|
+
expect(subject.title).to be_nil
|
49
|
+
expect(subject.created_at).to eq(DateTime.parse("2015-11-11T11:04:15-02:00"))
|
50
|
+
expect(subject.updated_at).to eq(DateTime.parse("2015-11-11T11:04:15-02:00"))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "when not found" do
|
55
|
+
let(:client) { Myfinance.client('') }
|
56
|
+
subject { client.attachments.find(3798, 1305) }
|
57
|
+
|
58
|
+
it "raises NotFound" do
|
59
|
+
expect{ subject }.to raise_error(Myfinance::RequestError)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#create" do
|
65
|
+
let(:params) { { title: 'My first attachment' } }
|
66
|
+
subject { client.attachments.create(entity_id, file, params) }
|
67
|
+
|
68
|
+
context "with success" do
|
69
|
+
it "creates a new object" do
|
70
|
+
expect(subject.id).to eq(1585)
|
71
|
+
expect(subject.entity_id).to eq(entity_id)
|
72
|
+
expect(subject.attachment_file_size).to eq(6115)
|
73
|
+
expect(subject.title).to eq(params[:title])
|
74
|
+
expect(subject.attachment_file_name).to eq('attachment.png')
|
75
|
+
expect(subject.download_url).to eq("https://sandbox.myfinance.com.br/entities/3798/attachments/1585/download")
|
76
|
+
expect(subject.attachment_content_type).to eq("image/png")
|
77
|
+
expect(subject.created_at).to eq(DateTime.parse("2016-03-01T15:42:30-03:00"))
|
78
|
+
expect(subject.updated_at).to eq(DateTime.parse("2016-03-01T15:42:30-03:00"))
|
79
|
+
expect(subject.attachables).to be_empty
|
80
|
+
expect(subject.links).to eq([{ "rel" => "self", "href" => "https://sandbox.myfinance.com.br/entities/3798/attachments/1585", "method" => "get" }, { "rel" => "download", "href" => "https://sandbox.myfinance.com.br/entities/3798/attachments/1585/download", "method" => "get" }])
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "when any data is invalid" do
|
85
|
+
subject { client.attachments.create(entity_id, nil, params) }
|
86
|
+
|
87
|
+
it "raises Myfinance::RequestError" do
|
88
|
+
expect { subject }.to raise_error(Myfinance::RequestError)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "adds information on request error object" do
|
92
|
+
expect(Myfinance::RequestError).to receive(:new).with(code: 422, message: "Unprocessable Entity", body: { "attachment" => ["não pode ser vazio."] }).and_call_original
|
93
|
+
expect { subject }.to raise_error(Myfinance::RequestError)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "when entity does not exist" do
|
98
|
+
subject { client.attachments.create(0, file, params) }
|
99
|
+
|
100
|
+
it "raises Myfinance::RequestError" do
|
101
|
+
expect { subject }.to raise_error(Myfinance::RequestError)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "adds information on request error object" do
|
105
|
+
expect(Myfinance::RequestError).to receive(:new).with(code: 403, message: "Forbidden", body: {"error" => "Você não tem permissão para acessar este recurso." }).and_call_original
|
106
|
+
expect { subject }.to raise_error(Myfinance::RequestError)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "#destroy", vcr: true do
|
112
|
+
let(:attachment_id) { 1585 }
|
113
|
+
subject { client.attachments.destroy(entity_id, attachment_id) }
|
114
|
+
|
115
|
+
context "when attachment exists" do
|
116
|
+
it { expect(subject.code).to eq(200) }
|
117
|
+
end
|
118
|
+
|
119
|
+
context "when payable account does not exist" do
|
120
|
+
subject { client.attachments.destroy(entity_id, attachment_id) }
|
121
|
+
|
122
|
+
it "raises request error" do
|
123
|
+
expect { subject }.to raise_error(Myfinance::RequestError)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
Binary file
|
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.
|
4
|
+
version: 0.4.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:
|
14
|
+
date: 2016-03-03 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: typhoeus
|
@@ -55,6 +55,20 @@ dependencies:
|
|
55
55
|
- - "~>"
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
version: 1.0.5
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: mime-types
|
60
|
+
requirement: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - "~>"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '2.99'
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '2.99'
|
58
72
|
- !ruby/object:Gem::Dependency
|
59
73
|
name: bundler
|
60
74
|
requirement: !ruby/object:Gem::Requirement
|
@@ -222,6 +236,8 @@ files:
|
|
222
236
|
- lib/myfinance.rb
|
223
237
|
- lib/myfinance/client.rb
|
224
238
|
- lib/myfinance/configuration.rb
|
239
|
+
- lib/myfinance/entities/attachment.rb
|
240
|
+
- lib/myfinance/entities/attachment_collection.rb
|
225
241
|
- lib/myfinance/entities/base.rb
|
226
242
|
- lib/myfinance/entities/collection.rb
|
227
243
|
- lib/myfinance/entities/entity.rb
|
@@ -232,6 +248,7 @@ files:
|
|
232
248
|
- lib/myfinance/exception.rb
|
233
249
|
- lib/myfinance/http.rb
|
234
250
|
- lib/myfinance/request.rb
|
251
|
+
- lib/myfinance/resources/attachment.rb
|
235
252
|
- lib/myfinance/resources/base.rb
|
236
253
|
- lib/myfinance/resources/entity.rb
|
237
254
|
- lib/myfinance/resources/financial_account.rb
|
@@ -242,6 +259,8 @@ files:
|
|
242
259
|
- myfinance.gemspec
|
243
260
|
- spec/lib/myfinance/client_spec.rb
|
244
261
|
- spec/lib/myfinance/configuration_spec.rb
|
262
|
+
- spec/lib/myfinance/entities/attachment_collection_spec.rb
|
263
|
+
- spec/lib/myfinance/entities/attachment_spec.rb
|
245
264
|
- spec/lib/myfinance/entities/base_spec.rb
|
246
265
|
- spec/lib/myfinance/entities/collection_spec.rb
|
247
266
|
- spec/lib/myfinance/entities/entity_collection_spec.rb
|
@@ -250,12 +269,14 @@ files:
|
|
250
269
|
- spec/lib/myfinance/entities/receivable_account_spec.rb
|
251
270
|
- spec/lib/myfinance/http_spec.rb
|
252
271
|
- spec/lib/myfinance/request_spec.rb
|
272
|
+
- spec/lib/myfinance/resources/attachment_spec.rb
|
253
273
|
- spec/lib/myfinance/resources/entity_spec.rb
|
254
274
|
- spec/lib/myfinance/resources/payable_account_spec.rb
|
255
275
|
- spec/lib/myfinance/resources/receivable_account_spec.rb
|
256
276
|
- spec/lib/myfinance/response_spec.rb
|
257
277
|
- spec/lib/myfinance_spec.rb
|
258
278
|
- spec/spec_helper.rb
|
279
|
+
- spec/support/attachments/attachment.png
|
259
280
|
- spec/support/client.rb
|
260
281
|
- spec/support/matchers/have_attr_accessor.rb
|
261
282
|
- spec/support/shared_examples/entity_attributes.rb
|
@@ -289,6 +310,8 @@ summary: A Ruby client for the Myfinance REST API
|
|
289
310
|
test_files:
|
290
311
|
- spec/lib/myfinance/client_spec.rb
|
291
312
|
- spec/lib/myfinance/configuration_spec.rb
|
313
|
+
- spec/lib/myfinance/entities/attachment_collection_spec.rb
|
314
|
+
- spec/lib/myfinance/entities/attachment_spec.rb
|
292
315
|
- spec/lib/myfinance/entities/base_spec.rb
|
293
316
|
- spec/lib/myfinance/entities/collection_spec.rb
|
294
317
|
- spec/lib/myfinance/entities/entity_collection_spec.rb
|
@@ -297,12 +320,14 @@ test_files:
|
|
297
320
|
- spec/lib/myfinance/entities/receivable_account_spec.rb
|
298
321
|
- spec/lib/myfinance/http_spec.rb
|
299
322
|
- spec/lib/myfinance/request_spec.rb
|
323
|
+
- spec/lib/myfinance/resources/attachment_spec.rb
|
300
324
|
- spec/lib/myfinance/resources/entity_spec.rb
|
301
325
|
- spec/lib/myfinance/resources/payable_account_spec.rb
|
302
326
|
- spec/lib/myfinance/resources/receivable_account_spec.rb
|
303
327
|
- spec/lib/myfinance/response_spec.rb
|
304
328
|
- spec/lib/myfinance_spec.rb
|
305
329
|
- spec/spec_helper.rb
|
330
|
+
- spec/support/attachments/attachment.png
|
306
331
|
- spec/support/client.rb
|
307
332
|
- spec/support/matchers/have_attr_accessor.rb
|
308
333
|
- spec/support/shared_examples/entity_attributes.rb
|