mercadopago-ruby 0.10.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +20 -0
- data/README.md +55 -0
- data/Rakefile +6 -0
- data/lib/mercadopago.rb +4 -0
- data/lib/mercadopago/active_support/deep_symbolize_keys.rb +27 -0
- data/lib/mercadopago/api.rb +11 -0
- data/lib/mercadopago/api/cards.rb +35 -0
- data/lib/mercadopago/api/clients.rb +82 -0
- data/lib/mercadopago/base.rb +48 -0
- data/lib/mercadopago/version.rb +16 -0
- data/mercadopago-ruby.gemspec +31 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 58b0eae1c8f7b70853fcf5d518131018d48fa959e321542b702eafb01cb22a32
|
4
|
+
data.tar.gz: 281d3382dc4b60d9bc16d434441bc3e2ebbe9a6785b9322b5a73ffea964b0fa4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d49465e837fab0af6c84dc36a1bf42a93786ab220efd28d6eeac97463e34f5fefb95361706cf14241666be30e8069a8674489509b5809e63d21d537c4bf36fb6
|
7
|
+
data.tar.gz: 0eaa84b968c3d0369ad92e1b0ed4c3dfc69d6da7baa1d5d29395f5a2b416a3b231989c50429d025269260f86dbde379ec2b2d16877c66b6d6b500324f8af80da
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2018 Nardo Nykolyszyn
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Mercado Pago Gem
|
2
|
+
[](https://badge.fury.io/rb/mercadopago-ruby)
|
3
|
+
-----
|
4
|
+
## Index
|
5
|
+
- [Installation](#installation)
|
6
|
+
* API end-points
|
7
|
+
- [Clients](#clients)
|
8
|
+
* Search a customer by email
|
9
|
+
* Search a customer by any criteria
|
10
|
+
* Create a customer
|
11
|
+
* Remove customer
|
12
|
+
* Update customer
|
13
|
+
- [Cards](#cards)
|
14
|
+
* Retrieve
|
15
|
+
------
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
```
|
19
|
+
$ gem install mercadopago-ruby
|
20
|
+
```
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
require 'mercadopago'
|
24
|
+
```
|
25
|
+
## Clients
|
26
|
+
- Get a customer by email
|
27
|
+
```ruby
|
28
|
+
@client = MercadoPago::API::Clients.new(access_token: ACCESS_TOKEN)
|
29
|
+
@client.search_customers_by_email(email: 'customer@mail.com')
|
30
|
+
```
|
31
|
+
- Get a customer by any criteria
|
32
|
+
```ruby
|
33
|
+
@client.search_by(first_name: 'Peter Khaule')
|
34
|
+
```
|
35
|
+
- Create a new customer
|
36
|
+
```ruby
|
37
|
+
@client.create_customer(email: 'customer@mail.com')
|
38
|
+
```
|
39
|
+
- Remove customer
|
40
|
+
```ruby
|
41
|
+
@client.remove_customer(CUSTOMER_ID)
|
42
|
+
```
|
43
|
+
- Update customer
|
44
|
+
```ruby
|
45
|
+
payload = {
|
46
|
+
first_name: 'Peter Khaule'
|
47
|
+
}
|
48
|
+
@client.update_customer(CUSTOMER_ID, payload)
|
49
|
+
```
|
50
|
+
## Cards
|
51
|
+
- Retrieve customer cards
|
52
|
+
```ruby
|
53
|
+
@client = MercadoPago::API::Cards.new(access_token: ACCESS_TOKEN)
|
54
|
+
@client.retrieve_customer_cards(CUSTOMER_ID)
|
55
|
+
```
|
data/Rakefile
ADDED
data/lib/mercadopago.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SymbolizeHelper
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def symbolize_recursive(hash)
|
7
|
+
{}.tap do |h|
|
8
|
+
hash.each { |key, value| h[key.to_sym] = transform(value) }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def transform(thing)
|
15
|
+
case thing
|
16
|
+
when Hash; symbolize_recursive(thing)
|
17
|
+
when Array; thing.map { |v| transform(v) }
|
18
|
+
else; thing
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
refine Hash do
|
23
|
+
def deep_symbolize_keys
|
24
|
+
SymbolizeHelper.symbolize_recursive(self)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mercadopago/base'
|
4
|
+
|
5
|
+
module MercadoPago
|
6
|
+
module API
|
7
|
+
class Cards < Base
|
8
|
+
# Override parent class method
|
9
|
+
# Place here main base URL
|
10
|
+
def service_url
|
11
|
+
'https://api.mercadopago.com'
|
12
|
+
end
|
13
|
+
|
14
|
+
# GET /v1/customers/:customer_id/cards
|
15
|
+
# It retrieves all cards from a customer
|
16
|
+
def retrieve_customer_cards(customer_id)
|
17
|
+
response = connection.get customer_cards_endpoint(customer_id) do |req|
|
18
|
+
req.params['access_token'] = access_token
|
19
|
+
end
|
20
|
+
response = process_response(response)
|
21
|
+
OpenStruct.new(success?: true, body: response)
|
22
|
+
rescue Faraday::ClientError => exception
|
23
|
+
OpenStruct.new(success?: false, message: 'Los datos no son correctos', details: exception.response[:body].to_s)
|
24
|
+
rescue Faraday::Error::TimeoutError, Faraday::ConnectionFailed, Timeout::Error => e
|
25
|
+
OpenStruct.new(success?: false, message: 'El servidor de mercadopago se encuentra fuera de servicio. Intenta más tarde', details: 'Server timeout')
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def customer_cards_endpoint(customer_id)
|
31
|
+
"/v1/customers/#{customer_id}/cards/"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mercadopago/base'
|
4
|
+
|
5
|
+
module MercadoPago
|
6
|
+
module API
|
7
|
+
class Clients < Base
|
8
|
+
# Override parent class method
|
9
|
+
# Place here main base URL
|
10
|
+
def service_url
|
11
|
+
'https://api.mercadopago.com'
|
12
|
+
end
|
13
|
+
|
14
|
+
# Argument must be an Hash
|
15
|
+
# request.create_customer(email: 'example@mail.com')
|
16
|
+
def create_customer(payload)
|
17
|
+
response = connection.post(customer_endpoint, payload) do |req|
|
18
|
+
req.params['access_token'] = access_token
|
19
|
+
end
|
20
|
+
response = process_response(response)
|
21
|
+
OpenStruct.new(success?: true, body: response)
|
22
|
+
rescue Faraday::ClientError => exception
|
23
|
+
OpenStruct.new(success?: false, message: 'Los datos no son correctos', details: exception.response[:body].to_s)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Argument must be an Hash
|
27
|
+
def search_customers_by_email(payload)
|
28
|
+
response = connection.get(customers_search_endpoint, payload) do |req|
|
29
|
+
req.params['access_token'] = access_token
|
30
|
+
end
|
31
|
+
response = process_response(response)
|
32
|
+
OpenStruct.new(success?: true, body: response)
|
33
|
+
rescue Faraday::ClientError => exception
|
34
|
+
OpenStruct.new(success?: false, message: 'Bad request', details: exception.response[:body].to_s)
|
35
|
+
end
|
36
|
+
|
37
|
+
def search_by(criteria={})
|
38
|
+
response = connection.get(customers_search_endpoint, criteria) do |req|
|
39
|
+
req.params['access_token'] = access_token
|
40
|
+
end
|
41
|
+
response = process_response(response)
|
42
|
+
OpenStruct.new(success?: true, body: response)
|
43
|
+
rescue Faraday::ClientError => exception
|
44
|
+
OpenStruct.new(success?: false, message: 'Bad request', details: exception.response[:body].to_s)
|
45
|
+
end
|
46
|
+
|
47
|
+
def update_customer(customer_id, payload)
|
48
|
+
response = connection.put(customer_id_endpoint(customer_id), payload) do |req|
|
49
|
+
req.params['access_token'] = access_token
|
50
|
+
end
|
51
|
+
response = process_response(response)
|
52
|
+
OpenStruct.new(success?: true, body: response)
|
53
|
+
rescue Faraday::ClientError => exception
|
54
|
+
OpenStruct.new(success?: false, message: 'Bad request', details: exception.response[:body].to_s)
|
55
|
+
end
|
56
|
+
|
57
|
+
def remove_customer(customer_id)
|
58
|
+
response = connection.delete(customer_id_endpoint(customer_id)) do |req|
|
59
|
+
req.params['access_token'] = access_token
|
60
|
+
end
|
61
|
+
response = process_response(response)
|
62
|
+
OpenStruct.new(success?: true, body: response)
|
63
|
+
rescue Faraday::ClientError => exception
|
64
|
+
OpenStruct.new(success?: false, message: 'Bad request', details: exception.response[:body].to_s)
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def customer_id_endpoint(customer_id)
|
70
|
+
"/v1/customers/#{customer_id}"
|
71
|
+
end
|
72
|
+
|
73
|
+
def customer_endpoint
|
74
|
+
'/v1/customers'
|
75
|
+
end
|
76
|
+
|
77
|
+
def customers_search_endpoint
|
78
|
+
'/v1/customers/search'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday/request_id'
|
4
|
+
require 'faraday_middleware'
|
5
|
+
require 'mercadopago/active_support/deep_symbolize_keys'
|
6
|
+
|
7
|
+
module MercadoPago
|
8
|
+
class Base
|
9
|
+
using SymbolizeHelper
|
10
|
+
attr_reader :access_token
|
11
|
+
|
12
|
+
def initialize(access_token: '', sandbox: true)
|
13
|
+
@access_token = access_token
|
14
|
+
@sandbox = sandbox
|
15
|
+
end
|
16
|
+
|
17
|
+
def service_url
|
18
|
+
raise NotImplementedError
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def connection
|
24
|
+
@connection ||= Faraday.new(service_url) do |config|
|
25
|
+
config.request :json
|
26
|
+
config.response :raise_error
|
27
|
+
config.response :json, content_type: /\bjson$/
|
28
|
+
config.use :instrumentation
|
29
|
+
config.options[:timeout] = 10
|
30
|
+
config.use Faraday::RequestId
|
31
|
+
config.adapter Faraday.default_adapter
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def process_response(response)
|
36
|
+
if response.success?
|
37
|
+
body = response.body
|
38
|
+
if body.empty?
|
39
|
+
{}
|
40
|
+
elsif body.is_a?(Array)
|
41
|
+
body.map(&:deep_symbolize_keys)
|
42
|
+
else
|
43
|
+
body.deep_symbolize_keys
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mercadopago/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'mercadopago-ruby'
|
8
|
+
spec.version = MercadoPago::Version
|
9
|
+
spec.authors = ['Nardo Nykolyszyn']
|
10
|
+
spec.email = ['devpolish@protonmail.com']
|
11
|
+
spec.summary = %q{ Mercado Pago gem. }
|
12
|
+
spec.description = %q{ A Ruby interface to the Mercado Pago API. }
|
13
|
+
spec.homepage = 'https://github.com/devpolish/mercadopago-ruby'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = %w(LICENSE.txt README.md Rakefile mercadopago-ruby.gemspec)
|
17
|
+
spec.files += Dir.glob('lib/**/*.rb')
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = Dir.glob('test/**/*')
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
spec.required_rubygems_version = '>= 1.3.5'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
24
|
+
spec.add_development_dependency 'rake', '~> 0'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.3.0'
|
26
|
+
|
27
|
+
spec.add_dependency 'faraday', '~> 0.9.0'
|
28
|
+
spec.add_dependency 'faraday_middleware'
|
29
|
+
spec.add_dependency 'request_id'
|
30
|
+
spec.add_dependency 'json'
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mercadopago-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.10.9
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nardo Nykolyszyn
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-12-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.3.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.3.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: faraday
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.9.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.9.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: faraday_middleware
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: request_id
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: json
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: " A Ruby interface to the Mercado Pago API. "
|
112
|
+
email:
|
113
|
+
- devpolish@protonmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- LICENSE.txt
|
119
|
+
- README.md
|
120
|
+
- Rakefile
|
121
|
+
- lib/mercadopago.rb
|
122
|
+
- lib/mercadopago/active_support/deep_symbolize_keys.rb
|
123
|
+
- lib/mercadopago/api.rb
|
124
|
+
- lib/mercadopago/api/cards.rb
|
125
|
+
- lib/mercadopago/api/clients.rb
|
126
|
+
- lib/mercadopago/base.rb
|
127
|
+
- lib/mercadopago/version.rb
|
128
|
+
- mercadopago-ruby.gemspec
|
129
|
+
homepage: https://github.com/devpolish/mercadopago-ruby
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
metadata: {}
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: 1.3.5
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 2.7.7
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: Mercado Pago gem.
|
153
|
+
test_files: []
|