conekta 0.4.2 → 0.4.3

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
- ODdjZDM1YzZlMDhiMzRlYjA5MTk0YWNmZjA0M2EwM2JlZGM3MzE0Yg==
4
+ MTA3YmQzYTliZWM5MDdjY2ZkZWRmZTNjMDgwOWJlYWIyNzYzOGU1MQ==
5
5
  data.tar.gz: !binary |-
6
- NmE3NDdkNzM5NmE1MDNkNzBkOThmOGU0ZDJkYWY3ZjA1NWVmOTBmYg==
6
+ ZDE0MzUyMTdiMWZmMDc2ZDE5MmM4ZWY1NWVjYzc1OGQyNDU4NTAwZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZmYxNjU5OTZkOWE2YmQyNGY3MWYwYTNkZjI1MDE0ZTgwYzE2MWM1NTM3NDYy
10
- ODkxNjA0MWRlYzFjY2U0OWZhMjk5M2RmMDk1OTU1NzU3YTFlMGEwYzBmMzJi
11
- MTJkMzU0Zjg5ZTk1Y2U4MGQwNGY4OGE4ZDc4MjI3MDdmNGIyMTU=
9
+ Y2M5MGVjOTY5Mzc3YzZiMDBlNmU4MjBmMzZlYzkzMTJlNjdmNmMxMzU2MWM5
10
+ YmI2YzkxZTdjNjQzYzg4NmRjMTQxZTE4NjQ3YTZiZTNkMDMxZWU0ZTgxODE1
11
+ NDQ2NTI2ZWE2NTc1NDAyZjlhZWNjOGM5NDkxYjFmMTk3YTIyNjg=
12
12
  data.tar.gz: !binary |-
13
- MWU4NTYyNTE4ZGQ1YTgwZGI4ZjY5MDE0ZWEzMzYxOWU0NGM1ZGM2NTJkNjgy
14
- MGFkMmUxZjRiMDEwZDBmOGE0Y2UxN2U1Y2Q1OGRmYTk4NDY0YWM4MzJlODEy
15
- ZmJmZTM2M2NlZWQ4Yjc4ZjU4MThlMjllYmIzZGE4ODIzODJlOWE=
13
+ OWNkNzA5MGQ4ZDA3OWEwNGIxNjQzYTIyNmQyMTI5ZDY0NDEyZDg0NTc2ZTgz
14
+ ZmExZWY1OWYzMWUyNGVjMDVjNDhkYTIzMTRmOWU5ZDQyMDg4ZmYxZTY3NjQ0
15
+ OTBhMDAxMzc2ODdmZDlmMzdkMTAwNTlmMjM4YzFlYTFlYmRmMjY=
data/CHANGELOG CHANGED
@@ -24,3 +24,7 @@
24
24
  === 0.4.2 2014-04-28
25
25
 
26
26
  * Fix Payout specs.
27
+
28
+ === 0.4.3 2014-05-25
29
+
30
+ * Add locale and message_to_purchaser.
data/Gemfile CHANGED
@@ -3,5 +3,6 @@ gem 'sys-uname'
3
3
  gem 'rspec'
4
4
  gem 'faraday'
5
5
  gem 'json'
6
+ gem 'i18n'
6
7
  # Specify your gem's dependencies in conekta.gemspec
7
8
  gemspec
data/lib/conekta.rb CHANGED
@@ -28,10 +28,13 @@ require "conekta/payout"
28
28
  require "conekta/payout_method"
29
29
  require "conekta/method"
30
30
  require "conekta/webhook_log"
31
+ require "i18n"
31
32
 
32
33
  module Conekta
34
+ I18n.load_path = Dir[File.join(File.expand_path('../..', __FILE__), 'locales', '*.{rb,yml}').to_s]
33
35
  @api_base = 'https://api.conekta.io'
34
36
  @api_version = '0.3.0'
37
+ @locale = 'es'
35
38
  def self.api_base
36
39
  @api_base
37
40
  end
@@ -50,4 +53,10 @@ module Conekta
50
53
  def self.api_key=(api_key)
51
54
  @api_key = api_key
52
55
  end
56
+ def self.locale
57
+ @locale
58
+ end
59
+ def self.locale=(locale)
60
+ @locale = locale
61
+ end
53
62
  end
data/lib/conekta/error.rb CHANGED
@@ -1,12 +1,14 @@
1
1
  module Conekta
2
2
  class Error < Exception
3
3
  attr_reader :message
4
+ attr_reader :message_to_purchaser
4
5
  attr_reader :type
5
6
  attr_reader :code
6
7
  attr_reader :param
7
8
 
8
- def initialize(message=nil, type=nil, code=nil, param=nil)
9
+ def initialize(message=nil, message_to_purchaser=nil, type=nil, code=nil, param=nil)
9
10
  @message = message
11
+ @message_to_purchaser = message_to_purchaser
10
12
  @type = type
11
13
  @code = code
12
14
  @param = param
@@ -17,28 +19,29 @@ module Conekta
17
19
  def self.error_handler(resp, code)
18
20
  if resp.instance_of?(Hash)
19
21
  @message = resp["message"] if resp.has_key?('message')
22
+ @message_to_purchaser = resp["message_to_purchaser"] if resp.has_key?('message_to_purchaser')
20
23
  @type = resp["type"] if resp.has_key?('type')
21
24
  @code = resp["code"] if resp.has_key?('code')
22
25
  @param = resp["param"] if resp.has_key?('param')
23
26
  end
24
27
  if code == nil or code == 0 or code == nil or code == ""
