cobrato-client 0.2.7 → 0.2.8

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: d8f28834000086dd2307158da436790e63c5a1e3
4
- data.tar.gz: 88e8a7c41fb8b22a04df0368bb44d7536271dd16
3
+ metadata.gz: a680b8a82eef019c7ea680ed070ea39e922b6f17
4
+ data.tar.gz: 06b9d8ffec6af5b002cc07ddb9ae438aee26ed1d
5
5
  SHA512:
6
- metadata.gz: b964924882d43fc88afad30396d15d8335c768ec16317c4c2cdfbf61fa030a9dc8708c082be626bc434e9b289e23431a85c57c3ef56d6b6df89021ad685ae16b
7
- data.tar.gz: a5812f4209b3dd0bc1eca84704c352725a188ccb8ba704f7ce4ee00eb0da67bfbc8ddc443961cfb6721ff172d6afbb865aeb876635ba9b15a2f0887cbe333358
6
+ metadata.gz: db9806214d747fb5829134037a6806beb94d1aac979eb83eaddf2f879725ac023066a0c6036bfedc55c241682503f42342b3b2a9b05930b28e47b8e0fe61587a
7
+ data.tar.gz: 6633f12d129521ae63ed09a1f798d1106617314ac1baa67f323f7dd62770d80adaa3ef94c08a7c0fe8a2d66f15f26a3a975b4208e3a9e94037f53c014c06fba3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cobrato-client (0.2.5)
4
+ cobrato-client (0.2.8)
5
5
  multi_json (~> 1.11.1)
6
6
  typhoeus (~> 0.7.2)
7
7
  virtus (~> 1.0.5)
