README.md

# Mercadolibre

**TODO: Add description**

## Installation

  1. Add `mercadolibre` to your list of dependencies in `mix.exs`:

```elixir
def deps do
  [{:mercadolibre, "~> 0.1.0"}]
end
```

## Usage

You can do api calls by using one of two methods:
```elixir
Mercadolibre.request(:get, "/items/MLA123", [])
```

Which simply does a request and returns a tuple like
```elixir
{http_status_code, decoded_response}
```

Or
```elixir
Mercadolibre.authenticated_request(client_pid, verb, url, data)`
```

which requires the pid of a Mercadolibre.Authentication process.

## Example

```elixir
{: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.

```elixir
# ...
children = [
  worker(Authentication, [%{client_id: "x", client_secret: "y"}, name: :account1])
]
supervise(children, strategy: one_for_one)
```

and then:
```elixir
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:
```elixir
{: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")
...
```