cobrato-client 0.2.5 → 0.2.6

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: e40e2ee4e6b8c81d614e07c2fc8e3be6ca5b0bd7
4
- data.tar.gz: c16bb3e90297445a661756fc8e816374675f8985
3
+ metadata.gz: 4bef9a5860ddd105122d08c270505282b31cb9dd
4
+ data.tar.gz: 0e603498630075585c6e7c25ef048cbf2304e078
5
5
  SHA512:
6
- metadata.gz: cdc1675445d868907e632a7e028e9972cec58ab069497606c9fac9c4962ac41c821ca0b0c899d27ecaf21556954cb062d21989b347ea811e31fbf372413e1b2f
7
- data.tar.gz: 735c9456842ecd3fb9997e9abf9958a7933b7008fc1ada49badba2f3fb098ba44ee7b6eb08f6721ed691cfc0f5fbc6ee9cf0f58fc7ef1e1368f470a45af9d3a0
6
+ metadata.gz: 839f391c67316af2c0246e517d73ce754ab22df6dbca3ef04bf1cc801db61b706745a4df5f24fdd657c25c9da08fc23a48f70c2ed4e5ef1aa429cad8ace6e4d1
7
+ data.tar.gz: 7f4fe901803a7448e502d1375599e3ea31e2372d1f95d577248206c2f9fea1fa266e86e45932290d835ad12f0831c87cb8928f5d2409b1b773d40ea11b15cb68
@@ -42,19 +42,19 @@ GEM
42
42
  byebug (~> 5.0)
43
43
  pry (~> 0.10)
44
44
  rake (10.4.2)
45
- rspec (3.3.0)
46
- rspec-core (~> 3.3.0)
47
- rspec-expectations (~> 3.3.0)
48
- rspec-mocks (~> 3.3.0)
49
- rspec-core (3.3.2)
50
- rspec-support (~> 3.3.0)
51
- rspec-expectations (3.3.1)
45
+ rspec (3.4.0)
46
+ rspec-core (~> 3.4.0)
47
+ rspec-expectations (~> 3.4.0)
48
+ rspec-mocks (~> 3.4.0)
49
+ rspec-core (3.4.1)
50
+ rspec-support (~> 3.4.0)
51
+ rspec-expectations (3.4.0)
52
52
  diff-lcs (>= 1.2.0, < 2.0)
53
- rspec-support (~> 3.3.0)
54
- rspec-mocks (3.3.2)
53
+ rspec-support (~> 3.4.0)
54
+ rspec-mocks (3.4.1)
55
55
  diff-lcs (>= 1.2.0, < 2.0)
56
- rspec-support (~> 3.3.0)
57
- rspec-support (3.3.0)
56
+ rspec-support (~> 3.4.0)
57
+ rspec-support (3.4.1)
58
58
  simplecov (0.10.0)
59
59
  docile (~> 1.1.0)
60
60
  json (~> 1.8)
@@ -81,9 +81,9 @@ DEPENDENCIES
81
81
  codeclimate-test-reporter (~> 0.4)
82
82
  pry-byebug (~> 3.1)
83
83
  rake (~> 10.4)
84
- rspec (~> 3.3)
84
+ rspec (~> 3.4)
85
85
  simplecov (~> 0.10)
86
86
  vcr (~> 2.9)
87
87
 
88
88
  BUNDLED WITH
