pagarme 2.1.3 → 2.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32435bc6f31cb6c994fb5cf1c179085fc24b27f0
4
- data.tar.gz: b6dc35d91784e87fb4681693fd0e2ee06311ba1e
3
+ metadata.gz: 578deddbc00fc81efa0bfd3bc0c2d76503346933
4
+ data.tar.gz: c1448b5d1f4d746bd67e3c1718b75fecf524194d
5
5
  SHA512:
6
- metadata.gz: a8497647fc3b90c9bf2a7e7e603a680f83b687dd0e48d603695034bb4ffed4fd8190d89334b78a2396383d1ab7f61a19d580215388db11fb2180a93aacbffa62
7
- data.tar.gz: a1b0e5a51306c35352599434001552aa4e8c83572f72110dc83afeec96153d27cdd890e38249a359a0477fa9d4e9144ad837168684a4e3cfd5c2456ee5b82ca2
6
+ metadata.gz: 683f3c56c311fc53eedc8bf3888e8a48daf08aa6210e01146d707d06c0fa9f33f13cd6131a2f28d3b71a31a4cea1510c9195854d7dbee60da7ee130dd99b1a13
7
+ data.tar.gz: 80585f459e4bd2dee596ad344a6004b12d36961ba7488897b5a979cf778fd7875309500a29798886d3ad21a5afa3d0bfaebb458db91f7af561e33485e8a1202b
@@ -31,4 +31,11 @@ module PagarMe
31
31
  def self.validate_fingerprint(*args)
32
32
  raise '[Deprecation Error] PagarMe.validate_fingerprint is deprecated, use PagarMe::Postback.valid_request_signature? instead'
33
33
  end
34
+
35
+ def self.production?
36
+ ENV['RACK_ENV'] == 'production' ||
37
+ ENV['RAILS_ENV'] == 'production' ||
38
+ ENV['PRODUCTION'] ||
39
+ ENV['production']
40
+ end
34
41
  end
@@ -42,6 +42,10 @@ module PagarMe
42
42
  end
43
43
  super @errors.map(&:message).join(', ')
44
44
  end
45
+
46
+ def to_h
47
+ @errors.map(&:to_h)
48
+ end
45
49
  end
46
50
 
47
51
  class ParamError < PagarMeError
@@ -51,5 +55,9 @@ module PagarMe
51
55
  @parameter_name, @type, @url = parameter_name, type, url
52
56
  super message
53
57
  end
58
+
59
+ def to_h
60
+ { parameter_name: parameter_name , type: type , message: message }
61
+ end
54
62
  end
55
63
  end
@@ -28,19 +28,19 @@ module PagarMe
28
28
  end
29
29
  alias :find :find_by_id
30
30
 
31
- def find_by(hash, page = 1, count = 10)
32
- raise RequestError.new('Invalid page count') if page < 1 or count < 1
31
+ def find_by(params = Hash.new, page = nil, count = nil)
32
+ params = extract_page_count_or_params(page, count, **params)
33
+ raise RequestError.new('Invalid page count') if params[:page] < 1 or params[:count] < 1
33
34
 
34
- PagarMe::Request.get(url, params: hash.merge(
35
- page: page,
36
- count: count
37
- )).call
35
+ PagarMe::Request.get(url, params: params).call
38
36
  end
39
37
  alias :find_by_hash :find_by
40
38
 
41
- def all(page = 1, count = 10)
42
- find_by Hash.new, page, count
39
+ def all(*args, **params)
40
+ params = extract_page_count_or_params(*args, **params)
41
+ find_by params
43
42
  end
43
+ alias :where :all
44
44
 
45
45
  def url(*params)
46
46
  ["/#{ CGI.escape underscored_class_name }s", *params].join '/'
@@ -54,6 +54,12 @@ module PagarMe
54
54
  class_name.gsub(/[a-z0-9][A-Z]/){|s| "#{s[0]}_#{s[1]}"}.downcase
55
55
  end
56
56
 
57
+ def extract_page_count_or_params(*args, **params)
58
+ params[:page] ||= args[0] || 1
59
+ params[:count] ||= args[1] || 10
60
+ params
61
+ end
62
+
57
63
  end
