conekta 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZWRlMTZkMzZlNjEwZDMwZmQyYWViYTk3ODdhNjJiYWJjM2Q4MTExNQ==
4
+ NDBkYWQ2NWE4ODYzZDA5MTExOTU0YzJiOGVmZTU1ZjU1NDU2ZjA0ZQ==
5
5
  data.tar.gz: !binary |-
6
- YjJhY2Q1N2IxOTE4Y2ZkYTJlZGNiYzJmZTYyMjNlZTE5MTRkNzE2Zg==
6
+ NjBmNDgyYmYyYzJmNDFkMWQ0ZDZiNTU3ZTFlN2ZmMjgyNzQ1Nzk5MQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NDhlMTYyMzA3M2EzMTYzZWI0MjVhZTE1ZGEzNjRiOGVkMzJjNGEyZDUzNDkz
10
- N2U0NGZiOTMyMDAyOTBjYWU2NjIwZWM2N2ZiNDdiZjM2OWEyNGU4NTYxYjBl
11
- MjYwN2NmMzFkZjI2OGNhY2M5YjYyMmMzZWU3YzZjMWNjZGNlZDU=
9
+ M2IyNmRkMjI1YWU3MDEyYTFjMWY3MDJiNDUyNjVlYzQwZTMzNGQyZjFmN2E0
10
+ ZWYzNDgxY2M5NjcyOTMwNzkxODU1YjgxM2QwMDQyNDQ5ZmJlYTQyMzc0NzIy
11
+ MjY5MTI4NTZjNjE3ZmYzMjFjZmEzYjBiYzUzYjAwNzk0ZmNjNWY=
12
12
  data.tar.gz: !binary |-
13
- OGFjMTYxNjM0MWFjMzYzYTAxYjdiZmE1NTc5ODg0YjY3MzFjMDQ5ZDE2M2Jj
14
- OWU2OTMwNGYwMzk3YjRjNzA0YjYxY2QwNjcxMTgxYTJiOTY1MTA1OTc2ZmE0
15
- NzRhOTgzOWZlMGY2OGJmMzdiNTZmODQ2MGRmZGIyMzYwZmYwOGQ=
13
+ MDJkMzNhNjkzMTEwMDk2NDg4YmVhODQ2NWEwYjAxZjUzNGZmZWI0MGU4MzA0
14
+ ZTZhMGVhNWJkOGIyMDY2ZGNjNDY5NDdlMjA1ZTJjNzMxYTZlYzBmMzAyMDc2
15
+ NmY2YWI5MDcxMzE1Mjc4NzE0YmQ5M2E1ZDNhNWU0YzdlZjZiOTk=
data/CHANGELOG CHANGED
@@ -32,3 +32,7 @@
32
32
  === 0.4.4 2014-06-04
33
33
 
34
34
  * Fix requestor and where method.
35
+
36
+ === 0.4.5 2014-07-08
37
+
38
+ * Sprinkling small Ruby style conventions here and there (antillas21).
data/README.md CHANGED
@@ -21,17 +21,27 @@ Or install it yourself as:
21
21
  Conekta.locale = :es
22
22
 
23
23
  Conekta.api_key = '1tv5yJp3xnVZ7eK67m4h'
24
- @my_card = {number: '4242424242424242', exp_month: 5, exp_year: 2015, cvc: 123, name: 'Mario Moreno'}
24
+
25
25
  begin
26
- charge = Conekta::Charge.create({card: @my_card, description: 'Some desc', amount: 2000, currency: 'mxn'})
27
- p charge
26
+ charge = Conekta::Charge.create({
27
+ amount: 51000,
28
+ currency: "MXN",
29
+ description: "Pizza Delivery",
30
+ reference_id: "orden_de_id_interno",
31
+ card: params[:conektaTokenId]
32
+ #"tok_a4Ff0dD2xYZZq82d9"
33
+ })
34
+ rescue Conekta::ParameterValidationError => e
35
+ puts e.message
36
+ #alguno de los parámetros fueron inválidos
37
+ rescue Conekta::ProcessingError => e
38
+ puts e.message
39
+ #la tarjeta no pudo ser procesada
28
40
  rescue Conekta::Error
