Mercadolibre
TODO: Add description
Installation
-
Add
mercadolibreto your list of dependencies inmix.exs:
def deps do
[{:mercadolibre, "~> 0.1.0"}]
endUsage
You can do api calls by using one of two methods:
Mercadolibre.request(:get, "/items/MLA123", [])Which simply does a request and returns a tuple like
{http_status_code, decoded_response}Or
Mercadolibre.authenticated_request(client_pid, verb, url, data)`which requires the pid of a Mercadolibre.Authentication process.
Example
{:ok, auth} = Mercadolibre.Authentication.start_link(%{client_id: "x", client_secret: "y"})
Mercadolibre.authenticated_request(auth, :get, "items/MLA123")Probably you'll want a supervised Authentication process.
# ...
children = [
worker(Authentication, [%{client_id: "x", client_secret: "y"}, name: :account1])
]
supervise(children, strategy: one_for_one)and then:
Mercadolibre.authenticated_request(:account1, :post, "items", %{title: "Title", price: 10})MercadoLibre.com API
This library doesn't pretend to wrap Mercadolibre's API into nice named methods. Why? Because I don't want to have to update the Hex everytime the API changes. We are just abstracting the part of dealing with request, json or authentication. To know which url to call and which data, just read the documentation. But it's as easy as:
{:ok, account} = Mercadolibre.Authentication.start_link(credentials)
# Items
Mercadolibre.request ( :get, "items/MLA1234" )
Mercadolibre.authenticated_request(account, :post, "items", item_data)
Mercadolibre.authenticated_request(account, :put, "items/MLA123", data)
Mercadolibre.authenticated_request(account, :delete, "items/MLA123")
# Users
Mercadolibre.authenticated_request(account, :get, "users/me")
Mercadolibre.authenticated_request(account, :get, "users/1/addresses")
...