pagarme 1.9.2 → 1.9.3

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: db8bb546fef78ef9030feaa67e4b2653b954b605
4
- data.tar.gz: 791ac20fa6349679658a591df295df1fe60af23c
3
+ metadata.gz: 8641743ec32b982257e8fdd31df4acedcaf111a5
4
+ data.tar.gz: dad121632d7f8073b6ba047788154cbf965aa775
5
5
  SHA512:
6
- metadata.gz: 7f268fc7eb1887d3cebbf0b93cc14f5d220023f793d16a9969baafc3de5acc6df4471d0554a031e28c955ae66699629d5d6367de19f58e5589facf4dafd7b8b8
7
- data.tar.gz: e2a77cf16a0297be1d12536b34a255de4dc448b373c72d379eaa302396fbb355503ddeac4b05634ca5363935ede8be52fd42ecd884bf835626a55656f25fe64c
6
+ metadata.gz: 8e5dce369112fdd3d218700340bd65f912c9b2c9a27fc5763f544e95aebf8f22910a78a5445854e2f49007c2d33df29c82dd4f4a293df8773ade39c5ea938199
7
+ data.tar.gz: 2446887bd86e88057529c3ef18169bdbb36f47c21de44d17f1aa6aa4331a7e84431440d51daa92adbdbe8f6c9e0457d15a2990a866afeaef522158d7d3ed3b94
@@ -2,3 +2,4 @@ language: ruby
2
2
  rvm:
3
3
  - "1.9.3"
4
4
  - "2.0.0"
5
+ - "2.1.2"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pagarme (1.8)
4
+ pagarme (1.9.3)
5
5
  multi_json
6
6
  rest-client
7
7
 
@@ -14,11 +14,18 @@ require 'pagarme/errors'
14
14
 
15
15
  module PagarMe
16
16
  @@api_key = nil
17
- @@api_endpoint = 'https://api.pagar.me'
18
- @@api_version = '1'
17
+ @@api_endpoint = 'https://api.pagar.me/1'
19
18
  @@live = true
20
19
  @@api_card_encryption_public_key = File.join(File.dirname(__FILE__), '..', 'certs/public_key.pem')
21
20
 
21
+ def self.api_endpoint=(api_endpoint)
22
+ @@api_endpoint = api_endpoint
23
+ end
24
+
25
+ def self.api_endpoint
26
+ @@api_endpoint
27
+ end
28
+
22
29
  def self.api_key=(api_key)
23
30
  @@api_key = api_key
24
31
  end
@@ -32,10 +39,10 @@ module PagarMe
32
39
  end
33
40
 
34
41
  def self.full_api_url(relative_path)
35
- "#{@@api_endpoint}/#{@@api_version}#{relative_path}"
42
+ "#{@@api_endpoint}#{relative_path}"
36
43
  end
37
44
 
38
45
  def self.validate_fingerprint(id, fingerprint)
39
- Digest::SHA1.hexdigest(id.to_s + "#" + @@api_key) == fingerprint
46
+ Digest::SHA1.hexdigest(id.to_s + "#" + @@api_key) == fingerprint
40
47
  end
41
48
  end
@@ -1,30 +1,30 @@
1
1
  module PagarMe
2
2
  class PagarMeError < StandardError
3
- attr_accessor :message
4
- attr_accessor :parameter_name
5
- attr_accessor :type
6
- attr_accessor :url
7
- attr_accessor :errors
3
+ attr_accessor :message
4
+ attr_accessor :parameter_name
5
+ attr_accessor :type
6
+ attr_accessor :url
7
+ attr_accessor :errors
8
8
 
9
- def initialize(message = "", parameter_name = "", type = "", url = "")
10
- self.message = message
11
- self.type = type
12
- self.parameter_name = parameter_name
13
- self.errors = []
14
- end
9
+ def initialize(message = "", parameter_name = "", type = "", url = "")
10
+ self.message = message
11
+ self.type = type
12
+ self.parameter_name = parameter_name
13
+ self.errors = []
14
+ end
15
15
 
