Project

easy_meli

0.0
A long-lived project that still receives updates
A simple gem to work with MercadoLibre's API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 2.3.6
~> 5.18
>= 0
>= 0
~> 13.0

Runtime

~> 0.6.0
~> 0.24
~> 3.4.2
 Project Readme

EasyMeli

A simple gem to access low level MercadoLibre api calls. This is the draft beta version.

Installation

Add this line to your application's Gemfile:

gem 'easy_meli'

And then execute:

$ bundle

Or install it yourself as:

$ gem install easy_meli

Usage

Configure the gem with your application ID and secret key.

EasyMeli.configure do |config|
  config.application_id = 'your_app_id'
  config.secret_key = 'your_secret_key'
end

To get the authorization url that the end-user uses to give your app authorization to access MercadoLibre on your part call the authorization_url with the desired country and the url to redirect to in order to complete the authorization.

EasyMeli.authorization_url('MX', 'your_redirect_url')

Once MercadoLibre calls your redirect url you can get a refresh token by calling

response = EasyMeli.create_token('the_code_in_the_redirect', 'the_same_redirect_url_as_above')

This will return a response object with a json body that you can easily access via response.to_h.

If you want to refresh the token call

access_token = EasyMeli.access_token('a_refresh_token')

Once you can have an access token you can create a client and call the supported http verb methods.

client = EasyMeli.api_client(access_token: access_token)

client.get(path, query: { a: 1 })
client.post(path, query: { a: 1 }, body: { b: 1 })
client.put(path, query: { a: 1 }, body: { b: 1 })
client.delete(path, query: { a: 1 })

You can also pass a logger to any methods that make remote calls. The logger class must implement a log method which will be called with the HTTParty response for every remote request sent.

EasyMeli.create_token('the_code_in_the_redirect', 'the_same_redirect_url_as_above', logger: my_logger)
EasyMeli.api_client(access_token: access_token, logger: my_logger)

Example of how to retrieve a user profile

EasyMeli.configure do |config|
  config.application_id = "your_app_id"
  config.secret_key = "your_secret_key"
end

client = EasyMeli.api_client(access_token: access_token)
response = client.get('/users/me')

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/easybroker/easy_meli.

License

The gem is available as open source under the terms of the MIT License.