mercadopago-rb 0.1.7 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8548490d8d225a618f65bda7bd8e9dfd651bead1
4
- data.tar.gz: c50298287d02294b84bbad3434f3623f266f2b9f
3
+ metadata.gz: dab77349ceb162c112466e1edc44ca0e882eb81c
4
+ data.tar.gz: 971c2b88b0796ff50ff6f65fd3e3aab17818df22
5
5
  SHA512:
6
- metadata.gz: 0b5ec17109934e9cb184bba01c298edbeedc1cfb21223fd22b9ed13b0f486fd5edbd28c259e8c0a49cd8000837212aa077df5715be89e2f2e0be1fd2af514ed3
7
- data.tar.gz: 8fff268f191d919bcc7d36995f119862aadfb25295fa04cc4ae67d0ca906c3f331972f7ca2b3686530143cee788ab87ec2252d072e0a24810408b9a2e4c85acf
6
+ metadata.gz: 477f98911cd8c4cb07eb9497c703cac41c00293c69513747af1aec78bd81512657530fad45f4227d1eb0f0861e9776e527d4b95c7e316bd94b34e96afaa925e4
7
+ data.tar.gz: e35f6265cd7719ebc114757a0d7cdfb6c4f545b4505b03b93a28f09d1a2c0e6a04715fd4185f386064542b0e5060b33fedf21a87f50ec2831a91ca95f6ecb3fd
@@ -4,9 +4,3 @@ rvm:
4
4
  - 2.1.10
5
5
  - 2.2.5
6
6
  - 2.3.1
7
-
8
- deploy:
9
- provider: rubygems
10
- api_key: "Trgb2IN5vfA9XLej/l7ywrY0JtrL1s/UeofMXrpLgF3Or/u0Xa0IjHifXGiaLwGLX1OuxspSZMvjyhs7b3ntSgezquW7o+en/DDaGptt45HO7JLvXIkyYqPGzagBoGRpUhZ61CZyDvK+GEqme0euJgcrvxXlz4o8OD7ySBUiJ7oWoG2BoPNfx8Z6yffJF8DB0qjw575Y8kWOafLqn9VPdKEKBcFP93PulmStGDe10Bff9k0Rpy3+HfGWMxz4uWEYRgO97UrzGoR/0XVtACVEJB4jlEUe72FnEFpiuM2mcBSH/oM9ycyC9b9tMpzqT2btmKlavdE+YEoEXpBwQee6XcDbSvrHV6eKKlg1+ZYxUcyQUDJ0It5aeFxCyS4xToxhBtP/Ch0RmaeLstntbZEu6Ba8nqyV3uzYAZ0u1SW/G4yjSH5wNYwsWj4fCmAMO1qcI2+11zrA4mVrZVs8tbIl0Bxni+gl9DGKtcqINJ6+Ue7i2m2pLmdnhD3YPjf3sCUVzpB3msmiIIBkAFXxS2yg4a4f0NKigpgWicKgfZa6ge9HJryacsha4x7VCh5BrJ7PD5AavBdNX0yUXU4GI9Qiw2AscLedJY57imLkfPIUV5bmbMwv5sIVI1/HG/wmGYe0uyxKd/hmxD7VLnG7Jxz6pcWHtp3ii2x3+gORKaAOC84="
11
- gem: mercadopago
12
- gemspec: mercadopago.gemspec
@@ -1,12 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mercadopago-rb (0.1.0)
4
+ mercadopago-rb (0.1.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ addressable (2.5.0)
10
+ public_suffix (~> 2.0, >= 2.0.2)
11
+ crack (0.4.3)
12
+ safe_yaml (~> 1.0.0)
9
13
  diff-lcs (1.2.5)
14
+ hashdiff (0.3.1)
15
+ public_suffix (2.0.4)
10
16
  rake (10.5.0)
11
17
  rspec (3.4.0)
12
18
  rspec-core (~> 3.4.0)
@@ -21,6 +27,11 @@ GEM
21
27
  diff-lcs (>= 1.2.0, < 2.0)
22
28
  rspec-support (~> 3.4.0)
23
29
  rspec-support (3.4.1)
30
+ safe_yaml (1.0.4)
31
+ webmock (2.3.1)
32
+ addressable (>= 2.3.6)
33
+ crack (>= 0.3.2)
34
+ hashdiff
24
35
 
25
36
  PLATFORMS
26
37
  ruby
@@ -30,6 +41,7 @@ DEPENDENCIES
30
41
  mercadopago-rb!
31
42
  rake (~> 10.0)
32
43
  rspec (~> 3.0)
44
+ webmock (~> 2.3.1)
33
45
 
34
46
  BUNDLED WITH
35
- 1.11.2
47
+ 1.13.6
@@ -11,7 +11,6 @@ module Mercadopago
11
11
  def_delegators :@rest_client, :access_token, :public_key, :get, :post,
12
12
  :put, :delete
13
13
 
14
-
15
14
  def initialize(opts = {})
16
15
  @rest_client = RestClient.new(opts)
17
16
  end
@@ -26,6 +25,14 @@ module Mercadopago
26
25
  call_endpoint(Endpoint::PaymentMethods, method, data)
27
26
  end
28
27
 
28
+ # This method provides interaction with preference method's API endpoint
29
+ def preference(method, data = {})
30
+ call_endpoint(Endpoint::Preference, method, data)
31
+ end
32
+
33
+ def card_token(method, data = {})
34
+ call_endpoint(Endpoint::CardToken, method, data)
35
+ end
29
36
 
30
37
  private
31
38
  def call_endpoint(klazz, method, data)
@@ -4,7 +4,6 @@ module Mercadopago
4
4
  module Config
5
5
  extend self
6
6
  attr_accessor :access_token, :public_key
7
- attr_reader :secrets
8
7
 
9
8
  def access_token
10
9
  @access_token ||= secrets('access_token') ||
@@ -1,3 +1,5 @@
1
1
  require 'mercadopago/endpoint/base'
2
2
  require 'mercadopago/endpoint/payment_methods'
3
3
  require 'mercadopago/endpoint/payment'
4
+ require 'mercadopago/endpoint/preference'
5
+ require 'mercadopago/endpoint/card_token'
@@ -17,7 +17,6 @@ module Mercadopago
17
17
  id = data[:id] || raise(StandardError.new('Unknown ID'))
18
18
  "#{self.class::ENDPOINT}/#{id}"
19
19
  end
20
-
21
20
  end
22
21
  end
23
22
  end
@@ -0,0 +1,19 @@
1
+ module Mercadopago
2
+ module Endpoint
3
+ class CardToken < Base
4
+ ENDPOINT = "/v1/card_tokens".freeze
5
+
6
+ def get
7
+ rest_client.get(member_endpoint)
8
+ end
9
+
10
+ def create
11
+ rest_client.post(ENDPOINT, data)
12
+ end
13
+
14
+ def update
15
+ rest_client.put(ENDPOINT, data)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,7 +1,7 @@
1
1
  module Mercadopago
2
2
  module Endpoint
3
3
  class Payment < Base
4
- ENDPOINT = "/payments".freeze
4
+ ENDPOINT = "/v1/payments".freeze
5
5
 
6
6
  def get
7
7
  endpoint = data[:id] ? member_endpoint : ENDPOINT
@@ -23,7 +23,6 @@ module Mercadopago
23
23
  def search
24
24
  rest_client.get(ENDPOINT + "/search", data[:filters])
25
25
  end
26
-
27
26
  end
28
27
  end
29
28
  end
@@ -1,12 +1,11 @@
1
1
  module Mercadopago
2
2
  module Endpoint
3
3
  class PaymentMethods < Base
4
- ENDPOINT = "/payment_methods".freeze
4
+ ENDPOINT = "/v1/payment_methods".freeze
5
5
 
6
6
  def get
7
7
  rest_client.get(ENDPOINT)
8
8
  end
9
-
10
9
  end
11
10
  end
12
11
  end
@@ -0,0 +1,19 @@
1
+ module Mercadopago
2
+ module Endpoint
3
+ class Preference < Base
4
+ ENDPOINT = "/checkout/preferences".freeze
5
+
6
+ def get
7
+ rest_client.get(member_endpoint)
8
+ end
9
+
10
+ def create
11
+ rest_client.post(ENDPOINT, data)
12
+ end
13
+
14
+ def update
15
+ rest_client.update(ENDPOINT, data)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,6 +1,6 @@
1
1
  module Mercadopago
2
2
  class Response
3
- attr_reader :status, :response, :hash
3
+ attr_reader :status, :response, :content
4
4
 
5
5
  def initialize(status, response)
6
6
  @status = status
@@ -8,11 +8,11 @@ module Mercadopago
8
8
  end
9
9
 
10
10
  def [](attr)
11
- hash[attr]
11
+ content[attr]
12
12
  end
13
13
 
14
14
  def to_h
15
- hash
15
+ content
16
16
  end
17
17
 
18
18
  def method_missing(name, *args, &block)
@@ -27,8 +27,8 @@ module Mercadopago
27
27
  response.has_key?(name.to_sym) || response.has_key?(name.to_s) || super
28
28
  end
29
29
 
30
- def hash
31
- @hash ||= {status: status, response: response}
30
+ def content
31
+ @content ||= {status: status, response: response}
32
32
  end
33
33
  end
34
34
  end
@@ -7,17 +7,12 @@ require 'mercadopago/response'
7
7
  module Mercadopago
8
8
  class RestClient
9
9
  attr_accessor :http, :api_base_uri
10
- attr_reader :access_token, :public_key, :client_secret, :query
10
+ attr_reader :access_token, :public_key, :client_secret
11
11
 
12
12
  MIME_JSON = 'application/json'.freeze
13
13
  MIME_FORM = 'application/x-www-form-urlencoded'.freeze
14
14
  API_BASE_URL = 'https://api.mercadopago.com'.freeze
15
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
16
 
22
17
  def initialize(opts = {})
23
18
  @access_token = opts[:access_token] || Config.access_token
@@ -25,27 +20,27 @@ module Mercadopago
25
20
  @http = set_http
26
21
  end
27
22
 
28
- def generate_uri(uri, params = {})
23
+ def request_uri(path, params = {})
29
24
  params['access_token'] = access_token
30
- @query ||= (uri.include?("?") ? "&" : "?") +
31
- URI.encode_www_form(params)
32
- API_VERSION + uri + @query
25
+ uri = api_base_uri + path
26
+ uri.query = [uri.query, URI.encode_www_form(params)].compact.join('&')
27
+ uri.request_uri
33
28
  end
34
29
 
35
30
  def get(uri, params = {}, content_type = MIME_JSON)
36
- request(GET, uri, params, content_type)
31
+ request(Net::HTTP::Get::METHOD, uri, params, content_type)
37
32
  end
38
33
 
39
34
  def post(uri, data, params = {}, content_type = MIME_JSON)
40
- request(POST, uri, params, content_type, data)
35
+ request(Net::HTTP::Post::METHOD, uri, params, content_type, data)
41
36
  end
42
37
 
43
38
  def put(uri, data = nil, params = {}, content_type = MIME_JSON)
44
- request(PUT, uri, params, content_type, data)
39
+ request(Net::HTTP::Put::METHOD, uri, params, content_type, data)
45
40
  end
46
41
 
47
42
  def delete(uri, params = {}, content_type = MIME_JSON)
48
- request(DELETE, uri, params, content_type)
43
+ request(Net::HTTP::Delete::METHOD, uri, params, content_type)
49
44
  end
50
45
 
51
46
  def api_base_uri
@@ -53,11 +48,10 @@ module Mercadopago
53
48
  end
54
49
 
55
50
  def request(method, uri, params, content_type, data = {})
56
- api_result = http.send_request(method, generate_uri(uri, params), data.to_json, headers(content_type))
51
+ api_result = http.send_request(method, request_uri(uri, params), data.to_json, headers(content_type))
57
52
  Response.new(api_result.code, JSON.parse(api_result.body))
58
53
  end
59
54
 
60
- private
61
55
  def headers(content_type)
62
56
  {
63
57
  'User-Agent' => "MercadoPago Ruby SDK v" + MERCADO_PAGO_VERSION,
@@ -66,6 +60,7 @@ module Mercadopago
66
60
  }
67
61
  end
68
62
 
63
+ private
69
64
  def set_http
70
65
  http = Net::HTTP.new(api_base_uri.host, api_base_uri.port)
71
66
  if api_base_uri.scheme == "https"
@@ -1,3 +1,3 @@
1
1
  module Mercadopago
2
- VERSION = "0.1.7"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler", "~> 1.11"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
25
  spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "webmock", "~> 2.3.1"
26
27
  end
@@ -0,0 +1,18 @@
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 'card_token' do
14
+ context 'when API endpoint is invalid' do
15
+ it { expect{ client.card_token(:api_endpoint)}.to raise_error(Mercadopago::Errors::Endpoint)}
16
+ end
17
+ end
18
+ end
@@ -14,6 +14,5 @@ describe "Mercadopago::Client" do
14
14
  context 'when API endpoint is invalid' do
15
15
  it { expect{ client.payment(:api_endpoint)}.to raise_error(Mercadopago::Errors::Endpoint)}
16
16
  end
17
-
18
17
  end
19
18
  end
@@ -0,0 +1,18 @@
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 'preference' do
14
+ context 'when API endpoint is invalid' do
15
+ it { expect{ client.preference(:api_endpoint)}.to raise_error(Mercadopago::Errors::Endpoint)}
16
+ end
17
+ end
18
+ end
@@ -4,6 +4,4 @@ describe Mercadopago do
4
4
  it 'has a version number' do
5
5
  expect(Mercadopago::VERSION).not_to be nil
6
6
  end
7
-
8
-
9
7
  end
@@ -2,9 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  describe "Mercadopago::RestClient" do
4
4
  let(:rest_client) { Mercadopago.client.rest_client }
5
- let(:status_ok) { "200" }
6
- let(:status_error) { "400" }
7
- let(:empty_string_hash) { "{}" }
5
+ let(:endpoint) { "/v1/payments" }
6
+ let(:url) { MERCADOPAGO_API + rest_client.request_uri(endpoint) }
7
+ let(:headers) { rest_client.headers(Mercadopago::RestClient::MIME_JSON) }
8
8
 
9
9
  before(:each) do
10
10
  Mercadopago.configure do |config|
@@ -15,25 +15,21 @@ describe "Mercadopago::RestClient" do
15
15
 
16
16
  describe 'rest_client' do
17
17
  context 'when API endpoint\'s call response is ok' do
18
- before do
19
- http_stub = double
20
- allow(http_stub).to receive(:code).and_return(status_ok)
21
- allow(http_stub).to receive(:body).and_return(empty_string_hash)
22
- allow(rest_client.http).to receive(:send_request) do |arg1, arg2, arg3, arg4|
23
- end.and_return(http_stub)
18
+ it do
19
+ stub_request(:get, url)
20
+ .with( :body => "{}", :headers => headers )
21
+ .to_return(:status => 200, :body => "{}", :headers => {})
22
+ expect(rest_client.get(endpoint)[:status]).to eq("200")
24
23
  end
25
- it { expect(rest_client.get("/v1/payments")[:status]).to eq(status_ok) }
26
24
  end
27
25
 
28
26
  context 'when API endpoint\'s call response is a bad request' do
29
- before do
30
- http_stub = double
31
- allow(http_stub).to receive(:code).and_return(status_error)
32
- allow(http_stub).to receive(:body).and_return(empty_string_hash)
33
- allow(rest_client.http).to receive(:send_request) do |arg1, arg2, arg3, arg4|
34
- end.and_return(http_stub)
27
+ it do
28
+ stub_request(:get, url)
29
+ .with( :body => "{}", :headers => headers )
30
+ .to_return(:status => 400, :body => "{}", :headers => {})
31
+ expect(rest_client.get(endpoint)[:status]).to eq("400")
35
32
  end
36
- it { expect(rest_client.get("/v1/payments")[:status]).to eq(status_error) }
37
33
  end
38
34
  end
39
35
  end
@@ -1,2 +1,5 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
  require 'mercadopago'
3
+ require 'webmock/rspec'
4
+
5
+ MERCADOPAGO_API = 'https://api.mercadopago.com'.freeze
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.7
4
+ version: 0.2.0
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-07-04 00:00:00.000000000 Z
11
+ date: 2016-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.3.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.3.1
55
69
  description: Object-oriented wrapper for mercadopago's API.
56
70
  email:
57
71
  - fedebonisconti26@gmail.com
@@ -77,8 +91,10 @@ files:
77
91
  - lib/mercadopago/config/locales/es.yml
78
92
  - lib/mercadopago/endpoint.rb
79
93
  - lib/mercadopago/endpoint/base.rb
94
+ - lib/mercadopago/endpoint/card_token.rb
80
95
  - lib/mercadopago/endpoint/payment.rb
81
96
  - lib/mercadopago/endpoint/payment_methods.rb
97
+ - lib/mercadopago/endpoint/preference.rb
82
98
  - lib/mercadopago/errors.rb
83
99
  - lib/mercadopago/errors/bad_request.rb
84
100
  - lib/mercadopago/errors/credential_not_found.rb
@@ -89,9 +105,11 @@ files:
89
105
  - lib/mercadopago/version.rb
90
106
  - mercadopago.gemspec
91
107
  - spec/config/config_spec.rb
108
+ - spec/mercadopago_client/card_token_spec.rb
109
+ - spec/mercadopago_client/payment_methods_spec.rb
110
+ - spec/mercadopago_client/payment_spec.rb
111
+ - spec/mercadopago_client/preference_spec.rb
92
112
  - spec/mercadopago_spec.rb
93
- - spec/payment_methods_spec.rb
94
- - spec/payment_spec.rb
95
113
  - spec/response_spec.rb
96
114
  - spec/rest_client_spec.rb
97
115
  - spec/spec_helper.rb
@@ -119,5 +137,13 @@ rubygems_version: 2.5.1
119
137
  signing_key:
120
138
  specification_version: 4
121
139
  summary: Object-oriented wrapper for mercadopago's API.
122
- test_files: []
123
- has_rdoc:
140
+ test_files:
141
+ - spec/config/config_spec.rb
142
+ - spec/mercadopago_client/card_token_spec.rb
143
+ - spec/mercadopago_client/payment_methods_spec.rb
144
+ - spec/mercadopago_client/payment_spec.rb
145
+ - spec/mercadopago_client/preference_spec.rb
146
+ - spec/mercadopago_spec.rb
147
+ - spec/response_spec.rb
148
+ - spec/rest_client_spec.rb
149
+ - spec/spec_helper.rb