29
- # Catch all exceptions including validation errors.
30
- e.message
31
-
32
- # Error message translated
33
- e.message_to_purchaser
41
+ puts e.message
42
+ #un error ocurrió que no sucede en el flujo normal de cobros como por ejemplo un auth_key incorrecto
34
43
  end
44
+
35
45
 
36
46
  {
37
47
  "id": "5286828b8ee31e64b7001739",
@@ -4,9 +4,7 @@ module Conekta
4
4
  include Conekta::Operations::Update
5
5
  include Conekta::Operations::CustomAction
6
6
  def url
7
- if id == nil || id == ""
8
- raise Error.new('Could not get the id of ' + self.class.class_name + ' instance.')
9
- end
7
+ raise Error.new('Could not get the id of ' + self.class.class_name + ' instance.') if (id.nil? || id.empty?)
10
8
  self.customer.url + self.class.url + "/" + id
11
9
  end
12
10
  def delete
@@ -5,14 +5,10 @@ module Conekta
5
5
  include Conekta::Operations::Create
6
6
  include Conekta::Operations::CustomAction
7
7
  def capture
8
- custom_action(:post, 'capture', nil)
8
+ custom_action(:post, 'capture')
9
9
  end
10
10
  def refund(params=nil)
11
- if params == nil
12
- params = {"amount" => self.amount}
13
- else
14
- params = {"amount" => params}
15
- end
11
+ params = { 'amount' => (params || self.amount) }
16
12
  custom_action(:post, 'refund', params)
17
13
  end
18
14
  end
@@ -3,9 +3,8 @@ module Conekta
3
3
  module Create
4
4
  module ClassMethods
5
5
  def create(params)
6
- requestor = Requestor.new
7
6
  url = Util.types[self.class_name.downcase].url
8
- response = requestor.request(:post, url, params)
7
+ response = Requestor.new.request(:post, url, params)
9
8
  instance = self.new
10
9
  instance.load_from(response)
11
10
  instance
@@ -2,13 +2,13 @@ module Conekta
2
2
  module Operations
3
3
  module CreateMember
4
4
  def create_member(member, params)
5
- url = self.url + "/" + member
5
+ url = [self.url, member].join('/')
6
6
  member = member.to_sym
7
- requestor = Requestor.new
8
- response = requestor.request(:post, url, params)
7
+ response = Requestor.new.request(:post, url, params)
8
+
9
9
  if self.method(member).call and self.method(member).call.class.class_name == "ConektaObject"
10
10
  arr = []
11
- self.method(member).call.values.each do |(k,v)|
11
+ self.method(member).call.values.each do |_,v|
12
12
  arr << v.to_hash
13
13
  end
14
14
  arr << response
@@ -2,13 +2,9 @@ module Conekta
2
2
  module Operations
3
3
  module CustomAction
4
4
  def custom_action(method, action=nil, params=nil)
5
- requestor = Requestor.new
6
- if action
7
- url = self.url + "/" + action
8
- else
9
- url = self.url
10
- end
11
- response = requestor.request(method, url, params)
5
+ url = action ? [self.url, action].join('/') : self.url
6
+ response = Requestor.new.request(method, url, params)
7
+
12
8
  self.load_from(response)
13
9
  self
14
10
  end
@@ -4,21 +4,13 @@ module Conekta
4
4
  module ClassMethods
5
5
  def find(id)
6
6
  instance = self.new(id)
7
- url = instance.url
8
- requestor = Requestor.new
9
- response = requestor.request(:get, url)
7
+ response = Requestor.new.request(:get, instance.url)
10
8
  instance.load_from(response)
11
9
  instance
12
10
  end
11
+
13
12
  # <b>DEPRECATED:</b> Please use <tt>find</tt> instead.
14
- def retrieve(id)
15
- instance = self.new(id)
16
- url = instance.url
17
- requestor = Requestor.new
18
- response = requestor.request(:get, url)
19
- instance.load_from(response)
20
- instance
21
- end
13
+ alias_method :retrieve, :find
22
14
  end
23
15
  def self.included(base)
24
16
  base.extend(ClassMethods)
@@ -2,9 +2,7 @@ module Conekta
2
2
  module Operations
3
3
  module Update
4
4
  def update(params)
5
- requestor = Requestor.new
6
- url = self.url
7
- response = requestor.request(:put, url, params)
5
+ response = Requestor.new.request(:put, self.url, params)
8
6
  self.load_from(response)
9
7
  self
10
8
  end
@@ -5,20 +5,13 @@ module Conekta
5
5
  def where(params=nil)
6
6
  instance = ConektaObject.new
7
7
  url = Util.types[self.class_name.downcase].url
8
- requestor = Requestor.new
9
- response = requestor.request(:get, url,params)
8
+ response = Requestor.new.request(:get, url,params)
10
9
  instance.load_from(response)
11
10
  instance
12
11
  end
12
+
13
13
  # <b>DEPRECATED:</b> Please use <tt>where</tt> instead.
14
- def all(params=nil)
15
- instance = ConektaObject.new
16
- url = Util.types[self.class_name.downcase].url
17
- requestor = Requestor.new
18
- response = requestor.request(:get, url)
19
- instance.load_from(response)
20
- instance
21
- end
14
+ alias_method :all, :where
22
15
  end
23
16
  def self.included(base)
24
17
  base.extend(ClassMethods)
@@ -4,9 +4,7 @@ module Conekta
4
4
  include Conekta::Operations::Update
5
5
  include Conekta::Operations::CustomAction
6
6
  def url
7
- if id == nil || id == ""
8
- raise Error.new('Could not get the id of ' + self.class.class_name + ' instance.')
9
- end
7
+ raise Error.new('Could not get the id of ' + self.class.class_name + ' instance.') if (id.nil? || id.empty?)
10
8
  self.payee.url + self.class.url + "/" + id
11
9
  end
12
10
  def delete
@@ -4,10 +4,9 @@ module Conekta
4
4
  "/#{CGI.escape(self.class_name.downcase)}s"
5
5
  end
6
6
  def url
7
- if id == nil || id == ""
8
- raise Error.new(I18n.t('error.resource.id', {resource: self.class.class_name, locale: :en}), I18n.t('error.resource.id', {resource: self.class.class_name, locale: Conekta.locale.to_sym}))
9
- end
10
- self.class.url + "/" + id
7
+ raise Error.new(I18n.t('error.resource.id', {resource: self.class.class_name, locale: :en}), I18n.t('error.resource.id', {resource: self.class.class_name, locale: Conekta.locale.to_sym})) if (id.nil? || id.empty?)
8
+
9
+ return [self.class.url, id].join('/')
11
10
  end
12
11
  end
13
12
  end
@@ -3,9 +3,8 @@ module Conekta
3
3
  include Conekta::Operations::Update
4
4
  include Conekta::Operations::CustomAction
5
5
  def url
6
- if id == nil || id == ""
7
- raise Error.new('Could not get the id of ' + self.class.class_name + ' instance.')
8
- end
6
+ raise Error.new('Could not get the id of ' + self.class.class_name + ' instance.') if (id.nil? || id.empty?)
7
+
9
8
  self.customer.url + "/subscription"
10
9
  end
11
10
  def pause
@@ -1,3 +1,3 @@
1
1
  module Conekta
2
- VERSION = '0.4.4'
2
+ VERSION = '0.4.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conekta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - MauricioMurga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-04 00:00:00.000000000 Z
11
+ date: 2014-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler