easypost v0.0.1 Easypost.Client
Access the Easypost API from Elixir using maps and returning structs
##Usage:
First, add test key to config/test.exs and config/dev.exs like this:
config :myapp, easypost_endpoint: "https://api.easypost.com/v2/",
easypost_key: "your test key"
Then, define endpoint and key in module where you will use client:
defmodule Myapp.Mymodule do
use Easypost.Client, endpoint: Application.get_env(:my_app, :easypost_endpoint),
key: Application.get_env(:my_app, :easypost_key)
#omitted...
end
Now, the Easypost functions will be available in the module:
#add an address by passing a binary key map (%{"foo" => "bar"})
create_address(user.address)
#gets a list of rate quotes
create_shipment(shipment)
#purchases a shipment using a particular rate where shipment_id is the Easypost id of the shipment and rate is a map containing the Easypost rate id
buy_shipment(shipment_id, rate)
#creates a batch of shipments using either a list of previously created shipping ids or shipment maps
create_batch(shipments)
All functions return either {:ok, (struct)} or {:error, %Easypost.Error{}}, so you should pattern match the result of the functions. For more examples, see tests.