myfinance 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -2
- data/.hound.yml +3 -1063
- data/.overcommit.yml +33 -0
- data/.rubocop.yml +19 -1131
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +3 -1
- data/README.md +200 -0
- data/Rakefile +1 -1
- data/bin/rspec +21 -0
- data/lib/myfinance.rb +4 -59
- data/lib/myfinance/client.rb +14 -2
- data/lib/myfinance/configuration.rb +2 -2
- data/lib/myfinance/entities/collection.rb +13 -5
- data/lib/myfinance/entities/sale.rb +32 -0
- data/lib/myfinance/entities/sale_account.rb +18 -0
- data/lib/myfinance/entities/sale_account_collection.rb +13 -0
- data/lib/myfinance/entities/sale_collection.rb +13 -0
- data/lib/myfinance/entities/sale_rule.rb +16 -0
- data/lib/myfinance/entities/sale_rule_collection.rb +13 -0
- data/lib/myfinance/http.rb +10 -11
- data/lib/myfinance/request.rb +2 -3
- data/lib/myfinance/resources/base.rb +1 -1
- data/lib/myfinance/resources/sale.rb +39 -0
- data/lib/myfinance/resources/sale_account.rb +39 -0
- data/lib/myfinance/resources/sale_rule.rb +39 -0
- data/lib/myfinance/response.rb +6 -6
- data/lib/myfinance/version.rb +1 -1
- data/myfinance.gemspec +14 -9
- data/spec/lib/myfinance/client_spec.rb +14 -0
- data/spec/lib/myfinance/entities/sale_account_collection_spec.rb +5 -0
- data/spec/lib/myfinance/entities/sale_account_spec.rb +18 -0
- data/spec/lib/myfinance/entities/sale_collection_spec.rb +5 -0
- data/spec/lib/myfinance/entities/sale_rule_collection_spec.rb +5 -0
- data/spec/lib/myfinance/entities/sale_rule_spec.rb +16 -0
- data/spec/lib/myfinance/entities/sale_spec.rb +32 -0
- data/spec/lib/myfinance/resources/sale_account.spec.rb +124 -0
- data/spec/lib/myfinance/resources/sale_account_spec.rb +116 -0
- data/spec/lib/myfinance/resources/sale_rule_spec.rb +126 -0
- data/spec/lib/myfinance/resources/sale_spec.rb +126 -0
- data/spec/support/shared_examples/entity_collection.rb +21 -0
- data/spec/support/shared_examples/http_request_methods.rb +12 -5
- metadata +51 -3
@@ -0,0 +1,18 @@
|
|
1
|
+
module Myfinance
|
2
|
+
module Entities
|
3
|
+
class SaleAccount < Base
|
4
|
+
attribute :id
|
5
|
+
attribute :name
|
6
|
+
attribute :entity_id
|
7
|
+
attribute :description
|
8
|
+
attribute :provider
|
9
|
+
attribute :payment_methods
|
10
|
+
attribute :category_id
|
11
|
+
attribute :person_id
|
12
|
+
attribute :classification_center_id
|
13
|
+
attribute :custom_classifications
|
14
|
+
attribute :created_at
|
15
|
+
attribute :updated_at
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Myfinance
|
2
|
+
module Entities
|
3
|
+
class SaleAccountCollection < Collection
|
4
|
+
def build_collection
|
5
|
+
response.parsed_body.each do |attributes|
|
6
|
+
collection.push(
|
7
|
+
Myfinance::Entities::SaleAccount.new(attributes["sale_account"])
|
8
|
+
)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Myfinance
|
2
|
+
module Entities
|
3
|
+
class SaleRule < Base
|
4
|
+
attribute :id
|
5
|
+
attribute :sale_account_id
|
6
|
+
attribute :issuer
|
7
|
+
attribute :payment_method
|
8
|
+
attribute :fee_percentage
|
9
|
+
attribute :fixed_fee_amount
|
10
|
+
attribute :days_to_liquidation
|
11
|
+
attribute :weekdays
|
12
|
+
attribute :created_at
|
13
|
+
attribute :updated_at
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Myfinance
|
2
|
+
module Entities
|
3
|
+
class SaleRuleCollection < Collection
|
4
|
+
def build_collection
|
5
|
+
response.parsed_body.each do |attributes|
|
6
|
+
collection.push(
|
7
|
+
Myfinance::Entities::SaleRule.new(attributes["sale_rule"])
|
8
|
+
)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/myfinance/http.rb
CHANGED
@@ -19,17 +19,16 @@ module Myfinance
|
|
19
19
|
private
|
20
20
|
|
21
21
|
def send_request(method, path, options, &block)
|
22
|
-
request
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
response.resolve!(&block)
|
22
|
+
request = Request.new(
|
23
|
+
options.merge!(
|
24
|
+
method: method,
|
25
|
+
token: token,
|
26
|
+
url: "#{Myfinance.configuration.url}#{path}",
|
27
|
+
user_agent: Myfinance.configuration.user_agent,
|
28
|
+
account_id: account_id
|
29
|
+
)
|
30
|
+
)
|
31
|
+
Response.new(request.run).resolve!(&block)
|
33
32
|
end
|
34
33
|
end
|
35
34
|
end
|
data/lib/myfinance/request.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Myfinance
|
2
2
|
class Request
|
3
|
-
|
4
3
|
def initialize(args)
|
5
4
|
@args = args
|
6
5
|
end
|
@@ -26,7 +25,7 @@ module Myfinance
|
|
26
25
|
headers: headers,
|
27
26
|
accept_encoding: "gzip",
|
28
27
|
params_encoding: :rack
|
29
|
-
}.reject { |_k,v| v.nil? }
|
28
|
+
}.reject { |_k, v| v.nil? }
|
30
29
|
end
|
31
30
|
|
32
31
|
def headers
|
@@ -38,7 +37,7 @@ module Myfinance
|
|
38
37
|
"User-Agent" => args[:user_agent],
|
39
38
|
"Authorization" => "Basic #{authorization_hash}",
|
40
39
|
"ACCOUNT_ID" => args[:account_id]
|
41
|
-
}.merge(headers).delete_if { |_,v| v.nil? || v.to_s.empty? }
|
40
|
+
}.merge(headers).delete_if { |_, v| v.nil? || v.to_s.empty? }
|
42
41
|
end
|
43
42
|
|
44
43
|
def body
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Myfinance
|
2
|
+
module Resources
|
3
|
+
class Sale < Base
|
4
|
+
def find_all(entity_id)
|
5
|
+
http.get("/entities/#{entity_id}/sales", body: {}) do |response|
|
6
|
+
respond_with_collection(response)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def find(entity_id, sale_id)
|
11
|
+
path = "/entities/#{entity_id}/sales/#{sale_id}"
|
12
|
+
http.get(path, body: {}) do |response|
|
13
|
+
respond_with_object(response, "sale")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def create(entity_id, params = {})
|
18
|
+
path = "/entities/#{entity_id}/sales/"
|
19
|
+
http.post(path, body: { sale: params }) do |response|
|
20
|
+
respond_with_object(response, "sale")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def update(entity_id, sale_id, params = {})
|
25
|
+
path = "/entities/#{entity_id}/sales/#{sale_id}"
|
26
|
+
http.put(path, body: { sale: params }) do |response|
|
27
|
+
respond_with_object(response, "sale")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def destroy(entity_id, sale_id, params = {})
|
32
|
+
path = "/entities/#{entity_id}/sales/#{sale_id}"
|
33
|
+
http.delete(path, body: { sale: params }) do |response|
|
34
|
+
response
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Myfinance
|
2
|
+
module Resources
|
3
|
+
class SaleAccount < Base
|
4
|
+
def find_all
|
5
|
+
http.get("/sale_accounts", body: {}) do |response|
|
6
|
+
respond_with_collection(response)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def find(sale_account_id)
|
11
|
+
path = "/sale_accounts/#{sale_account_id}"
|
12
|
+
http.get(path, body: {}) do |response|
|
13
|
+
respond_with_object(response, "sale_account")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def create(params = {})
|
18
|
+
path = "/sale_accounts/"
|
19
|
+
http.post(path, body: { sale_account: params }) do |response|
|
20
|
+
respond_with_object(response, "sale_account")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def update(sale_account_id, params = {})
|
25
|
+
path = "/sale_accounts/#{sale_account_id}"
|
26
|
+
http.put(path, body: { sale_account: params }) do |response|
|
27
|
+
respond_with_object(response, "sale_account")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def destroy(sale_account_id, params = {})
|
32
|
+
path = "/sale_accounts/#{sale_account_id}"
|
33
|
+
http.delete(path, body: { sale_account: params }) do |response|
|
34
|
+
response
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Myfinance
|
2
|
+
module Resources
|
3
|
+
class SaleRule < Base
|
4
|
+
def find_all(sale_account_id)
|
5
|
+
http.get("/sale_accounts/#{sale_account_id}/rules", body: {}) do |response|
|
6
|
+
respond_with_collection(response)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def find(sale_account_id, rule_id)
|
11
|
+
path = "/sale_accounts/#{sale_account_id}/rules/#{rule_id}"
|
12
|
+
http.get(path, body: {}) do |response|
|
13
|
+
respond_with_object(response, "sale_rule")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def create(sale_account_id, params = {})
|
18
|
+
path = "/sale_accounts/#{sale_account_id}/rules/"
|
19
|
+
http.post(path, body: { sale_rule: params }) do |response|
|
20
|
+
respond_with_object(response, "sale_rule")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def update(sale_account_id, rule_id, params = {})
|
25
|
+
path = "/sale_accounts/#{sale_account_id}/rules/#{rule_id}"
|
26
|
+
http.put(path, body: { sale_rule: params }) do |response|
|
27
|
+
respond_with_object(response, "sale_rule")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def destroy(sale_account_id, rule_id, params = {})
|
32
|
+
path = "/sale_accounts/#{sale_account_id}/rules/#{rule_id}"
|
33
|
+
http.delete(path, body: { sale_rule: params }) do |response|
|
34
|
+
response
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/myfinance/response.rb
CHANGED
@@ -5,8 +5,7 @@ module Myfinance
|
|
5
5
|
RequestError = Class.new(Exception)
|
6
6
|
|
7
7
|
class Response < SimpleDelegator
|
8
|
-
|
9
|
-
def resolve!(&block)
|
8
|
+
def resolve!
|
10
9
|
if success?
|
11
10
|
block_given? ? yield(self) : self
|
12
11
|
elsif timed_out?
|
@@ -16,9 +15,9 @@ module Myfinance
|
|
16
15
|
end
|
17
16
|
end
|
18
17
|
|
19
|
-
def parsed_body(key=nil)
|
20
|
-
return MultiJson.load(
|
21
|
-
MultiJson.load(
|
18
|
+
def parsed_body(key = nil)
|
19
|
+
return MultiJson.load(body)[key] unless key.nil?
|
20
|
+
MultiJson.load(body)
|
22
21
|
rescue MultiJson::ParseError
|
23
22
|
{}
|
24
23
|
end
|
@@ -30,11 +29,12 @@ module Myfinance
|
|
30
29
|
end
|
31
30
|
|
32
31
|
def error!
|
33
|
-
|
32
|
+
error = RequestError.new(
|
34
33
|
code: code,
|
35
34
|
message: request_error_message,
|
36
35
|
body: parsed_body
|
37
36
|
)
|
37
|
+
raise error
|
38
38
|
end
|
39
39
|
|
40
40
|
def request_error_message
|
data/lib/myfinance/version.rb
CHANGED
data/myfinance.gemspec
CHANGED
@@ -1,24 +1,28 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
3
|
+
require "myfinance/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
6
|
spec.name = "myfinance"
|
8
7
|
spec.version = Myfinance::VERSION
|
9
8
|
spec.authors = ["Eduardo Hertz", "Guilherme Franco", "Rafael B. Tauil", "Rodrigo Tassinari"]
|
10
|
-
spec.email = [
|
11
|
-
|
9
|
+
spec.email = [
|
10
|
+
"eduardohertz@gmail.com",
|
11
|
+
"g.francosilva@gmail.com",
|
12
|
+
"rafael@tauil.com.br",
|
13
|
+
"rodrigo@pittlandia.net"
|
14
|
+
]
|
15
|
+
spec.required_ruby_version = ">= 2.0.0"
|
12
16
|
|
13
17
|
spec.summary = %q{A Ruby client for the Myfinance REST API}
|
14
18
|
spec.description = %q{A Ruby client for the Myfinance REST API: https://app.myfinance.com.br/docs/api}
|
15
19
|
spec.homepage = "https://github.com/myfreecomm/myfinance-client-ruby"
|
16
20
|
spec.license = "MIT"
|
17
21
|
|
18
|
-
# Prevent pushing this gem to RubyGems.org by setting
|
22
|
+
# Prevent pushing this gem to RubyGems.org by setting "allowed_push_host", or
|
19
23
|
# delete this section to allow pushing this gem to any host.
|
20
24
|
if spec.respond_to?(:metadata)
|
21
|
-
spec.metadata[
|
25
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
22
26
|
else
|
23
27
|
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
24
28
|
end
|
@@ -31,8 +35,9 @@ Gem::Specification.new do |spec|
|
|
31
35
|
|
32
36
|
spec.add_dependency "typhoeus", "~> 0.8"
|
33
37
|
spec.add_dependency "multi_json", "~> 1.11"
|
34
|
-
spec.add_dependency "virtus",
|
35
|
-
spec.add_dependency "mime-types",
|
38
|
+
spec.add_dependency "virtus", "~> 1.0.5"
|
39
|
+
spec.add_dependency "mime-types", "~> 2.99"
|
40
|
+
spec.add_dependency "require_all", "~> 1.4.0"
|
36
41
|
|
37
42
|
spec.add_development_dependency "bundler", "~> 1.10"
|
38
43
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -3,6 +3,16 @@ require "spec_helper"
|
|
3
3
|
describe Myfinance::Client do
|
4
4
|
subject { client }
|
5
5
|
|
6
|
+
shared_examples :resource do |method, type|
|
7
|
+
describe "##{method}" do
|
8
|
+
it "instantiates a new #{type}" do
|
9
|
+
allow(type).to receive(:new)
|
10
|
+
subject.send(method)
|
11
|
+
expect(type).to have_received(:new).with(subject.http)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
6
16
|
describe "#initialize" do
|
7
17
|
it "instantiates a new Myfinance::Http object" do
|
8
18
|
expect(Myfinance::Http).to receive(:new).with("abc", nil)
|
@@ -145,4 +155,8 @@ describe Myfinance::Client do
|
|
145
155
|
subject.reconciles
|
146
156
|
end
|
147
157
|
end
|
158
|
+
|
159
|
+
include_examples :resource, :sales, Myfinance::Resources::Sale
|
160
|
+
include_examples :resource, :sale_accounts, Myfinance::Resources::SaleAccount
|
161
|
+
include_examples :resource, :sale_rules, Myfinance::Resources::SaleRule
|
148
162
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Myfinance::Entities::SaleAccount do
|
4
|
+
it_behaves_like "entity_attributes", %i[
|
5
|
+
id
|
6
|
+
name
|
7
|
+
entity_id
|
8
|
+
description
|
9
|
+
provider
|
10
|
+
payment_methods
|
11
|
+
category_id
|
12
|
+
person_id
|
13
|
+
classification_center_id
|
14
|
+
custom_classifications
|
15
|
+
created_at
|
16
|
+
updated_at
|
17
|
+
]
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Myfinance::Entities::SaleRule do
|
4
|
+
it_behaves_like "entity_attributes", %i[
|
5
|
+
id
|
6
|
+
sale_account_id
|
7
|
+
issuer
|
8
|
+
payment_method
|
9
|
+
fee_percentage
|
10
|
+
fixed_fee_amount
|
11
|
+
days_to_liquidation
|
12
|
+
weekdays
|
13
|
+
created_at
|
14
|
+
updated_at
|
15
|
+
]
|
16
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Myfinance::Entities::Sale do
|
4
|
+
it_behaves_like "entity_attributes", %i[
|
5
|
+
id
|
6
|
+
nominal_amount
|
7
|
+
receivable_amount
|
8
|
+
fixed_fee_amount
|
9
|
+
fee_percentage
|
10
|
+
fee_percentage_amount
|
11
|
+
issuer
|
12
|
+
payment_method
|
13
|
+
status
|
14
|
+
summary
|
15
|
+
description
|
16
|
+
observation
|
17
|
+
category_id
|
18
|
+
classification_center_id
|
19
|
+
person_id
|
20
|
+
days_to_liquidation
|
21
|
+
sale_account_id
|
22
|
+
financial_account_id
|
23
|
+
liquidation_week_day
|
24
|
+
estimated_liquidated_at
|
25
|
+
liquidated_at
|
26
|
+
occurred_at
|
27
|
+
confirmed_at
|
28
|
+
created_at
|
29
|
+
updated_at
|
30
|
+
custom_classifications
|
31
|
+
]
|
32
|
+
end
|