58
64
  end
59
65
  end
@@ -36,21 +36,20 @@ module PagarMe
36
36
  end
37
37
  alias :find :find_by_id
38
38
 
39
- def find_by(parent_id, hash, page = 1, count = 10)
40
- raise RequestError.new('Invalid page count') if page < 1 or count < 1
39
+ def find_by(parent_id, params = Hash.new, page = nil, count = nil)
40
+ params = extract_page_count_or_params(page, count, **params)
41
+ raise RequestError.new('Invalid page count') if params[:page] < 1 or params[:count] < 1
41
42
 
42
- PagarMe::Request.get(url(parent_id), params: hash.merge(
43
- page: page,
44
- count: count
45
- )).call.map do |object|
43
+ PagarMe::Request.get(url(parent_id), params: params).call.map do |object|
46
44
  object.parent_id = parent_id
47
45
  object
48
46
  end
49
47
  end
50
48
  alias :find_by_hash :find_by
51
49
 
52
- def all(parent_id, page = 1, count = 10)
53
- find_by parent_id, Hash.new, page, count
50
+ def all(parent_id, *args, **params)
51
+ params = extract_page_count_or_params(*args, **params)
52
+ find_by parent_id, params
54
53
  end
55
54
 
56
55
  def url(parent_id, *params)
@@ -91,7 +91,7 @@ module PagarMe
91
91
  end
92
92
 
93
93
  if args.size == 0
94
- return self[name]
94
+ return self[name] || self[name.to_sym]
95
95
  end
96
96
  end
97
97
 
@@ -18,17 +18,18 @@ module PagarMe
18
18
  end
19
19
  end
20
20
 
21
- def balance_operations(page = 1, count = 10)
22
- raise RequestError.new('Invalid page count') if page < 1 or count < 1
21
+ def balance_operations(*args, **params)
22
+ params = PagarMe::Model.extract_page_count_or_params(*args, **params)
23
+ raise RequestError.new('Invalid page count') if params[:page] < 1 or params[:count] < 1
23
24
 
24
- params = { page: page, count: count }
25
25
  PagarMe::Request.get(url, params: params).call
26
26
  end
27
27
 
28
- def find_by_recipient_id(recipient_id, page = 1, count = 10)
29
- raise RequestError.new('Invalid ID') unless recipient_id.present?
28
+ def find_by_recipient_id(recipient_id, *args, **params)
29
+ params = PagarMe::Model.extract_page_count_or_params(*args, **params)
30
+ raise RequestError.new('Invalid page count') if params[:page] < 1 or params[:count] < 1
31
+ raise RequestError.new('Invalid ID') unless recipient_id.present?
30
32
 
31
- params = { page: page, count: count }
32
33
  PagarMe::Request.get(url(recipient_id), params: params).call
33
34
  end
34
35
  end
@@ -6,7 +6,7 @@ module PagarMe
6
6
 
7
7
  protected
8
8
  def default_recipient_by_env
9
- if ENV['production']
9
+ if PagarMe.production?
10
10
  default_recipient_id.live
11
11
  else
12
12
  default_recipient_id.test
@@ -4,6 +4,11 @@ module PagarMe
4
4
  self.class.valid_request_signature? payload, signature
5
5
  end
6
6
 
7
+ def redirect(url = 'http://localhost:3000/pagarme/postback')
8
+ uri = URI(url)
9
+ Net::HTTP.new(uri.host, uri.port).post uri.path, payload, JSON.parse(headers)
10
+ end
11
+
7
12
  class << self
8
13
  def valid_request_signature?(payload, signature)
9
14
  kind, raw_signature = signature.split '=', 2
@@ -4,9 +4,10 @@ module PagarMe
4
4
  PagarMe::BulkAnticipation.bulk_anticipations_limits id, params
5
5
  end
6
6
 