data/README.md CHANGED
@@ -51,6 +51,8 @@ end
51
51
  * [Bank Accounts API](http://docs.cobrato.com/#conta-bancária)
52
52
  * [Charge Accounts API](http://docs.cobrato.com/#conta-de-cobrança)
53
53
  * [Charges API](http://docs.cobrato.com/#cobrança)
54
+ * [Regress Cnab](http://docs.cobrato.com/#cnab-de-retorno)
55
+ * [Remittance Cnab](http://docs.cobrato.com/#cnab-de-remessa)
54
56
  * [Webhooks API](http://docs.cobrato.com/#webhook)
55
57
 
56
58
  ## Endpoints
@@ -110,6 +112,17 @@ end
110
112
  | DELETE | [api/v1/regress_cnabs/:id](http://docs.cobrato.com/#exclusão-de-cnab-de-retorno) | client.regress_cnabs.destroy |
111
113
  | GET | [api/v1/regress_cnabs/:id/file](http://docs.cobrato.com/#arquivo-do-cnab-de-retorno) | client.regress_cnabs.file |
112
114
 
115
+ #### [Remittance Cnab](http://docs.cobrato.com/#cnab-de-remessa)
116
+
117
+ | HTTP method | Endpoint | Client method |
118
+ | ----------- | ---------------------------------------------------------------------------------------------------------------- | ------------------------------- |
119
+ | POST | [api/v1/remittance_cnabs](http://docs.cobrato.com/##criação-de-arquivo-cnab-de-remessa) | client.remittance_cnabs.create |
120
+ | GET | [api/v1/remittance_cnabs](http://docs.cobrato.com/#lista-de-todas-as-cnabs-de-remessa) | client.remittance_cnabs.list |
121
+ | GET | [api/v1/remittance_cnabs/:id](http://docs.cobrato.com/#informações-do-cnab-de-remessa) | client.remittance_cnabs.show |
122
+ | DELETE | [api/v1/remittance_cnabs/:id](http://docs.cobrato.com/#exclusão-de-cnab-de-remessa) | client.remittance_cnabs.destroy |
123
+ | GET | [api/v1/remittance_cnabs/:id/file](http://docs.cobrato.com/#arquivo-do-cnab-de-remessa) | client.remittance_cnabs.file |
124
+ | GET | [api/v1/remittance_cnabs/:id/charges](http://docs.cobrato.com/#lista-de-todas-as-cobrança-do-arquivo-de-remessa) | client.remittance_cnabs.charges |
125
+
113
126
  #### [Webhooks](http://docs.cobrato.com/#webhook)
114
127
 
115
128
  | HTTP method | Endpoint | Client method |
data/lib/cobrato.rb CHANGED
@@ -15,6 +15,7 @@ require "cobrato/entities/charge"
15
15
  require "cobrato/entities/webhook"
16
16
  require "cobrato/entities/bank_billet"
17
17
  require "cobrato/entities/regress_cnab"
18
+ require "cobrato/entities/remittance_cnab"
18
19
 
19
20
  require "cobrato/resources/base"
20
21
  require "cobrato/resources/payee"
@@ -24,6 +25,7 @@ require "cobrato/resources/charge"
24
25
  require "cobrato/resources/webhook"
25
26
  require "cobrato/resources/charging_type"
26
27
  require "cobrato/resources/regress_cnab"
28
+ require "cobrato/resources/remittance_cnab"
27
29
 
28
30
  module Cobrato
29
31
  def self.configuration
@@ -0,0 +1,9 @@
1
+ module Cobrato
2
+ module Entities
3
+ class RemittanceCnab < Base
4
+ attribute :id, Integer
5
+ attribute :charge_account_id, Integer
6
+ attribute :status, String
7
+ end
8
+ end
9
+ end
@@ -16,7 +16,7 @@ module Cobrato
16
16
  end
17
17
 
18
18
  def collection_name
19
- @collection_name ||= "#{base_klass.gsub(/(.)([A-Z])/,'\1_\2').downcase}s"
19
+ @collection_name ||= underscore_pluralized(base_klass)
20
20
  end
21
21
 
22
22
  def parsed_body(response)
@@ -77,11 +77,13 @@ module Cobrato
77
77
  end
78
78
  end
79
79
 
80
- def respond_with_collection(response, naked_klass = entity_klass)
81
- hash = parsed_body(response)
82
- hash[collection_name].map do |item|
83
- naked_klass.new(item)
84
- end
80
+ def respond_with_collection(response, class_name = nil)
81
+ class_name ||= base_klass
82
+ naked_klass = entity_klass(class_name)
83
+ hash = parsed_body(response)
84
+ collection_name = underscore_pluralized(class_name)
85
+
86
+ hash[collection_name].map { |item| naked_klass.new(item) }
85
87
  end
86
88
 
87
89
  def respond_with_entity(response, naked_klass = entity_klass)
@@ -101,8 +103,13 @@ module Cobrato
101
103
  @base_klass ||= self.class.name.split('::').last
102
104
  end
103
105
 
104
- def entity_klass
105
- @entity_klass ||= Cobrato::Entities.const_get(base_klass.to_sym)
106
+ def entity_klass(class_name = base_klass)
107
+ @entity_klass ||= Cobrato::Entities.const_get(class_name.to_sym)
108
+ end
109
+
110
+
111
+ def underscore_pluralized(str)
112
+ "#{str.gsub(/(.)([A-Z])/,'\1_\2').downcase}s"
106
113
  end
107
114
  end
108
115
  end
@@ -0,0 +1,28 @@
1
+ require "cobrato/resources/hooks"
2
+
3
+ module Cobrato
4
+ module Resources
5
+ class RemittanceCnab < Base
6
+ crud :show, :list, :destroy
7
+
8
+ def create(params)
9
+ http.post(resource_base_path, { body: params }) do |response|
10
+ respond_with_collection(response)
11
+ end
12
+ end
13
+
14
+ def file(id)
15
+ http.get("#{resource_base_path}/#{id}/file") do |response|
16
+ respond_with_openstruct(response)
17
+ end
18
+ end
19
+
20
+ def charges(id)
21
+ http.get("#{resource_base_path}/#{id}/charges") do |response|
22
+ respond_with_collection(response, 'Charge')
23
+ end
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module Cobrato
2
- VERSION = '0.2.7'
2
+ VERSION = '0.2.8'
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.7
4
+ version: 0.2.8
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-26 00:00:00.000000000 Z
13
+ date: 2016-02-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: typhoeus
@@ -198,6 +198,7 @@ files:
198
198
  - lib/cobrato/entities/charge_account.rb
199
199
  - lib/cobrato/entities/payee.rb
200
200
  - lib/cobrato/entities/regress_cnab.rb
201
+ - lib/cobrato/entities/remittance_cnab.rb
201
202
  - lib/cobrato/entities/webhook.rb
202
203
  - lib/cobrato/exception.rb
203
204
  - lib/cobrato/http.rb
@@ -210,6 +211,7 @@ files:
210
211
  - lib/cobrato/resources/hooks.rb
211
212
  - lib/cobrato/resources/payee.rb
212
213
  - lib/cobrato/resources/regress_cnab.rb
214
+ - lib/cobrato/resources/remittance_cnab.rb
213
215
  - lib/cobrato/resources/webhook.rb
214
216
  - lib/cobrato/response.rb
215
217
  - lib/cobrato/version.rb