mercadopago-rb 0.1.5 → 0.1.6

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: 32c3e27bcee654d524f3d6d17d37ae348587e508
4
- data.tar.gz: 05f4460791423426f78de7e3fe40ffc0f6dba547
3
+ metadata.gz: b2afbf6c2d0e14b92baffabb9a40e9bc1a469bc1
4
+ data.tar.gz: c13ab7ec97dd9bd9fc71a65e57b046cae95be1ec
5
5
  SHA512:
6
- metadata.gz: b3e8f3749a5b2226e56f6faa3fc08cc381f1815a3ce1b4e0dd41e4fa8eb7f5948c581b5c7167396098e2f15d95e1236222f10526f7dfde1c270bb0732edafd22
7
- data.tar.gz: 371d7aa266d6ea6bf044f506e0363b89c072758cddd7dfdeeee2bde6b350977c223ec6dc04f2121047d1bd0bba650b7eac93f3f606b93f0f07198d0d71a025d0
6
+ metadata.gz: 79325d8bea4f96d2f1e525e082944243695245a4bc91663aa98d640597b25ba316df7674fb604c6fa8f35417efbb0034977f3f07f890fb0136af5e1ef2633903
7
+ data.tar.gz: e9720f661158d1f5a19846619cba6381a1ffb989728caef58ea1b64489e13275470c6774f0bd4413c85abca7109116375408efe01cc617c4127284a34d05f334
data/.travis.yml CHANGED
@@ -4,3 +4,9 @@ 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
data/README.md CHANGED
@@ -9,7 +9,7 @@ mercadopago-rb is an object-oriented adapter that facilitates the usage of Merca
9
9
  You can add it to your Gemfile with:
10
10
 
11
11
  ```ruby
12
- gem 'mercadopago-rb'
12
+ gem 'mercadopago-rb', require: 'mercadopago'
13
13
  ```
14
14
 
15
15
  And then execute:
@@ -0,0 +1,30 @@
1
+ module Mercadopago
2
+ class Response
3
+ attr_reader :status, :response, :hash
4
+
5
+ def initialize(status, response)
6
+ @status = status
7
+ @response = response
8
+ end
9
+
10
+ def [](attr)
11
+ to_h[attr]
12
+ end
13
+
14
+ def to_h
15
+ @hash ||= {status: status, response: response}
16
+ end
17
+
18
+ def method_missing(name, *args, &block)
19
+ if response.has_key?(name) || response.has_key?(name.to_s)
20
+ response[name] || response[name.to_s]
21
+ else
22
+ super
23
+ end
24
+ end
25
+
26
+ def respond_to?(name, include_private = false)
27
+ response.has_key?(name.to_sym) || response.has_key?(name.to_s) || super
28
+ end
29
+ end
30
+ end
@@ -2,6 +2,7 @@ require 'uri'
2
2
  require 'net/https'
3
3
  require 'json'
4
4
  require 'mercadopago/config'
5
+ require 'mercadopago/response'
5
6
 
6
7
  module Mercadopago
7
8
  class RestClient
@@ -55,10 +56,7 @@ module Mercadopago
55
56
 
56
57
  def request(method, uri, params, content_type, data = {})
57
58
  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
- }
59
+ Response.new(api_result.code, JSON.parse(api_result.body))
62
60
  end
63
61
 
64
62
  private
@@ -1,3 +1,3 @@
1
1
  module Mercadopago
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Mercadopago::Response" do
4
+ let(:status) { "200" }
5
+ let(:response) { {:id => 1234} }
6
+ let(:response_object) { Mercadopago::Response.new(status, response) }
7
+
8
+ describe 'response' do
9
+ context 'when sended status to response_object' do
10
+ it { expect(response_object.status).to eq(status) }
11
+ end
12
+
13
+ context 'when sended response to response_object' do
14
+ it { expect(response_object.response).to eq(response) }
15
+ end
16
+
17
+ context 'when sended method to response_object and response contains method name' do
18
+ it { expect(response_object.respond_to?(:id)).to be_truthy }
19
+ end
20
+
21
+ context 'when sended method to response_object and response contains method name' do
22
+ it { expect(response_object.id).to eq(response[:id]) }
23
+ end
24
+ end
25
+ end
@@ -2,6 +2,10 @@ 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) { "{}" }
8
+
5
9
  before(:each) do
6
10
  Mercadopago.configure do |config|
7
11
  config.access_token = 'foo_bar_access_token'
@@ -13,23 +17,23 @@ describe "Mercadopago::RestClient" do
13
17
  context 'when API endpoint\'s call response is ok' do
14
18
  before do
15
19
  http_stub = double
16
- allow(http_stub).to receive(:code).and_return("200")
17
- allow(http_stub).to receive(:body).and_return("{}")
20
+ allow(http_stub).to receive(:code).and_return(status_ok)
21
+ allow(http_stub).to receive(:body).and_return(empty_string_hash)
18
22
  allow(rest_client.http).to receive(:send_request) do |arg1, arg2, arg3, arg4|
19
23
  end.and_return(http_stub)
20
24
  end
21
- it { expect(rest_client.get("/v1/payments")[:status]).to eq("200") }
25
+ it { expect(rest_client.get("/v1/payments")[:status]).to eq(status_ok) }
22
26
  end
23
27
 
24
28
  context 'when API endpoint\'s call response is a bad request' do
25
29
  before do
26
30
  http_stub = double
27
- allow(http_stub).to receive(:code).and_return("400")
28
- allow(http_stub).to receive(:body).and_return("{}")
31
+ allow(http_stub).to receive(:code).and_return(status_error)
32
+ allow(http_stub).to receive(:body).and_return(empty_string_hash)
29
33
  allow(rest_client.http).to receive(:send_request) do |arg1, arg2, arg3, arg4|
30
34
  end.and_return(http_stub)
31
35
  end
32
- it { expect(rest_client.get("/v1/payments")[:status]).to eq("400") }
36
+ it { expect(rest_client.get("/v1/payments")[:status]).to eq(status_error) }
33
37
  end
34
38
  end
35
39
  end
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.5
4
+ version: 0.1.6
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-28 00:00:00.000000000 Z
11
+ date: 2016-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -84,6 +84,7 @@ files:
84
84
  - lib/mercadopago/errors/credential_not_found.rb
85
85
  - lib/mercadopago/errors/endpoint.rb
86
86
  - lib/mercadopago/errors/no_environment.rb
87
+ - lib/mercadopago/response.rb
87
88
  - lib/mercadopago/rest_client.rb
88
89
  - lib/mercadopago/version.rb
89
90
  - mercadopago.gemspec
@@ -91,6 +92,7 @@ files:
91
92
  - spec/mercadopago_spec.rb
92
93
  - spec/payment_methods_spec.rb
93
94
  - spec/payment_spec.rb
95
+ - spec/response_spec.rb
94
96
  - spec/rest_client_spec.rb
95
97
  - spec/spec_helper.rb
96
98
  homepage: https://github.com/fedebonisconti/mercadopago
@@ -118,3 +120,4 @@ signing_key:
118
120
  specification_version: 4
119
121
  summary: Object-oriented wrapper for mercadopago's API.
120
122
  test_files: []
123
+ has_rdoc: