cobrato-client 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.8
4
- - 2.2.4
5
- - 2.3.0
3
+ - 2.1.9
4
+ - 2.2.5
5
+ - 2.3.1
6
6
  env:
7
7
  global:
8
8
  # CODECLIMATE_REPO_TOKEN
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.5.0
4
+
5
+ - The `Charge#generate_token ` was removed and `CreditCard#created_as_reusable` was added with the same goal.
6
+ - Add credit_cards#create endpoint
7
+ - Add credit_cards#list endpoint
8
+ - Add credit_cards#show endpoint
9
+ - Add credit_cards#charges endpoint
10
+
3
11
  ## v0.3.0
4
12
 
5
13
  ### Structural changes
@@ -52,4 +60,4 @@ To open the path for new charging methods beyond Bank Billet, we made some struc
52
60
 
53
61
  ### Add `ChargeAccount` attributes:
54
62
 
55
- - `transmission-code`: it is a remittance related attribute only used by billet ChargeConfig for Santander bank
63
+ - `transmission-code`: it is a remittance related attribute only used by billet ChargeConfig for Santander bank
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cobrato-client (0.4.2)
4
+ cobrato-client (0.5.0)
5
5
  multi_json (~> 1.11.1)
6
6
  typhoeus (~> 0.7.2)
7
7
  virtus (~> 1.0.5)
data/README.md CHANGED
@@ -18,15 +18,18 @@ gem 'cobrato-client'
18
18
 
19
19
  And then execute:
20
20
 
21
- $ bundle
21
+ ```
22
+ $ bundle
23
+ ```
22
24
 
23
25
  Or install it yourself as:
24
-
25
- $ gem install cobrato-client
26
+ ```
27
+ $ gem install cobrato-client
28
+ ```
26
29
 
27
30
  ## Configuration
28
31
 
29
- ##### Use Cobrato.configure to setup your environment:
32
+ Use `Cobrato.configure` to setup your environment:
30
33
 
31
34
  ```ruby
32
35
  require "cobrato"
@@ -39,13 +42,13 @@ end
39
42
 
40
43
  ## Usage
41
44
 
42
- ##### Given your token, create an instance of Cobrato::Client, as below:
45
+ Given your token, create an instance of `Cobrato::Client`, as below:
43
46
 
44
47
  ```ruby
45
- client = Cobrato.client("YOUR_TOKEN_HERE")
48
+ client = Cobrato.client("YOUR_TOKEN_HERE")
46
49
  ```
47
50
 
48
- ##### Now you have acess to every API endpoint:
51
+ Now you have acess to every API endpoint:
49
52
 
50
53
  * [Payees API](http://docs.cobrato.com/#beneficiário)
51
54
  * [Bank Accounts API](http://docs.cobrato.com/#conta-bancária)
@@ -54,6 +57,7 @@ end
54
57
  * [Charges API](http://docs.cobrato.com/#cobrança)
55
58
  * [Regress Cnab](http://docs.cobrato.com/#cnab-de-retorno)
56
59
  * [Remittance Cnab](http://docs.cobrato.com/#cnab-de-remessa)
60
+ * [CreditCards API](http://docs.cobrato.com/#cart-o-de-cr-dito)
57
61
  * [Webhooks API](http://docs.cobrato.com/#webhook)
58
62
 
59
63
  ## Endpoints
@@ -135,11 +139,14 @@ end
135
139
  | 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 |
136
140
 
137
141
 
138
- #### [Credit Card](http://docs.cobrato.com/#cartao-de-credito)
142
+ #### [Credit Card](http://docs.cobrato.com/#cart-o-de-cr-dito)
139
143
 
140
- | HTTP method | Endpoint | Client method |
141
- | ----------- | ----------------------------------------------------------------------------------- | ------------------------ |
142
- | GET | [api/v1/credit_cards/:id](http://docs.cobrato.com/#informações-do-cartao-de-credit) | client.credit_cards.show |
144
+ | HTTP method | Endpoint | Client method |
145
+ | ----------- | ---------------------------------------------------------------------------------------------------------------------- | --------------------------- |
146
+ | POST | [api/v1/credit_cards](http://docs.cobrato.com/#cria-o-de-cart-o-de-cr-dito) | client.credit_cards.create |
147
+ | GET | [api/v1/credit_cards](http://docs.cobrato.com/#lista-dos-cart-es-de-cr-dito) | client.credit_cards.list |
148
+ | GET | [api/v1/credit_cards/:id](http://docs.cobrato.com/#informa-es-do-cart-o-de-cr-dito) | client.credit_cards.show |
149
+ | GET | [api/v1/credit_cards/:id/charges](http://docs.cobrato.com/#lista-de-todas-as-cobran-as-feitas-com-o-cart-o-de-cr-dito) | client.credit_cards.charges |
143
150
 
144
151
  #### [Webhooks](http://docs.cobrato.com/#webhook)
145
152
 
@@ -17,6 +17,7 @@ module Cobrato
17
17
  attribute :payer_zipcode, String
18
18
  attribute :payer_city, String
19
19
  attribute :payer_state, String
20
+ attribute :for_homologation, Boolean
20
21
 
21
22
  # billet specifics
22
23
  attribute :due_date, Date
@@ -32,7 +33,6 @@ module Cobrato
32
33
  attribute :received, Boolean
33
34
  attribute :received_amount, Decimal
34
35
  attribute :received_at, Date
35
- attribute :for_homologation, Boolean
36
36
  attribute :registrable, Boolean
37
37
  attribute :registration_status, String
38
38
 
@@ -42,7 +42,6 @@ module Cobrato
42
42
  attribute :soft_descriptor, String
43
43
  attribute :payment_method, String
44
44
  attribute :installments, Integer
45
- attribute :generate_token, Boolean
46
45
  attribute :payment_gateway_status, String
47
46
  attribute :payment_gateway_message, String
48
47
  end
@@ -1,19 +1,21 @@
1
1
  module Cobrato
2
2
  module Entities
3
3
  class CreditCard < Base
4
- attribute :id, Integer
5
- attribute :number, String
6
- attribute :holder_name, String
7
- attribute :unusable, Boolean
8
- attribute :brand, String
9
- attribute :expiration, String
10
- attribute :avs_address, String
11
- attribute :avs_number, String
12
- attribute :avs_complement, String
13
- attribute :avs_district, String
14
- attribute :avs_zipcode, String
15
- attribute :payer_id, Integer
16
- attribute :charge_config_id, Integer
4
+ attribute :id, Integer
5
+ attribute :number, String
6
+ attribute :holder_name, String
7
+ attribute :reusable, Boolean
8
+ attribute :reusability_status, String
9
+ attribute :reusability_error_message, String
10
+ attribute :brand, String
11
+ attribute :expiration, String
12
+ attribute :avs_address, String
13
+ attribute :avs_number, String
14
+ attribute :avs_complement, String
15
+ attribute :avs_district, String
16
+ attribute :avs_zipcode, String
17
+ attribute :payer_id, Integer
18
+ attribute :charge_config_id, Integer
17
19
  end
18
20
  end
19
- end
21
+ end
@@ -27,7 +27,7 @@ module Cobrato
27
27
 
28
28
  def create(params)
29
29
  crud_request do
30
- http.post(resource_base_path, { body: params }) do |response|
30
+ http.post(resource_base_path, body: params) do |response|
31
31
  respond_with_entity(response)
32
32
  end
33
33
  end
@@ -41,9 +41,9 @@ module Cobrato
41
41
  end
42
42
  end
43
43
 
44
- def list
44
+ def list(params={})
45
45
  crud_request do
46
- http.get(resource_base_path) do |response|
46
+ http.get(resource_base_path, params: params) do |response|
47
47
  respond_with_collection(response)
48
48
  end
49
49
  end
@@ -59,7 +59,7 @@ module Cobrato
59
59
 
60
60
  def update(id, params)
61
61
  crud_request do
62
- http.put("#{resource_base_path}/#{id}", { body: params }) do |response|
62
+ http.put("#{resource_base_path}/#{id}", body: params) do |response|
63
63
  respond_with_entity(response)
64
64
  end
65
65
  end
@@ -68,49 +68,50 @@ module Cobrato
68
68
  notify :create, :destroy
69
69
 
70
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
71
+
72
+ def crud_request
73
+ method = caller_locations(1, 1)[0].label
74
+ if self.class.crud.include?(:all) || self.class.crud.include?(method.to_sym)
75
+ yield
76
+ else
77
+ raise "#{base_klass} do not implement the #{method} method"
78
78
  end
79
+ end
79
80
 
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)
81
+ def respond_with_collection(response, class_name=nil)
82
+ class_name ||= base_klass
83
+ naked_klass = entity_klass(class_name)
84
+ hash = parsed_body(response)
85
+ collection_name = underscore_pluralized(class_name)
85
86
 
86
- hash[collection_name].map { |item| naked_klass.new(item) }
87
- end
87
+ hash[collection_name].map { |item| naked_klass.new(item) }
88
+ end
88
89
 
89
- def respond_with_entity(response, naked_klass = entity_klass)
90
- item = parsed_body(response)
91
- naked_klass.new(item)
92
- end
90
+ def respond_with_entity(response, naked_klass=entity_klass)
91
+ item = parsed_body(response)
92
+ naked_klass.new(item)
93
+ end
93
94
 
94
- def respond_with_openstruct(response)
95
- OpenStruct.new(MultiJson.load(response.body))
96
- end
95
+ def respond_with_openstruct(response)
96
+ OpenStruct.new(MultiJson.load(response.body))
97
+ end
97
98
 
98
- def resource_base_path
99
- @resource_base_path ||= "/#{collection_name}"
100
- end
99
+ def resource_base_path
100
+ @resource_base_path ||= "/#{collection_name}"
101
+ end
101
102
 
102
- def base_klass
103
- @base_klass ||= self.class.name.split('::').last
104
- end
103
+ def base_klass
104
+ @base_klass ||= self.class.name.split("::").last
105
+ end
105
106
 
106
- def entity_klass(class_name = base_klass)
107
- @entity_klass ||= Cobrato::Entities.const_get(class_name.to_sym)
108
- end
107
+ def entity_klass(class_name=base_klass)
108
+ @entity_klass ||= Cobrato::Entities.const_get(class_name.to_sym)
109
+ end
109
110
 
110
111
 
111
- def underscore_pluralized(str)
112
- "#{str.gsub(/(.)([A-Z])/,'\1_\2').downcase}s"
113
- end
112
+ def underscore_pluralized(str)
113
+ "#{str.gsub(/(.)([A-Z])/, '\1_\2').downcase}s"
114
+ end
114
115
  end
115
116
  end
116
117
  end
@@ -1,7 +1,13 @@
1
1
  module Cobrato
2
2
  module Resources
3
3
  class CreditCard < Base
4
- crud :show
4
+ crud :show, :create, :list
5
+
6
+ def charges(id, params={})
7
+ http.get("#{resource_base_path}/#{id}/charges", params: params) do |response|
8
+ respond_with_collection(response, "Charge")
9
+ end
10
+ end
5
11
  end
6
12
  end
7
- end
13
+ end
@@ -16,17 +16,17 @@ module Cobrato
16
16
  end
17
17
 
18
18
  private
19
- def timeout!
20
- raise RequestTimeout
21
- end
22
19
 
23
- def error!
24
- raise RequestError.new(
25
- code: code,
26
- message: status_message,
27
- body: (MultiJson.load(body) rescue {})
28
- )
29
- end
20
+ def timeout!
21
+ raise RequestTimeout
22
+ end
30
23
 
24
+ def error!
25
+ raise RequestError.new(
26
+ code: code,
27
+ message: status_message,
28
+ body: (MultiJson.load(body) rescue {})
29
+ )
30
+ end
31
31
  end
32
- end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module Cobrato
2
- VERSION = '0.4.2'
2
+ VERSION = '0.5.0'
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.4.2
4
+ version: 0.5.0
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-06-20 00:00:00.000000000 Z
13
+ date: 2016-06-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: typhoeus
@@ -176,9 +176,11 @@ executables: []
176
176
  extensions: []
177
177
  extra_rdoc_files: []
178
178
  files:
179
+ - ".codeclimate.yml"
179
180
  - ".gitignore"
180
181
  - ".hound.yml"
181
182
  - ".rspec"
183
+ - ".rubocop.yml"
182
184
  - ".travis.yml"
183
185
  - CHANGELOG.md
184
186
  - Gemfile