mp_api 0.1.3 → 0.1.5

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
  SHA256:
3
- metadata.gz: 3f995fbd62258b78eeaccc601d0af2cfb7be6554c5ddb045080566e7c344de87
4
- data.tar.gz: b86c88757bfc428cc980ed7b8325a10dbb52e19fc9a583dfdc6bd4916896315b
3
+ metadata.gz: 87b59a957a7922cebcccd48666b9e7a73de18d105b7c3a0cad863d2a877b91cf
4
+ data.tar.gz: 3cf121623c8efff7e1a8efd1e2afdf56ebe8f2aca70d4221cdddc2acde837cb5
5
5
  SHA512:
6
- metadata.gz: 92bb79b5bea00df5fe9878c4317a8e2d93b335a64a52ddd95d2ea1d95e89890045080acf15bb083562a20038905e87a87f78dfa8e7e9aad042c007549cd01076
7
- data.tar.gz: ec801010e7d476533eefb75c0342e9a3c392862a2c889ef1805ddfedfdd938fc38743aae5a502c5e80a1da209f7994c2902a67849f5982650610442d6f58b708
6
+ metadata.gz: fff89be33542ff3a6287efabdb13d19c4ba2e62e2c264ea6ee2323142e68e1898a1621ca2a29b35e32f4058b689758924a4ed5987d45b50995d67ab6acbd288b
7
+ data.tar.gz: 3e8bb21dade656b94de0e6b2678eb77e6ea090d004db08fed1d912c206696ad31b57d75f6b497acf32db6d3a93877264818365d91262f018eb0c68e11b540b33
@@ -1,9 +1,9 @@
1
- module MercadoPagoApi
1
+ module MpApi
2
2
  module Generators
3
3
  class InstallGenerator < Rails::Generators::Base
4
4
  source_root File.expand_path("templates", __dir__)
5
5
  def copy_initializer
6
- template "initializer.rb", "config/initializers/mercado_pago_api.rb"
6
+ template "initializer.rb", "config/initializers/mp_api.rb"
7
7
  end
8
8
  end
9
9
  end
@@ -0,0 +1,3 @@
1
+ MpApi.configure do |config|
2
+ # config.access_token = nil
3
+ end
@@ -1,9 +1,9 @@
1
- module MercadoPagoApi
1
+ module MpApi
2
2
  class Client < Ac::Base
3
3
  BASE_URL = "https://api.mercadopago.com/v1/"
4
4
 
5
5
  attr_reader :access_token
6
- def initialize(access_token=MercadoPagoApi.configuration.access_token)
6
+ def initialize(access_token=MpApi.configuration.access_token)
7
7
  @headers = {
8
8
  "Content-Type": "application/json",
9
9
  'x-idempotency-key' => SecureRandom.uuid
@@ -17,8 +17,8 @@ module MercadoPagoApi
17
17
  end
18
18
 
19
19
  def get_payment(payment_id)
20
- response = get("/payments/#{payment_id}") {_1.json['id']}
21
- response.json
20
+ response = get("/payments/#{payment_id}") {_1.json['id']}
21
+ response.json
22
22
  end
23
23
 
24
24
  def create_token(card_token_data)
@@ -1,8 +1,12 @@
1
- module MercadoPagoApi
1
+ module MpApi
2
2
  class Payment
3
3
 
4
4
  def self.find_by_id(payment_id)
5
- response = Client.new.get_payment(payment_id)
5
+ begin
6
+ response = Client.new.get_payment(payment_id)
7
+ rescue RuntimeError => e
8
+ e.message == 'Too many retries' ? raise(TooManyRequests) : raise(e)
9
+ end
6
10
  new(**build_hash(response))
7
11
  end
8
12
 
@@ -62,7 +66,11 @@ module MercadoPagoApi
62
66
  end
63
67
 
64
68
  def create
65
- response = Client.new.create_payment(JSON.dump(build_json))
69
+ begin
70
+ response = Client.new.create_payment(JSON.dump(build_json))
71
+ rescue RuntimeError => e
72
+ e.message == 'Too many retries' ? raise(TooManyRequests) : raise(e)
73
+ end
66
74
  self.class.new(**self.class.build_hash(response))
67
75
  end
68
76
 
@@ -1,4 +1,4 @@
1
- module MercadoPagoApi
1
+ module MpApi
2
2
 
3
3
  class PaymentMethod
4
4
 
@@ -1,4 +1,4 @@
1
- module MercadoPagoApi
1
+ module MpApi
2
2
 
3
3
  class Token
4
4
 
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MpApi
4
+ VERSION = "0.1.5"
5
+ end
@@ -1,13 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "ac"
4
- require_relative "mercado_pago_api/client"
5
- require_relative "mercado_pago_api/payment"
6
- require_relative "mercado_pago_api/token"
7
- require_relative "mercado_pago_api/payment_method"
8
- require_relative "mercado_pago_api/version"
9
- module MercadoPagoApi
4
+ require_relative "mp_api/client"
5
+ require_relative "mp_api/payment"
6
+ require_relative "mp_api/token"
7
+ require_relative "mp_api/payment_method"
8
+ require_relative "mp_api/version"
9
+ module MpApi
10
10
  class Error < StandardError; end
11
+
12
+ class TooManyRequests < StandardError
13
+ def message
14
+ "Too many requests"
15
+ end
16
+ end
11
17
 
12
18
  class Configuration
13
19
  attr_accessor :access_token, :public_key
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mp_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - caio
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-27 00:00:00.000000000 Z
11
+ date: 2023-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ac
@@ -34,15 +34,14 @@ files:
34
34
  - LICENSE.txt
35
35
  - README.md
36
36
  - Rakefile
37
- - lib/generators/mercado_pago_api/install/install_generator.rb
38
- - lib/generators/mercado_pago_api/install/templates/initializer.rb
39
- - lib/mercado_pago_api.rb
40
- - lib/mercado_pago_api/client.rb
41
- - lib/mercado_pago_api/payment.rb
42
- - lib/mercado_pago_api/payment_method.rb
43
- - lib/mercado_pago_api/token.rb
44
- - lib/mercado_pago_api/version.rb
45
- - sig/mercado_pago_api.rbs
37
+ - lib/generators/mp_api/install/install_generator.rb
38
+ - lib/generators/mp_api/install/templates/initializer.rb
39
+ - lib/mp_api.rb
40
+ - lib/mp_api/client.rb
41
+ - lib/mp_api/payment.rb
42
+ - lib/mp_api/payment_method.rb
43
+ - lib/mp_api/token.rb
44
+ - lib/mp_api/version.rb
46
45
  homepage: https://github.com/CaioGarcia1/mp_api
47
46
  licenses:
48
47
  - MIT
@@ -1,3 +0,0 @@
1
- MercadoPagoApi.configure do |config|
2
- # config.access_token = nil
3
- end
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MercadoPagoApi
4
- VERSION = "0.1.3"
5
- end
@@ -1,4 +0,0 @@
1
- module MercadoPagoApi
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end