89
- 1.10.6
89
+ 1.11.2
data/README.md CHANGED
@@ -98,7 +98,17 @@ end
98
98
  | POST | [api/v1/charges/:id/receive](http://docs.cobrato.com/#recebimento-de-cobrança) | client.charges.receive |
99
99
  | POST | [api/v1/charges/:id/undo_receive](http://docs.cobrato.com/#desfazer-recebimento-de-cobrança) | client.charges.undo_receive |
100
100
  | POST | [api/v1/charges/:id/deliver_billet](http://docs.cobrato.com/#envio-de-boleto-da-cobrança) | client.charges.deliver_billet |
101
- | GET | [api/v1/charges/:id/billet](http://docs.cobrato.com/#boleto-da-cobrança) | client.charges.billet |
101
+ | GET | [api/v1/charges/:id/billet](http://docs.cobrato.com/#boleto-da-cobrança) | client.charges.billet |
102
+
103
+ #### [Regress Cnab](http://docs.cobrato.com/#cnab-de-retorno)
104
+
105
+ | HTTP method | Endpoint | Client method |
106
+ | ----------- | ------------------------------------------------------------------------------------ | ---------------------------- |
107
+ | POST | [api/v1/regress_cnabs](http://docs.cobrato.com/#criação-de-cnab-de-retorno) | client.regress_cnabs.create |
108
+ | GET | [api/v1/regress_cnabs](http://docs.cobrato.com/#lista-de-todas-as-cnabs-de-retorno) | client.regress_cnabs.list |
109
+ | GET | [api/v1/regress_cnabs/:id](http://docs.cobrato.com/#informações-do-cnab-de-retorno) | client.regress_cnabs.show |
110
+ | DELETE | [api/v1/regress_cnabs/:id](http://docs.cobrato.com/#exclusão-de-cnab-de-retorno) | client.regress_cnabs.destroy |
111
+ | GET | [api/v1/regress_cnabs/:id/file](http://docs.cobrato.com/#arquivo-do-cnab-de-retorno) | client.regress_cnabs.file |
102
112
 
103
113
  #### [Webhooks](http://docs.cobrato.com/#webhook)
104
114
 
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency "rake", "~> 10.4"
36
36
  spec.add_development_dependency 'vcr', '~> 2.9'
37
37
  spec.add_development_dependency 'pry-byebug', '~> 3.1'
38
- spec.add_development_dependency 'rspec', '~> 3.3'
38
+ spec.add_development_dependency 'rspec', '~> 3.4'
39
39
  spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.4'
40
40
  spec.add_development_dependency 'simplecov', '~> 0.10'
41
41
  end
@@ -14,6 +14,7 @@ require "cobrato/entities/charge_account"
14
14
  require "cobrato/entities/charge"
15
15
  require "cobrato/entities/webhook"
16
16
  require "cobrato/entities/bank_billet"
17
+ require "cobrato/entities/regress_cnab"
17
18
 
18
19
  require "cobrato/resources/base"
19
20
  require "cobrato/resources/payee"
@@ -22,6 +23,7 @@ require "cobrato/resources/charge_account"
22
23
  require "cobrato/resources/charge"
23
24
  require "cobrato/resources/webhook"
24
25
  require "cobrato/resources/charging_type"
26
+ require "cobrato/resources/regress_cnab"
25
27
 
26
28
  module Cobrato
27
29
  def self.configuration
@@ -0,0 +1,10 @@
1
+ module Cobrato
2
+ module Entities
3
+ class RegressCnab < Base
4
+ attribute :id, Integer
5
+ attribute :charge_account_id, Integer
6
+ attribute :status, String
7
+ attribute :report, Hash
8
+ end
9
+ end
10
+ end
@@ -1,10 +1,7 @@
1
1
  module Cobrato
2
2
  module Resources
3
3
  class BankAccount < Base
4
-
5
- def collection_name
6
- "bank_accounts"
7
- end
4
+ crud :all
8
5
 
9
6
  def portfolio_codes(id)
10
7
  http.get("#{resource_base_path}/#{id}/portfolio_codes") do |response|
@@ -7,14 +7,18 @@ module Cobrato
7
7
  extend Hooks
8
8
  attr_accessor :http
9
9
 
10
- def collection_name
11
- "#{base_klass.downcase}s"
10
+ def self.crud(*args)
11
+ @crud ||= args
12
12
  end
13
13
 
14
14
  def initialize(http)
15
15
  @http = http
16
16
  end
17
17
 
18
+ def collection_name
19
+ @collection_name ||= "#{base_klass.gsub(/(.)([A-Z])/,'\1_\2').downcase}s"
20
+ end
21
+
18
22
  def parsed_body(response)
19
23
  MultiJson.load(response.body)
20
24
  rescue MultiJson::ParseError
@@ -22,38 +26,57 @@ module Cobrato
22
26
  end
23
27
 
24
28
  def create(params)
25
- http.post(resource_base_path, { body: params }) do |response|
26
- respond_with_entity(response)
29
+ crud_request do
30
+ http.post(resource_base_path, { body: params }) do |response|
31
+ respond_with_entity(response)
32
+ end
27
33
  end
28
34
  end
29
35
 
30
36
  def show(id)
31
- http.get("#{resource_base_path}/#{id}") do |response|
32
- respond_with_entity(response)
37
+ crud_request do
38
+ http.get("#{resource_base_path}/#{id}") do |response|
39
+ respond_with_entity(response)
40
+ end
33
41
  end
34
42
  end
35
43
 
36
44
  def list
37
- http.get(resource_base_path) do |response|
38
- respond_with_collection(response)
45
+ crud_request do
46
+ http.get(resource_base_path) do |response|
47
+ respond_with_collection(response)
48
+ end
39
49
  end
40
50
  end
41
51
 
42
52
  def destroy(id)
43
- http.delete("#{resource_base_path}/#{id}") do |response|
44
- response.code == 204
53
+ crud_request do
54
+ http.delete("#{resource_base_path}/#{id}") do |response|
55
+ response.code == 204
56
+ end
45
57
  end
46
58
  end
47
59
 
48
60
  def update(id, params)
49
- http.put("#{resource_base_path}/#{id}", { body: params }) do |response|
50
- respond_with_entity(response)
61
+ crud_request do
62
+ http.put("#{resource_base_path}/#{id}", { body: params }) do |response|
63
+ respond_with_entity(response)
64
+ end
51
65
  end
52
66
  end
53
67
 
54
68
  notify :create, :destroy
55
69
 
56
70
  protected
71
+ def crud_request
72
+ method = caller_locations(1,1)[0].label
73
+ if self.class.crud.include?(:all) || self.class.crud.include?(method.to_sym)
74
+ yield
75
+ else
76
+ raise raise RuntimeError, "#{base_klass} do not implement the #{method} method"
77
+ end
78
+ end
79
+
57
80
  def respond_with_collection(response, naked_klass = entity_klass)
58
81
  hash = parsed_body(response)
59
82
  hash[collection_name].map do |item|
@@ -66,18 +89,21 @@ module Cobrato
66
89
  naked_klass.new(item)
67
90
  end
68
91
 
92
+ def respond_with_openstruct(response)
93
+ OpenStruct.new(MultiJson.load(response.body))
94
+ end
95
+
69
96
  def resource_base_path
70
97
  @resource_base_path ||= "/#{collection_name}"
71
98
  end
72
99
 
73
100
  def base_klass
74
- @base_klass ||= self.class.name.split("::").last
101
+ @base_klass ||= self.class.name.split('::').last
75
102
  end
76
103
 
77
104
  def entity_klass
78
105
  @entity_klass ||= Cobrato::Entities.const_get(base_klass.to_sym)
79
106
  end
80
-
81
107
  end
82
108
  end
83
109
  end
@@ -1,6 +1,7 @@
1
1
  module Cobrato
2
2
  module Resources
3
3
  class Charge < Base
4
+ crud :all
4
5
 
5
6
  def receive(id, params)
6
7
  http.post("#{resource_base_path}/#{id}/receive", { body: params }) do |response|
@@ -23,12 +24,11 @@ module Cobrato
23
24
 
24
25
  def billet(id)
25
26
  http.get("#{resource_base_path}/#{id}/billet") do |response|
26
- OpenStruct.new(MultiJson.load(response.body))
27
+ respond_with_openstruct response
27
28
  end
28
29
  end
29
30
 
30
31
  notify :receive, :undo_receive
31
-
32
32
  end
33
33
  end
34
34
  end
@@ -1,11 +1,7 @@
1
1
  module Cobrato
2
2
  module Resources
3
3
  class ChargeAccount < Base
4
-
5
- def collection_name
6
- "charge_accounts"
7
- end
8
-
4
+ crud :all
9
5
  end
10
6
  end
11
7
  end
@@ -1,10 +1,7 @@
1
1
  module Cobrato
2
2
  module Resources
3
3
  class ChargingType < Base
4
-
5
- def collection_name
6
- 'charging_types'
7
- end
4
+ crud :all
8
5
 
9
6
  def list
10
7
  http.get(resource_base_path) do |response|
@@ -1,7 +1,7 @@
1
1
  module Cobrato
2
2
  module Resources
3
3
  class Payee < Base
4
-
4
+ crud :all
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,16 @@
1
+ require "cobrato/resources/hooks"
2
+
3
+ module Cobrato
4
+ module Resources
5
+ class RegressCnab < Base
6
+ crud :create, :show, :list, :destroy
7
+
8
+ def file(id)
9
+ http.get("#{resource_base_path}/#{id}/file") do |response|
10
+ respond_with_openstruct(response)
11
+ end
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -1,7 +1,7 @@
1
1
  module Cobrato
2
2
  module Resources
3
3
  class Webhook < Base
4
-
4
+ crud :all
5
5
  end
6
6
  end
7
7
  end
@@ -1,3 +1,3 @@
1
1
  module Cobrato
2
- VERSION = '0.2.5'
2
+ VERSION = '0.2.6'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cobrato-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcio Ricardo Santos
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2016-01-05 00:00:00.000000000 Z
13
+ date: 2016-01-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: typhoeus
@@ -130,14 +130,14 @@ dependencies:
130
130
  requirements:
131
131
  - - "~>"
132
132
  - !ruby/object:Gem::Version
133
- version: '3.3'
133
+ version: '3.4'
134
134
  type: :development
135
135
  prerelease: false
136
136
  version_requirements: !ruby/object:Gem::Requirement
137
137
  requirements:
138
138
  - - "~>"
139
139
  - !ruby/object:Gem::Version
140
- version: '3.3'
140
+ version: '3.4'
141
141
  - !ruby/object:Gem::Dependency
142
142
  name: codeclimate-test-reporter
143
143
  requirement: !ruby/object:Gem::Requirement
@@ -197,6 +197,7 @@ files:
197
197
  - lib/cobrato/entities/charge.rb
198
198
  - lib/cobrato/entities/charge_account.rb
199
199
  - lib/cobrato/entities/payee.rb
200
+ - lib/cobrato/entities/regress_cnab.rb
200
201
  - lib/cobrato/entities/webhook.rb
201
202
  - lib/cobrato/exception.rb
202
203
  - lib/cobrato/http.rb
@@ -208,6 +209,7 @@ files:
208
209
  - lib/cobrato/resources/charging_type.rb
209
210
  - lib/cobrato/resources/hooks.rb
210
211
  - lib/cobrato/resources/payee.rb
212
+ - lib/cobrato/resources/regress_cnab.rb
211
213
  - lib/cobrato/resources/webhook.rb
212
214
  - lib/cobrato/response.rb
213
215
  - lib/cobrato/version.rb