7
- def bulk_anticipations(page = 1, count = 10)
8
- raise RequestError.new('Invalid page count') if page < 1 or count < 1
9
- PagarMe::BulkAnticipation.all id, page, count
7
+ def bulk_anticipations(*args, **params)
8
+ params = self.class.extract_page_count_or_params(*args, **params)
9
+ raise RequestError.new('Invalid page count') if params[:page] < 1 or params[:count] < 1
10
+ PagarMe::BulkAnticipation.all id, params
10
11
  end
11
12
 
12
13
  def bulk_anticipate(params = Hash.new)
@@ -18,6 +18,14 @@ module PagarMe
18
18
  PagarMe::Request.get( url 'postbacks' ).call
19
19
  end
20
20
 
21
+ def operations
22
+ PagarMe::Request.get( url 'operations' ).call
23
+ end
24
+
25
+ def events
26
+ PagarMe::Request.get( url 'events' ).call
27
+ end
28
+
21
29
  def collect_payment(params={})
22
30
  PagarMe::Request.post(url('collect_payment'), params: params).run
23
31
  end
@@ -31,16 +39,16 @@ module PagarMe
31
39
  end
32
40
 
33
41
  class << self
42
+ alias :charge :create
43
+
34
44
  def calculate_installments(params)
35
45
  PagarMe::Request.get(url('calculate_installments_amount'), query: params).run
36
46
  end
37
-
38
- def generate_card_hash()
39
- raise RequestError.new('Invalid Encryption Key') if PagarMe.encryption_key.blank?
40
-
41
- PagarMe::Request.get(url('card_hash_key'), params: { encryption_key: PagarMe.encryption_key }).call
42
- end
43
- alias :charge :create
47
+
48
+ def generate_card_hash
49
+ raise RequestError.new('Invalid Encryption Key') if PagarMe.encryption_key.blank?
50
+ PagarMe::Request.get(url('card_hash_key'), params: { encryption_key: PagarMe.encryption_key }).call
51
+ end
44
52
  end
45
53
  end
46
54
  end
@@ -1,3 +1,3 @@
1
1
  module PagarMe
2
- VERSION = '2.1.3'
2
+ VERSION = '2.1.4'
3
3
  end
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'rake'
26
26
  spec.add_development_dependency 'webmock'
27
27
  spec.add_development_dependency 'test-unit'
28
+ spec.add_development_dependency 'clipboard'
28
29
 
29
30
  spec.add_dependency 'rest-client'
30
31
  spec.add_dependency 'multi_json'
@@ -18,11 +18,11 @@ module PagarMe
18
18
  end
19
19
 
20
20
  {
21
- bank_code: 'foo',
22
- agencia: 'abcd',
23
- agencia_dv: 'Y',
24
- conta: 'ABCD',
25
- conta_dv: 'X',
21
+ bank_code: '123',
22
+ agencia: '1234',
23
+ agencia_dv: '1',
24
+ conta: '4444',
25
+ conta_dv: '1',
26
26
  legal_name: 'John Doe',
27
27
  document_number: '02476585700'
28
28
  }.each do |key, value|
@@ -26,7 +26,7 @@ module PagarMe
26
26
  PagarMe::Recipient.create recipient_with_nested_bank_account_params
27
27
 
28
28
  bank_account_doc_number = bank_account_params[:document_number]
29
- recipients = PagarMe::Recipient.find_by 'bank_account[document_number]' => bank_account_doc_number
29
+ recipients = PagarMe::Recipient.find_by bank_account: { document_number: bank_account_doc_number }
30
30
 
31
31
  assert recipients.size > 0
32
32
  recipients.each do |recipient|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagarme
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Franceschi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-07-13 00:00:00.000000000 Z
12
+ date: 2016-11-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -123,6 +123,20 @@ dependencies:
123
123
  - - ">="
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: clipboard
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
126
140
  - !ruby/object:Gem::Dependency
127
141
  name: rest-client
128
142
  requirement: !ruby/object:Gem::Requirement
@@ -254,4 +268,3 @@ test_files:
254
268
  - test/pagarme/resources/transfer_test.rb
255
269
  - test/pagarme/resources/zipcode_test.rb
256
270
  - test/test_helper.rb
257
- has_rdoc: