mercadolibre 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/mercadolibre/api.rb +1 -1
- data/lib/mercadolibre/core/auth.rb +6 -10
- data/lib/mercadolibre/entity/auth.rb +1 -1
- data/lib/mercadolibre/version.rb +1 -1
- data/lib/mercadolibre.rb +9 -2
- data/lib/mercadopago/api.rb +80 -0
- data/lib/mercadopago/core/auth.rb +65 -0
- data/lib/mercadopago/entity/auth.rb +21 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f42c944710411a95b35f4f68b6f6fd73e27af798
|
4
|
+
data.tar.gz: ba9a023d3863c7b4a25e7b13ec04fe69593dc4b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 380d8ba68825ba11195fa1af9dfcf3236fe421dabfe1aebc61a33154b14ca043d32d48a565a145e464b69ecb6dcef400ebeeb1cf2a8fbc77918ee50b34447f66
|
7
|
+
data.tar.gz: 1788c66f07db19a69fbe62a646f45cef3e3121895a8444423d8723306dc48ead7000a3b3e14f0a6df6c4a48d09512254f43dbe803bdba605b1aa3df740ac14c8
|
data/CHANGELOG.md
CHANGED
data/lib/mercadolibre/api.rb
CHANGED
@@ -6,11 +6,11 @@ module Mercadolibre
|
|
6
6
|
@app_key = args[:app_key]
|
7
7
|
@app_secret = args[:app_secret]
|
8
8
|
@callback_url = args[:callback_url]
|
9
|
-
@site = args[:site]
|
10
9
|
@access_token = args[:access_token]
|
11
10
|
@endpoint_url = 'https://api.mercadolibre.com'
|
12
11
|
@auth_url = 'https://auth.mercadolibre.com.ar'
|
13
12
|
@debug = args[:debug]
|
13
|
+
@site = args[:site]
|
14
14
|
end
|
15
15
|
|
16
16
|
include Mercadolibre::Core::Auth
|
@@ -22,11 +22,9 @@ module Mercadolibre
|
|
22
22
|
|
23
23
|
@access_token = response['access_token']
|
24
24
|
|
25
|
-
Mercadolibre::Entity::Auth.new({
|
26
|
-
|
27
|
-
|
28
|
-
expired_at: response['expires_in'].to_i.seconds.from_now
|
29
|
-
})
|
25
|
+
Mercadolibre::Entity::Auth.new(response.merge({
|
26
|
+
expired_at: (Time.now + response['expires_in'].to_i)
|
27
|
+
}))
|
30
28
|
end
|
31
29
|
|
32
30
|
def update_token(refresh_token)
|
@@ -39,11 +37,9 @@ module Mercadolibre
|
|
39
37
|
|
40
38
|
@access_token = response['access_token']
|
41
39
|
|
42
|
-
Mercadolibre::Entity::Auth.new({
|
43
|
-
|
44
|
-
|
45
|
-
expired_at: response['expires_in'].to_i.seconds.from_now
|
46
|
-
})
|
40
|
+
Mercadolibre::Entity::Auth.new(response.merge({
|
41
|
+
expired_at: (Time.now + response['expires_in'].to_i)
|
42
|
+
}))
|
47
43
|
end
|
48
44
|
end
|
49
45
|
end
|
data/lib/mercadolibre/version.rb
CHANGED
data/lib/mercadolibre.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "mercadolibre/version"
|
2
2
|
|
3
|
-
# entities
|
3
|
+
# mercadolibre -> entities
|
4
4
|
require "mercadolibre/entity/address"
|
5
5
|
require "mercadolibre/entity/address_agency"
|
6
6
|
require "mercadolibre/entity/answer"
|
@@ -62,7 +62,7 @@ require "mercadolibre/entity/state"
|
|
62
62
|
require "mercadolibre/entity/user"
|
63
63
|
require "mercadolibre/entity/zip_code"
|
64
64
|
|
65
|
-
# core
|
65
|
+
# mercadolibre -> core
|
66
66
|
require "mercadolibre/core/auth"
|
67
67
|
require "mercadolibre/core/categories_and_listings"
|
68
68
|
require "mercadolibre/core/items_and_searches"
|
@@ -73,6 +73,13 @@ require "mercadolibre/core/questions"
|
|
73
73
|
require "mercadolibre/core/users"
|
74
74
|
require "mercadolibre/api"
|
75
75
|
|
76
|
+
# mercadopago -< entities
|
77
|
+
require "mercadopago/entity/auth"
|
78
|
+
|
79
|
+
# mercadopago -< core
|
80
|
+
require "mercadopago/core/auth"
|
81
|
+
require "mercadopago/api"
|
82
|
+
|
76
83
|
# dependencies
|
77
84
|
require 'rest-client'
|
78
85
|
require 'singleton'
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module Mercadopago
|
2
|
+
class Api
|
3
|
+
attr_accessor :access_token
|
4
|
+
|
5
|
+
def initialize(args={})
|
6
|
+
@app_key = args[:app_key]
|
7
|
+
@app_secret = args[:app_secret]
|
8
|
+
@callback_url = args[:callback_url]
|
9
|
+
@access_token = args[:access_token]
|
10
|
+
@endpoint_url = 'https://api.mercadopago.com'
|
11
|
+
@auth_url = 'https://auth.mercadolibre.com.ar'
|
12
|
+
@debug = args[:debug]
|
13
|
+
end
|
14
|
+
|
15
|
+
include Mercadopago::Core::Auth
|
16
|
+
include Mercadolibre::Core::Payments
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def get_request(action, params={}, headers={})
|
21
|
+
begin
|
22
|
+
parse_response(RestClient.get("#{@endpoint_url}#{action}", {params: params}.merge(headers)))
|
23
|
+
rescue => e
|
24
|
+
parse_response(e.response)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def post_request(action, params={}, headers={})
|
29
|
+
begin
|
30
|
+
parse_response(RestClient.post("#{@endpoint_url}#{action}", params, headers))
|
31
|
+
rescue => e
|
32
|
+
parse_response(e.response)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def put_request(action, params={}, headers={})
|
37
|
+
begin
|
38
|
+
parse_response(RestClient.put("#{@endpoint_url}#{action}", params, headers))
|
39
|
+
rescue => e
|
40
|
+
parse_response(e.response)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def patch_request(action, params={}, headers={})
|
45
|
+
begin
|
46
|
+
parse_response(RestClient.patch("#{@endpoint_url}#{action}", params, headers))
|
47
|
+
rescue => e
|
48
|
+
parse_response(e.response)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def head_request(action, params={})
|
53
|
+
begin
|
54
|
+
parse_response(RestClient.head("#{@endpoint_url}#{action}", params))
|
55
|
+
rescue => e
|
56
|
+
parse_response(e.response)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def delete_request(action, params={})
|
61
|
+
begin
|
62
|
+
parse_response(RestClient.delete("#{@endpoint_url}#{action}", params))
|
63
|
+
rescue => e
|
64
|
+
parse_response(e.response)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def parse_response(response)
|
69
|
+
result = {
|
70
|
+
headers: response.headers,
|
71
|
+
body: (JSON.parse(response.body) rescue response.body),
|
72
|
+
status_code: response.code
|
73
|
+
}
|
74
|
+
|
75
|
+
p "DEBUG: #{result}" if @debug
|
76
|
+
|
77
|
+
result
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Mercadopago
|
2
|
+
module Core
|
3
|
+
module Auth
|
4
|
+
def authenticate_url
|
5
|
+
get_attrs = {
|
6
|
+
response_type: 'code',
|
7
|
+
client_id: @app_key,
|
8
|
+
redirect_uri: CGI.escape(@callback_url)
|
9
|
+
}.map { |k,v| "#{k}=#{v}" }.join('&')
|
10
|
+
|
11
|
+
"#{@auth_url}/authorization?#{get_attrs}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def authenticate(auth_code)
|
15
|
+
response = post_request('/oauth/token', {
|
16
|
+
grant_type: 'authorization_code',
|
17
|
+
client_id: @app_key,
|
18
|
+
client_secret: @app_secret,
|
19
|
+
code: auth_code,
|
20
|
+
redirect_uri: @callback_url
|
21
|
+
})[:body]
|
22
|
+
|
23
|
+
@access_token = response['access_token']
|
24
|
+
|
25
|
+
Mercadopago::Entity::Auth.new(response.merge({
|
26
|
+
expired_at: (Time.now + response['expires_in'].to_i)
|
27
|
+
}))
|
28
|
+
end
|
29
|
+
|
30
|
+
def update_token(refresh_token)
|
31
|
+
response = post_request('/oauth/token', {
|
32
|
+
grant_type: 'refresh_token',
|
33
|
+
client_id: @app_key,
|
34
|
+
client_secret: @app_secret,
|
35
|
+
refresh_token: refresh_token
|
36
|
+
})[:body]
|
37
|
+
|
38
|
+
@access_token = response['access_token']
|
39
|
+
|
40
|
+
Mercadopago::Entity::Auth.new(response.merge({
|
41
|
+
expired_at: (Time.now + response['expires_in'].to_i)
|
42
|
+
}))
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_token
|
46
|
+
headers = {
|
47
|
+
content_type: 'application/x-www-form-urlencoded',
|
48
|
+
accept: :json
|
49
|
+
}
|
50
|
+
|
51
|
+
response = post_request('/oauth/token', {
|
52
|
+
grant_type: 'client_credentials',
|
53
|
+
client_id: @app_key,
|
54
|
+
client_secret: @app_secret
|
55
|
+
}, headers)[:body]
|
56
|
+
|
57
|
+
@access_token = response['access_token']
|
58
|
+
|
59
|
+
Mercadopago::Entity::Auth.new(response.merge({
|
60
|
+
expired_at: (Time.now + response['expires_in'].to_i)
|
61
|
+
}))
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Mercadopago
|
2
|
+
module Entity
|
3
|
+
class Auth
|
4
|
+
def self.attr_list
|
5
|
+
[:access_token, :refresh_token, :live_mode, :user_id, :token_type, :scope, :expires_in, :expired_at]
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_reader *attr_list
|
9
|
+
|
10
|
+
def initialize(attributes={})
|
11
|
+
attributes.each do |k, v|
|
12
|
+
self.send("#{k}=", v) if self.respond_to?(k)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_writer *attr_list
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mercadolibre
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matias Hick
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -133,6 +133,9 @@ files:
|
|
133
133
|
- lib/mercadolibre/entity/user.rb
|
134
134
|
- lib/mercadolibre/entity/zip_code.rb
|
135
135
|
- lib/mercadolibre/version.rb
|
136
|
+
- lib/mercadopago/api.rb
|
137
|
+
- lib/mercadopago/core/auth.rb
|
138
|
+
- lib/mercadopago/entity/auth.rb
|
136
139
|
homepage: https://github.com/unformattmh/mercadolibre
|
137
140
|
licenses:
|
138
141
|
- MIT
|