16
- def self.initFromServerResponse(response = {})
17
- object = self.new
18
- response['errors'].map do |error|
19
- object.message += error['message'] + ', '
20
- object.errors << PagarMeError.new(error['message'], error['parameter_name'], error['type'], response['url'])
21
- end
22
- object
23
- end
24
-
25
- def to_s
26
- "#{self.class.to_s} - #{message}"
27
- end
16
+ def self.initFromServerResponse(response = {})
17
+ object = self.new
18
+ response['errors'].map do |error|
19
+ object.message += error['message'] + ', '
20
+ object.errors << PagarMeError.new(error['message'], error['parameter_name'], error['type'], response['url'])
21
+ end
22
+ object
23
+ end
24
+
25
+ def to_s
26
+ "#{self.class.to_s} - #{message}"
27
+ end
28
28
  end
29
29
 
30
30
  class RequestError < PagarMeError
@@ -1,64 +1,64 @@
1
1
  module PagarMe
2
2
  class Model < PagarMeObject
3
3
 
4
- def self.class_name
5
- self.name.split('::')[-1]
6
- end
4
+ def self.class_name
5
+ self.name.split('::')[-1]
6
+ end
7
7
 
8
- def self.url()
9
- if self == Model
10
- raise PagarMeError.new('Cant request for model')
11
- end
12
- "/#{CGI.escape(class_name.downcase)}s"
13
- end
8
+ def self.url()
9
+ if self == Model
10
+ raise PagarMeError.new('Cant request for model')
11
+ end
12
+ "/#{CGI.escape(class_name.downcase)}s"
13
+ end
14
14
 
15
- def url
16
- raise PagarMeError.new("ID invalido", 'id') if !self.id
17
- "#{self.class.url}/#{CGI.escape(id.to_s)}"
18
- end
15
+ def url
16
+ raise PagarMeError.new("ID invalido", 'id') if !self.id
17
+ "#{self.class.url}/#{CGI.escape(id.to_s)}"
18
+ end
19
19
 
20
- def create
21
- request = PagarMe::Request.new(self.class.url, 'POST')
22
- request.parameters = self.to_hash
23
- response = request.run
24
- update(response)
25
- end
20
+ def create
21
+ request = PagarMe::Request.new(self.class.url, 'POST')
22
+ request.parameters = self.to_hash
23
+ response = request.run
24
+ update(response)
25
+ end
26
26
 
27
- def save
28
- request = PagarMe::Request.new(self.url, 'PUT')
29
- request.parameters = self.unsaved_values
30
- response = request.run
31
- update(response)
32
- end
27
+ def save
28
+ request = PagarMe::Request.new(self.url, 'PUT')
29
+ request.parameters = self.unsaved_values
30
+ response = request.run
31
+ update(response)
32
+ end
33
33
 
34
- def self.find_by_id(id)
35
- request = PagarMe::Request.new(self.url + "/#{id}", 'GET')
36
- response = request.run
37
- PagarMe::Util.convert_to_pagarme_object(response)
38
- end
34
+ def self.find_by_id(id)
35
+ request = PagarMe::Request.new(self.url + "/#{id}", 'GET')
36
+ response = request.run
37
+ PagarMe::Util.convert_to_pagarme_object(response)
38
+ end
39
39
 
40
- def self.find_by(hash, page = 1, count = 10)
41
- raise RequestError.new("Invalid page count") if page < 1 or count < 1
42
-
43
- request = PagarMe::Request.new(self.url, 'GET')
44
-
45
- request.parameters = hash
46
- request.parameters.merge!({:page => page, :count => count})
47
- response = request.run
48
- PagarMe::Util.convert_to_pagarme_object(response)
49
- end
40
+ def self.find_by(hash, page = 1, count = 10)
41
+ raise RequestError.new("Invalid page count") if page < 1 or count < 1
50
42
 
51
- def self.all(page = 1, count = 10)
52
- raise RequestError.new("Invalid page count") if page < 1 or count < 1
43
+ request = PagarMe::Request.new(self.url, 'GET')
53
44
 
54
- request = PagarMe::Request.new(url, 'GET')
55
- request.parameters = {
56
- :page => page,
57
- :count => count
58
- }
45
+ request.parameters = hash
46
+ request.parameters.merge!({:page => page, :count => count})
47
+ response = request.run
48
+ PagarMe::Util.convert_to_pagarme_object(response)
49
+ end
59
50
 
60
- response = request.run
61
- response.map { |obj_response| self.new(obj_response) }
62
- end
51
+ def self.all(page = 1, count = 10)
52
+ raise RequestError.new("Invalid page count") if page < 1 or count < 1
53
+
54
+ request = PagarMe::Request.new(url, 'GET')
55
+ request.parameters = {
56
+ :page => page,
57
+ :count => count
58
+ }
59
+
60
+ response = request.run
61
+ response.map { |obj_response| self.new(obj_response) }
62
+ end
63
63
  end
64
64
  end
@@ -4,140 +4,140 @@ require 'set'
4
4
  module PagarMe
5
5
  class PagarMeObject
6
6
 
7
- def initialize(response = {})
8
- #init @attributes - which are the attributes in the object
9
- @attributes = {}
10
-
11
- # filters - which are the filters that will be called when appropriate , such as before_set
12
- @filters = {}
13
-
14
- # Values that were changed in the object but weren't saved
15
- @unsaved_values = Set.new
16
-
17
- #Update object
18
- update(response)
19
- end
20
-
21
- def self.build(attributes)
22
- object = self.new(attributes)
23
- return object
24
- end
25
-
26
- def update(attributes)
27
-
28
- removed = Set.new(@attributes.keys - attributes.keys)
29
- added = Set.new(attributes.keys - @attributes.keys)
30
-
31
- instance_eval do
32
- remove_attribute(removed)
33
- add_attribute(added)
34
- end
35
-
36
- removed.each do |key|
37
- @attributes.delete(key)
38
- @unsaved_values.delete(key)
39
- end
40
-
41
- attributes.each do |key, value|
42
- @attributes[key] = Util.convert_to_pagarme_object(value)
43
- @unsaved_values.delete(key)
44
- end
45
- end
46
-
47
- def each(&block)
48
- @attributes.each(&block)
49
- end
50
-
51
- def []=(key,value)
52
- @attributes[key] = value
53
- end
54
-
55
- def [](key)
56
- @attributes[key.to_sym]
57
- end
58
-
59
- def unsaved_values
60
- values = {}
61
- @unsaved_values.each do |k|
62
- if(@attributes[k].kind_of?(PagarMeObject))
63
- values[k] = @attributes[k].unsaved_values
64
- else
65
- values[k] = @attributes[k]
66
- end
67
- end
68
- values
69
- end
70
-
71
- def to_hash
72
- ret_attributes = {}
73
- @attributes.each do |k,v|
74
- if @attributes[k].kind_of?(PagarMeObject)
75
- ret_attributes[k] = @attributes[k].to_hash if @attributes[k].kind_of?(PagarMeObject)
76
- else
77
- ret_attributes[k] = @attributes[k]
78
- end
79
- end
80
- return ret_attributes
81
- end
82
-
83
- protected
84
-
85
- def metaclass
86
- class << self; self; end
87
- end
88
-
89
- def remove_attribute(keys)
90
- metaclass.instance_eval do
91
- keys.each do |key|
92
- key_sym = :"#{key}="
93
- remove_method(key) if method_defined?(key)
94
- remove_method(key_sym) if method_defined?(key_sym)
95
- end
96
- end
97
- end
98
-
99
- def add_attribute(keys)
100
- metaclass.instance_eval do
101
- keys.each do |key|
102
- key_set = "#{key}="
103
- define_method(key) { @attributes[key] }
104
- define_method(key_set) do |value|
105
- if @filters[key]
106
- @filters[key].each do |meth|
107
- if methods.include?(meth)
108
- @attributes[key] = method(meth).call(value)
109
- @unsaved_values.add(key)
110
- end
111
- end
112
- else
113
- @attributes[key] = value
114
- @unsaved_values.add(key)
115
- end
116
- end
117
- end
118
- end
119
- end
120
-
121
- def before_set_filter(attribute, method)
122
- @filters[attribute.to_sym] = Array.new unless @filters[attribute.to_sym]
123
- @filters[attribute.to_sym] << method.to_sym
124
- end
125
-
126
- def method_missing(name, *args)
127
- if name.to_s.end_with?('=')
128
- attr = name.to_s[0...-1].to_sym
129
- add_attribute([attr])
130
- begin
131
- mth = method(name)
132
- rescue NameError
133
- raise NoMethodError.new("O atributo #{name} nao e permitido.")
134
- end
135
- return mth.call(args[0])
136
- else
137
- if @attributes.has_key?(name)
138
- return @attributes[name]
139
- end
140
- end
141
- end
7
+ def initialize(response = {})
8
+ #init @attributes - which are the attributes in the object
9
+ @attributes = {}
10
+
11
+ # filters - which are the filters that will be called when appropriate , such as before_set
12
+ @filters = {}
13
+
14
+ # Values that were changed in the object but weren't saved
15
+ @unsaved_values = Set.new
16
+
17
+ #Update object
18
+ update(response)
19
+ end
20
+
21
+ def self.build(attributes)
22
+ object = self.new(attributes)
23
+ return object
24
+ end
25
+
26
+ def update(attributes)
27
+
28
+ removed = Set.new(@attributes.keys - attributes.keys)
29
+ added = Set.new(attributes.keys - @attributes.keys)
30
+
31
+ instance_eval do
32
+ remove_attribute(removed)
33
+ add_attribute(added)
34
+ end
35
+
36
+ removed.each do |key|
37
+ @attributes.delete(key)
38
+ @unsaved_values.delete(key)
39
+ end
40
+
41
+ attributes.each do |key, value|
42
+ @attributes[key] = Util.convert_to_pagarme_object(value)
43
+ @unsaved_values.delete(key)
44
+ end
45
+ end
46
+
47
+ def each(&block)
48
+ @attributes.each(&block)
49
+ end
50
+
51
+ def []=(key,value)
52
+ @attributes[key] = value
53
+ end
54
+
55
+ def [](key)
56
+ @attributes[key.to_sym]
57
+ end
58
+
59
+ def unsaved_values
60
+ values = {}
61
+ @unsaved_values.each do |k|
62
+ if(@attributes[k].kind_of?(PagarMeObject))
63
+ values[k] = @attributes[k].unsaved_values
64
+ else
65
+ values[k] = @attributes[k]
66
+ end
67
+ end
68
+ values
69
+ end
70
+
71
+ def to_hash
72
+ ret_attributes = {}
73
+ @attributes.each do |k,v|
74
+ if @attributes[k].kind_of?(PagarMeObject)
75
+ ret_attributes[k] = @attributes[k].to_hash if @attributes[k].kind_of?(PagarMeObject)
76
+ else
77
+ ret_attributes[k] = @attributes[k]
78
+ end
79
+ end
80
+ return ret_attributes
81
+ end
82
+
83
+ protected
84
+
85
+ def metaclass
86
+ class << self; self; end
87
+ end
88
+
89
+ def remove_attribute(keys)
90
+ metaclass.instance_eval do
91
+ keys.each do |key|
92
+ key_sym = :"#{key}="
93
+ remove_method(key) if method_defined?(key)
94
+ remove_method(key_sym) if method_defined?(key_sym)
95
+ end
96
+ end
97
+ end
98
+
99
+ def add_attribute(keys)
100
+ metaclass.instance_eval do
101
+ keys.each do |key|
102
+ key_set = "#{key}="
103
+ define_method(key) { @attributes[key] }
104
+ define_method(key_set) do |value|
105
+ if @filters[key]
106
+ @filters[key].each do |meth|
107
+ if methods.include?(meth)
108
+ @attributes[key] = method(meth).call(value)
109
+ @unsaved_values.add(key)
110
+ end
111
+ end
112
+ else
113
+ @attributes[key] = value
114
+ @unsaved_values.add(key)
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
120
+
121
+ def before_set_filter(attribute, method)
122
+ @filters[attribute.to_sym] = Array.new unless @filters[attribute.to_sym]
123
+ @filters[attribute.to_sym] << method.to_sym
124
+ end
125
+
126
+ def method_missing(name, *args)
127
+ if name.to_s.end_with?('=')
128
+ attr = name.to_s[0...-1].to_sym
129
+ add_attribute([attr])
130
+ begin
131
+ mth = method(name)
132
+ rescue NameError
133
+ raise NoMethodError.new("O atributo #{name} nao e permitido.")
134
+ end
135
+ return mth.call(args[0])
136
+ else
137
+ if @attributes.has_key?(name)
138
+ return @attributes[name]
139
+ end
140
+ end
141
+ end
142
142
  end
143
143
  end