MercadoLibre's Ruby SDK
This is the official Ruby SDK for MercadoLibre's Platform.
Installation
Build a gem
To build the Ruby code into a gem:
gem build meli.gemspec
Then either install the gem locally:
gem install ./meli-3.0.0.gem
(for development, run gem install --dev ./meli-3.0.0.gem
to install the development dependencies)
or publish the gem to a gem hosting service, e.g. RubyGems.
Finally add this to the Gemfile:
gem 'meli', '~> 3.0.0'
Install from Git
If the Ruby gem is hosted at a git repository: https://github.com/mercadolibre/ruby-sdk, then add the following in the Gemfile:
gem 'meli', :git => 'https://github.com/mercadolibre/ruby-sdk.git'
Include the Ruby code directly
Include the Ruby code directly using -I
as follows:
ruby -Ilib script.rb
Usage
# Auth URLs Options by country
# 1: "https://auth.mercadolibre.com.ar"
# 2: "https://auth.mercadolivre.com.br"
# 3: "https://auth.mercadolibre.com.co"
# 4: "https://auth.mercadolibre.com.mx"
# 5: "https://auth.mercadolibre.com.uy"
# 6: "https://auth.mercadolibre.cl"
# 7: "https://auth.mercadolibre.com.cr"
# 8: "https://auth.mercadolibre.com.ec"
# 9: "https://auth.mercadolibre.com.ve"
# 10: "https://auth.mercadolibre.com.pa"
# 11: "https://auth.mercadolibre.com.pe"
# 12: "https://auth.mercadolibre.com.do"
# 13: "https://auth.mercadolibre.com.bo"
# 14: "https://auth.mercadolibre.com.py"
# For example in your app
client_id = "Your client_id"
redirect_uri = "Your redirect uri"
puts '<a href= "https://auth.mercadolibre.com.ar/authorization?response_type=code&client_id=' + client_id + '&redirect_uri=' + redirect_uri +'">'+ Authenticate + '</a>'
his will give you the url to redirect the user. You need to specify a callback url which will be the one that the user will redirected after a successfull authrization process.
Once the user is redirected to your callback url, you'll receive in the query string, a parameter named code. You'll need this for the second part of the process
Examples for OAuth - get token
# load the gem
require 'Meli'
api_instance = Meli::OAuth20Api.new
opts = {
grant_type: 'authorization_code', # String |
client_id: 'client_id_example', # String |
client_secret: 'client_secret_example', # String |
redirect_uri: 'redirect_uri_example', # String |
code: 'code_example', # String |
refresh_token: 'refresh_token_example' # String |
}
begin
#Request Access Token
result = api_instance.get_token(opts)
p result
rescue Meli::ApiError => e
puts "Exception when calling OAuth20Api->get_token: #{e}"
end
Example using the RestClient with a POST Item
# load the gem
require 'Meli'
api_instance = Meli::RestClientApi.new
resource = 'resource_example' # String |
access_token = 'access_token_example' # String |
body = nil # Object |
begin
#Resourse path POST
result = api_instance.resource_post(resource, access_token, body)
p result
rescue Meli::ApiError => e
puts "Exception when calling RestClientApi->resource_post: #{e}"
end