25
- raise NoConnectionError.new("Could not connect to #{Conekta.api_base}", @type, @code, @param)
28
+ raise NoConnectionError.new(I18n.t('error.requestor.connection', {base: Conekta.api_base, locale: :en}), I18n.t('error.requestor.connection', {base: Conekta.api_base, locale: Conekta.locale.to_sym}))
26
29
  end
27
30
  case code
28
31
  when 400
29
- raise MalformedRequestError.new(@message, @type, @code, @params)
32
+ raise MalformedRequestError.new(@message, @message_to_purchaser, @type, @code, @params)
30
33
  when 401
31
- raise AuthenticationError.new(@message, @type, @code, @params)
34
+ raise AuthenticationError.new(@message, @message_to_purchaser, @type, @code, @params)
32
35
  when 402
33
- raise ProcessingError.new(@message, @type, @code, @params)
36
+ raise ProcessingError.new(@message, @message_to_purchaser, @type, @code, @params)
34
37
  when 404
35
- raise ResourceNotFoundError.new(@message, @type, @code, @params)
38
+ raise ResourceNotFoundError.new(@message, @message_to_purchaser, @type, @code, @params)
36
39
  when 422
37
- raise ParameterValidationError.new(@message, @type, @code, @params)
40
+ raise ParameterValidationError.new(@message, @message_to_purchaser, @type, @code, @params)
38
41
  when 500
39
- raise ApiError.new(@message, @type, @code, @params)
42
+ raise ApiError.new(@message, @message_to_purchaser, @type, @code, @params)
40
43
  else
41
- raise Error.new(@message, @type, @code, @params)
44
+ raise Error.new(@message, @message_to_purchaser, @type, @code, @params)
42
45
  end
43
46
  end
44
47
  end
@@ -18,7 +18,8 @@ module Conekta
18
18
  begin
19
19
  conn = Faraday.new(:ssl => {
20
20
  :ca_file => File.dirname(__FILE__) + '/../ssl_data/ca_bundle.crt'
21
- }) do |faraday|
21
+ }
22
+ ) do |faraday|
22
23
  faraday.adapter Faraday.default_adapter
23
24
  end
24
25
  response = conn.method(meth).call do |req|
@@ -27,6 +28,7 @@ module Conekta
27
28
  req.headers['X-Conekta-Client-User-Agent'] = set_headers.to_json
28
29
  req.headers['User-Agent'] = 'Conekta/v1 RubyBindings/' + Conekta::VERSION
29
30
  req.headers['Accept'] = "application/vnd.conekta-v#{Conekta.api_version}+json"
31
+ req.headers['Accept-Language'] = Conekta.locale
30
32
  req.headers['Authorization'] = "Basic #{ Base64.encode64("#{self.api_key}" + ':')}"
31
33
  if params
32
34
  req.headers['Content-Type'] = 'application/json'
@@ -34,7 +36,7 @@ module Conekta
34
36
  end
35
37
  end
36
38
  rescue Exception => e
37
- Error.error_handler(e.message, "")
39
+ Error.error_handler(e, "")
38
40
  end
39
41
  if response.status != 200
40
42
  Error.error_handler(JSON.parse(response.body), response.status)
@@ -5,7 +5,7 @@ module Conekta
5
5
  end
6
6
  def url
7
7
  if id == nil || id == ""
8
- raise Error.new('Could not get the id of ' + self.class.class_name + ' instance.')
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
9
  end
10
10
  self.class.url + "/" + id
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module Conekta
2
- VERSION = '0.4.2'
2
+ VERSION = '0.4.3'
3
3
  end
data/locales/en.yml ADDED
@@ -0,0 +1,7 @@
1
+ # encoding: UTF-8
2
+ en:
3
+ error:
4
+ resource:
5
+ id: 'Could not get the id of %{resource} instance.'
6
+ requestor:
7
+ connection: 'Could not connect to %{base}.'
data/locales/es.yml ADDED
@@ -0,0 +1,7 @@
1
+ # encoding: UTF-8
2
+ es:
3
+ error:
4
+ resource:
5
+ id: 'No se pudo obtener el id de la instancia de %{resource}.'
6
+ requestor:
7
+ connection: 'No se pudo conectar a %{base}.'
data/spec/conekta_spec.rb CHANGED
@@ -15,7 +15,6 @@ describe :conekta_tests do
15
15
  bank: {
16
16
  account_number: '032180000118359719',
17
17
  account_holder: 'J D - Radcorp',
18
- bank: 'Banorte',
19
18
  description: 'Conekta To JD',
20
19
  statement_description: 'Conekta To JD 111111111',
21
20
  statement_reference: '111111111'
@@ -57,7 +56,6 @@ describe :conekta_tests do
57
56
  payout.method.account_number.should eq('032180000118359719')
58
57
  payout.method.account_holder.should eq('J D - Radcorp')
59
58
  payout.method.bank.should eq('ixe')
60
- # payout.payout_transaction_id.should_not eq(nil)
61
59
  payout.transactions.count.should eq(0)
62
60
  end
63
61
  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.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - MauricioMurga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-28 00:00:00.000000000 Z
11
+ date: 2014-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -136,6 +136,8 @@ files:
136
136
  - lib/conekta/version.rb
137
137
  - lib/conekta/webhook_log.rb
138
138
  - lib/ssl_data/ca_bundle.crt
139
+ - locales/en.yml
140
+ - locales/es.yml
139
141
  - spec/conekta_spec.rb
140
142
  - spec/spec_helper.rb
141
143
  homepage: https://www.conekta.io