mercadopago-rb 0.1.4 → 0.1.5
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 +4 -4
- data/.gitignore +10 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +35 -0
- data/README.md +30 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/mercadopago.rb +18 -0
- data/lib/mercadopago/client.rb +37 -0
- data/lib/mercadopago/config.rb +42 -0
- data/lib/mercadopago/config/env.rb +33 -0
- data/lib/mercadopago/config/locales/es.yml +0 -0
- data/lib/mercadopago/endpoint.rb +3 -0
- data/lib/mercadopago/endpoint/base.rb +23 -0
- data/lib/mercadopago/endpoint/payment.rb +29 -0
- data/lib/mercadopago/endpoint/payment_methods.rb +12 -0
- data/lib/mercadopago/errors.rb +4 -0
- data/lib/mercadopago/errors/bad_request.rb +6 -0
- data/lib/mercadopago/errors/credential_not_found.rb +6 -0
- data/lib/mercadopago/errors/endpoint.rb +6 -0
- data/lib/mercadopago/errors/no_environment.rb +6 -0
- data/lib/mercadopago/rest_client.rb +84 -0
- data/lib/mercadopago/version.rb +3 -0
- data/mercadopago.gemspec +26 -0
- data/spec/config/config_spec.rb +42 -0
- data/spec/mercadopago_spec.rb +9 -0
- data/spec/payment_methods_spec.rb +21 -0
- data/spec/payment_spec.rb +19 -0
- data/spec/rest_client_spec.rb +35 -0
- data/spec/spec_helper.rb +2 -0
- metadata +38 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 32c3e27bcee654d524f3d6d17d37ae348587e508
|
|
4
|
+
data.tar.gz: 05f4460791423426f78de7e3fe40ffc0f6dba547
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b3e8f3749a5b2226e56f6faa3fc08cc381f1815a3ce1b4e0dd41e4fa8eb7f5948c581b5c7167396098e2f15d95e1236222f10526f7dfde1c270bb0732edafd22
|
|
7
|
+
data.tar.gz: 371d7aa266d6ea6bf044f506e0363b89c072758cddd7dfdeeee2bde6b350977c223ec6dc04f2121047d1bd0bba650b7eac93f3f606b93f0f07198d0d71a025d0
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Contributor Code of Conduct
|
|
2
|
+
|
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
|
7
|
+
|
|
8
|
+
We are committed to making participation in this project a harassment-free
|
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
|
12
|
+
|
|
13
|
+
Examples of unacceptable behavior by participants include:
|
|
14
|
+
|
|
15
|
+
* The use of sexualized language or imagery
|
|
16
|
+
* Personal attacks
|
|
17
|
+
* Trolling or insulting/derogatory comments
|
|
18
|
+
* Public or private harassment
|
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
|
20
|
+
addresses, without explicit permission
|
|
21
|
+
* Other unethical or unprofessional conduct
|
|
22
|
+
|
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
27
|
+
threatening, offensive, or harmful.
|
|
28
|
+
|
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
|
32
|
+
Conduct may be permanently removed from the project team.
|
|
33
|
+
|
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
|
35
|
+
when an individual is representing the project or its community.
|
|
36
|
+
|
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
38
|
+
reported by contacting a project maintainer at fedebonisconti26@gmail.com. All
|
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
|
42
|
+
incident.
|
|
43
|
+
|
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
45
|
+
version 1.3.0, available at
|
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
|
47
|
+
|
|
48
|
+
[homepage]: http://contributor-covenant.org
|
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
mercadopago-rb (0.1.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
diff-lcs (1.2.5)
|
|
10
|
+
rake (10.5.0)
|
|
11
|
+
rspec (3.4.0)
|
|
12
|
+
rspec-core (~> 3.4.0)
|
|
13
|
+
rspec-expectations (~> 3.4.0)
|
|
14
|
+
rspec-mocks (~> 3.4.0)
|
|
15
|
+
rspec-core (3.4.4)
|
|
16
|
+
rspec-support (~> 3.4.0)
|
|
17
|
+
rspec-expectations (3.4.0)
|
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
19
|
+
rspec-support (~> 3.4.0)
|
|
20
|
+
rspec-mocks (3.4.1)
|
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
22
|
+
rspec-support (~> 3.4.0)
|
|
23
|
+
rspec-support (3.4.1)
|
|
24
|
+
|
|
25
|
+
PLATFORMS
|
|
26
|
+
ruby
|
|
27
|
+
|
|
28
|
+
DEPENDENCIES
|
|
29
|
+
bundler (~> 1.11)
|
|
30
|
+
mercadopago-rb!
|
|
31
|
+
rake (~> 10.0)
|
|
32
|
+
rspec (~> 3.0)
|
|
33
|
+
|
|
34
|
+
BUNDLED WITH
|
|
35
|
+
1.11.2
|
data/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Mercadopago
|
|
2
|
+
|
|
3
|
+
[](https://travis-ci.org/fedebonisconti/mercadopago)
|
|
4
|
+
|
|
5
|
+
mercadopago-rb is an object-oriented adapter that facilitates the usage of Mercadopago's API.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
You can add it to your Gemfile with:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'mercadopago-rb'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install mercadopago-rb
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
Checkout the [wiki](https://github.com/fedebonisconti/mercadopago/wiki).
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## Contributing
|
|
29
|
+
|
|
30
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fedebonisconti/mercadopago. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "mercadopago"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/mercadopago.rb
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require "mercadopago/version"
|
|
2
|
+
require "mercadopago/client"
|
|
3
|
+
require "mercadopago/errors"
|
|
4
|
+
require "mercadopago/endpoint"
|
|
5
|
+
require "mercadopago/config"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
module Mercadopago
|
|
9
|
+
extend self
|
|
10
|
+
|
|
11
|
+
def configure
|
|
12
|
+
yield Config
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def client(opts = {})
|
|
16
|
+
Client.new(opts)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require "forwardable"
|
|
2
|
+
require "mercadopago/rest_client"
|
|
3
|
+
require "mercadopago/endpoint"
|
|
4
|
+
|
|
5
|
+
module Mercadopago
|
|
6
|
+
class Client
|
|
7
|
+
extend Forwardable
|
|
8
|
+
|
|
9
|
+
attr_accessor :rest_client
|
|
10
|
+
|
|
11
|
+
def_delegators :@rest_client, :access_token, :public_key, :get, :post,
|
|
12
|
+
:put, :delete
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def initialize(opts = {})
|
|
16
|
+
@rest_client = RestClient.new(opts)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# This method provides interaction with payment's API endpoint
|
|
20
|
+
def payment(method, data = {})
|
|
21
|
+
call_endpoint(Endpoint::Payment, method, data)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# This method provides interaction with payment methods's API endpoint
|
|
25
|
+
def payment_methods(method, data = {})
|
|
26
|
+
call_endpoint(Endpoint::PaymentMethods, method, data)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
def call_endpoint(klazz, method, data)
|
|
32
|
+
op = klazz.new(rest_client, data)
|
|
33
|
+
op.public_send(method) if op.respond_to?(method) ||
|
|
34
|
+
raise(Errors::Endpoint.new('Invalid endpoint method'))
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require 'mercadopago/config/env'
|
|
2
|
+
|
|
3
|
+
module Mercadopago
|
|
4
|
+
module Config
|
|
5
|
+
extend self
|
|
6
|
+
attr_accessor :access_token, :public_key, :sandbox_mode
|
|
7
|
+
attr_reader :secrets
|
|
8
|
+
|
|
9
|
+
def access_token
|
|
10
|
+
@access_token ||= secrets('access_token') ||
|
|
11
|
+
ENV['MERCADOPAGO_ACCESS_TOKEN'] ||
|
|
12
|
+
raise(Errors::CredentialNotFound.new('Access Token not found'))
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def public_key
|
|
16
|
+
@public_key ||= secrets('public_key') ||
|
|
17
|
+
ENV['MERCADOPAGO_PUBLIC_KEY'] ||
|
|
18
|
+
raise(Errors::CredentialNotFound.new('Public Key not found'))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def sandbox_mode
|
|
22
|
+
if @sandbox_mode.nil?
|
|
23
|
+
@sandbox_mode = secrets('sandbox_mode') ||
|
|
24
|
+
ENV['MERCADOPAGO_LIVE_MODE'] || true
|
|
25
|
+
end
|
|
26
|
+
@sandbox_mode
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def reset!
|
|
30
|
+
@access_token = (@public_key = (@sandbox_mode = nil))
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
def secrets(key = nil)
|
|
35
|
+
if defined?(::Rails)
|
|
36
|
+
@secrets ||= ::Rails.application.secrets.mercadopago
|
|
37
|
+
(@secrets && key && @secrets[key]) || @secrets
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Mercadopago
|
|
2
|
+
module Config
|
|
3
|
+
module Env
|
|
4
|
+
extend self
|
|
5
|
+
|
|
6
|
+
def environment
|
|
7
|
+
return Rails.env if defined?(Rails) && Rails.respond_to?(:env)
|
|
8
|
+
return Sinatra::Base.environment.to_s if defined?(Sinatra)
|
|
9
|
+
ENV['MERCADOPAGO_ENV'] || ENV['ENVIRONMENT'] ||
|
|
10
|
+
raise(Errors::NoEnvironment.new)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def development?
|
|
14
|
+
(defined?(Rails) && Rails.env.development?) ||
|
|
15
|
+
ENV['ENVIRONMENT'] == "development" ||
|
|
16
|
+
ENV['MERCADOPAGO_ENV'] == "development"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test?
|
|
20
|
+
(defined?(Rails) && Rails.env.test?) ||
|
|
21
|
+
ENV['ENVIRONMENT'] == "test" ||
|
|
22
|
+
ENV['MERCADOPAGO_ENV'] == "test"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def production?
|
|
26
|
+
(defined?(Rails) && Rails.env.production?) ||
|
|
27
|
+
ENV['ENVIRONMENT'] == "production" ||
|
|
28
|
+
ENV['MERCADOPAGO_ENV'] == "production"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Mercadopago
|
|
2
|
+
module Endpoint
|
|
3
|
+
class Base
|
|
4
|
+
attr_reader :data, :rest_client
|
|
5
|
+
|
|
6
|
+
def initialize(rest_client, data)
|
|
7
|
+
@rest_client = rest_client
|
|
8
|
+
@data = data
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def to_s
|
|
12
|
+
self.class.to_s.split("::").last.downcase
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
protected
|
|
16
|
+
def member_endpoint
|
|
17
|
+
id = data[:id] || raise(StandardError.new('Unknown ID'))
|
|
18
|
+
"#{self.class::ENDPOINT}/#{id}"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Mercadopago
|
|
2
|
+
module Endpoint
|
|
3
|
+
class Payment < Base
|
|
4
|
+
ENDPOINT = "/payments".freeze
|
|
5
|
+
|
|
6
|
+
def get
|
|
7
|
+
endpoint = data[:id] ? member_endpoint : ENDPOINT
|
|
8
|
+
rest_client.get(endpoint)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def create
|
|
12
|
+
rest_client.post(ENDPOINT, data)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def refund
|
|
16
|
+
rest_client.put(member_endpoint + "/refunds")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def cancel
|
|
20
|
+
rest_client.put(member_endpoint, {status: "cancelled"})
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def search
|
|
24
|
+
rest_client.get(ENDPOINT + "/search", data[:filters])
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
require 'uri'
|
|
2
|
+
require 'net/https'
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'mercadopago/config'
|
|
5
|
+
|
|
6
|
+
module Mercadopago
|
|
7
|
+
class RestClient
|
|
8
|
+
attr_accessor :http, :api_base_uri
|
|
9
|
+
attr_reader :sandbox_mode, :access_token, :public_key,
|
|
10
|
+
:client_secret, :query
|
|
11
|
+
|
|
12
|
+
MIME_JSON = 'application/json'.freeze
|
|
13
|
+
MIME_FORM = 'application/x-www-form-urlencoded'.freeze
|
|
14
|
+
API_BASE_URL = 'https://api.mercadopago.com'.freeze
|
|
15
|
+
MERCADO_PAGO_VERSION = '0.3.4'.freeze
|
|
16
|
+
API_VERSION = '/v1'.freeze
|
|
17
|
+
GET = "GET".freeze
|
|
18
|
+
POST = "POST".freeze
|
|
19
|
+
PUT = "PUT".freeze
|
|
20
|
+
DELETE = "DELETE".freeze
|
|
21
|
+
|
|
22
|
+
def initialize(opts = {})
|
|
23
|
+
@access_token = opts[:access_token] || Config.access_token
|
|
24
|
+
@public_key = opts[:public_key] || Config.public_key
|
|
25
|
+
@sandbox_mode = opts[:sandbox_mode] || Config.sandbox_mode || true
|
|
26
|
+
@http = set_http
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def generate_uri(uri, params = {})
|
|
30
|
+
params['access_token'] = access_token
|
|
31
|
+
@query ||= (uri.include?("?") ? "&" : "?") +
|
|
32
|
+
URI.encode_www_form(params)
|
|
33
|
+
API_VERSION + uri + @query
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def get(uri, params = {}, content_type = MIME_JSON)
|
|
37
|
+
request(GET, uri, params, content_type)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def post(uri, data, params = {}, content_type = MIME_JSON)
|
|
41
|
+
request(POST, uri, params, content_type, data)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def put(uri, data = nil, params = {}, content_type = MIME_JSON)
|
|
45
|
+
request(PUT, uri, params, content_type, data)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def delete(uri, params = {}, content_type = MIME_JSON)
|
|
49
|
+
request(DELETE, uri, params, content_type)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def api_base_uri
|
|
53
|
+
@api_base_uri ||= URI.parse(API_BASE_URL)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def request(method, uri, params, content_type, data = {})
|
|
57
|
+
api_result = http.send_request(method, generate_uri(uri, params), data.to_json, headers(content_type))
|
|
58
|
+
{
|
|
59
|
+
status: api_result.code,
|
|
60
|
+
response: JSON.parse(api_result.body)
|
|
61
|
+
}
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
private
|
|
65
|
+
def headers(content_type)
|
|
66
|
+
{
|
|
67
|
+
'User-Agent' => "MercadoPago Ruby SDK v" + MERCADO_PAGO_VERSION,
|
|
68
|
+
'Content-type' => content_type,
|
|
69
|
+
'Accept' => MIME_JSON
|
|
70
|
+
}
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def set_http
|
|
74
|
+
http = Net::HTTP.new(api_base_uri.host, api_base_uri.port)
|
|
75
|
+
if api_base_uri.scheme == "https"
|
|
76
|
+
http.use_ssl = true
|
|
77
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
78
|
+
# TODO: review this option
|
|
79
|
+
# @http.ssl_version = OpenSSL::SSL::OP_NO_SSLv3
|
|
80
|
+
end
|
|
81
|
+
http
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
data/mercadopago.gemspec
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
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-rb"
|
|
8
|
+
spec.version = Mercadopago::VERSION
|
|
9
|
+
spec.authors = ["Federico Bonisconti"]
|
|
10
|
+
spec.email = ["fedebonisconti26@gmail.com"]
|
|
11
|
+
spec.licenses = ["MIT"]
|
|
12
|
+
spec.summary = %Q{Object-oriented wrapper for mercadopago's API.}
|
|
13
|
+
spec.description = %Q{Object-oriented wrapper for mercadopago's API.}
|
|
14
|
+
spec.homepage = "https://github.com/fedebonisconti/mercadopago"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files`.split("\n")
|
|
18
|
+
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
19
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
20
|
+
spec.require_paths = ["lib"]
|
|
21
|
+
spec.required_ruby_version = '>= 2.1.0'
|
|
22
|
+
|
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
26
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Mercadopago::Config, specific_specs: true do
|
|
4
|
+
subject(:config){ Mercadopago::Config }
|
|
5
|
+
|
|
6
|
+
describe 'access_token' do
|
|
7
|
+
context 'when is not set' do
|
|
8
|
+
before { Mercadopago::Config.reset! }
|
|
9
|
+
it { expect{ config.access_token }.to raise_error(Mercadopago::Errors::CredentialNotFound) }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
context 'configure via config block' do
|
|
13
|
+
let(:access_token){ 'foo_bar_access_token' }
|
|
14
|
+
|
|
15
|
+
before do
|
|
16
|
+
Mercadopago.configure{|c| c.access_token = access_token }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it { expect(config.access_token).to be(access_token) }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe 'public_key' do
|
|
25
|
+
|
|
26
|
+
context 'when is not set' do
|
|
27
|
+
before { Mercadopago::Config.reset! }
|
|
28
|
+
it{ expect{ config.public_key }.to raise_error(Mercadopago::Errors::CredentialNotFound) }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context 'configure via config block' do
|
|
32
|
+
let(:public_key){ 'foo_bar_public_key' }
|
|
33
|
+
|
|
34
|
+
before do
|
|
35
|
+
Mercadopago.configure{|c| c.public_key = public_key }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it{ expect(config.public_key).to be(public_key) }
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "Mercadopago::Client" do
|
|
4
|
+
|
|
5
|
+
let(:client) { Mercadopago.client }
|
|
6
|
+
let(:api_endpoint) { :some_invalid_endpoint }
|
|
7
|
+
before(:each) do
|
|
8
|
+
Mercadopago.configure do |config|
|
|
9
|
+
config.access_token = 'foo_bar_access_token'
|
|
10
|
+
config.public_key = 'foo_bar_public_key'
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe 'payment_methods' do
|
|
15
|
+
context 'when API endpoint is invalid' do
|
|
16
|
+
it { expect{ client.payment_methods(:api_endpoint)}.to \
|
|
17
|
+
raise_error(Mercadopago::Errors::Endpoint)}
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "Mercadopago::Client" do
|
|
4
|
+
let(:client) { Mercadopago.client }
|
|
5
|
+
let(:api_endpoint) { :some_invalid_endpoint }
|
|
6
|
+
before(:each) do
|
|
7
|
+
Mercadopago.configure do |config|
|
|
8
|
+
config.access_token = 'foo_bar_access_token'
|
|
9
|
+
config.public_key = 'foo_bar_public_key'
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe 'payment' do
|
|
14
|
+
context 'when API endpoint is invalid' do
|
|
15
|
+
it { expect{ client.payment(:api_endpoint)}.to raise_error(Mercadopago::Errors::Endpoint)}
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "Mercadopago::RestClient" do
|
|
4
|
+
let(:rest_client) { Mercadopago.client.rest_client }
|
|
5
|
+
before(:each) do
|
|
6
|
+
Mercadopago.configure do |config|
|
|
7
|
+
config.access_token = 'foo_bar_access_token'
|
|
8
|
+
config.public_key = 'foo_bar_public_key'
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe 'rest_client' do
|
|
13
|
+
context 'when API endpoint\'s call response is ok' do
|
|
14
|
+
before do
|
|
15
|
+
http_stub = double
|
|
16
|
+
allow(http_stub).to receive(:code).and_return("200")
|
|
17
|
+
allow(http_stub).to receive(:body).and_return("{}")
|
|
18
|
+
allow(rest_client.http).to receive(:send_request) do |arg1, arg2, arg3, arg4|
|
|
19
|
+
end.and_return(http_stub)
|
|
20
|
+
end
|
|
21
|
+
it { expect(rest_client.get("/v1/payments")[:status]).to eq("200") }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
context 'when API endpoint\'s call response is a bad request' do
|
|
25
|
+
before do
|
|
26
|
+
http_stub = double
|
|
27
|
+
allow(http_stub).to receive(:code).and_return("400")
|
|
28
|
+
allow(http_stub).to receive(:body).and_return("{}")
|
|
29
|
+
allow(rest_client.http).to receive(:send_request) do |arg1, arg2, arg3, arg4|
|
|
30
|
+
end.and_return(http_stub)
|
|
31
|
+
end
|
|
32
|
+
it { expect(rest_client.get("/v1/payments")[:status]).to eq("400") }
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mercadopago-rb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Federico Bonisconti
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-06-
|
|
11
|
+
date: 2016-06-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -55,10 +55,44 @@ dependencies:
|
|
|
55
55
|
description: Object-oriented wrapper for mercadopago's API.
|
|
56
56
|
email:
|
|
57
57
|
- fedebonisconti26@gmail.com
|
|
58
|
-
executables:
|
|
58
|
+
executables:
|
|
59
|
+
- console
|
|
60
|
+
- setup
|
|
59
61
|
extensions: []
|
|
60
62
|
extra_rdoc_files: []
|
|
61
|
-
files:
|
|
63
|
+
files:
|
|
64
|
+
- ".gitignore"
|
|
65
|
+
- ".travis.yml"
|
|
66
|
+
- CODE_OF_CONDUCT.md
|
|
67
|
+
- Gemfile
|
|
68
|
+
- Gemfile.lock
|
|
69
|
+
- README.md
|
|
70
|
+
- Rakefile
|
|
71
|
+
- bin/console
|
|
72
|
+
- bin/setup
|
|
73
|
+
- lib/mercadopago.rb
|
|
74
|
+
- lib/mercadopago/client.rb
|
|
75
|
+
- lib/mercadopago/config.rb
|
|
76
|
+
- lib/mercadopago/config/env.rb
|
|
77
|
+
- lib/mercadopago/config/locales/es.yml
|
|
78
|
+
- lib/mercadopago/endpoint.rb
|
|
79
|
+
- lib/mercadopago/endpoint/base.rb
|
|
80
|
+
- lib/mercadopago/endpoint/payment.rb
|
|
81
|
+
- lib/mercadopago/endpoint/payment_methods.rb
|
|
82
|
+
- lib/mercadopago/errors.rb
|
|
83
|
+
- lib/mercadopago/errors/bad_request.rb
|
|
84
|
+
- lib/mercadopago/errors/credential_not_found.rb
|
|
85
|
+
- lib/mercadopago/errors/endpoint.rb
|
|
86
|
+
- lib/mercadopago/errors/no_environment.rb
|
|
87
|
+
- lib/mercadopago/rest_client.rb
|
|
88
|
+
- lib/mercadopago/version.rb
|
|
89
|
+
- mercadopago.gemspec
|
|
90
|
+
- spec/config/config_spec.rb
|
|
91
|
+
- spec/mercadopago_spec.rb
|
|
92
|
+
- spec/payment_methods_spec.rb
|
|
93
|
+
- spec/payment_spec.rb
|
|
94
|
+
- spec/rest_client_spec.rb
|
|
95
|
+
- spec/spec_helper.rb
|
|
62
96
|
homepage: https://github.com/fedebonisconti/mercadopago
|
|
63
97
|
licenses:
|
|
64
98
|
- MIT
|
|
@@ -67,7 +101,6 @@ post_install_message:
|
|
|
67
101
|
rdoc_options: []
|
|
68
102
|
require_paths:
|
|
69
103
|
- lib
|
|
70
|
-
- lib/mercadopago.rb
|
|
71
104
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
105
|
requirements:
|
|
73
106
|
- - ">="
|
|
@@ -85,4 +118,3 @@ signing_key:
|
|
|
85
118
|
specification_version: 4
|
|
86
119
|
summary: Object-oriented wrapper for mercadopago's API.
|
|
87
120
|
test_files: []
|
|
88
|
-
has_rdoc:
|