ex_easypost v1.0.2 ExEasyPost

ExEasyPost

Build Status HexDocs

ExEasyPost is an Elixir client library for the EasyPost API.

Features

  1. Support for all EasyPost resources
  2. Minimal configuration. Choose your favorite HTTP client and JSON codec.
  3. Support for per-request configuration

Getting Started

ExEasyPost allows you to choose which HTTP client and JSON codec you would like to use. ExEasyPost supports :httpoison (HTTP client) and :poison (JSON codec) out of the box.

defp deps do
  [
    {:ex_easypost, "~> 1.0"},
    {:httpoison, "~> 0.13"},
    {:poison, "~> 3.1"}
  ]
end

Usage

ExEasyPost.Address.find("adr_a6fd5dd822c94bdfa1e3f2d28a4dbf9c")
|> ExEasyPost.request()

ExEasyPost will return {:ok, response} on success and {:error, reason} on failure.

Configuration

ExEasyPost allows you to provide configuration as part of your application config or on a per-request basis.

Application configuration

config :ex_easypost,
  api_key: "xxx"

Per-request configuration

config = %{api_key: "xxx"}

ExEasyPost.Address.find("adr_a6fd5dd822c94bdfa1e3f2d28a4dbf9c")
|> ExEasyPost.request(config)

Configuration options

  • :api_key - your EasyPost API key
  • :host - host to make requests to (default: api.easypost.com)
  • :http_client - HTTP client used to make requests (default: :httpoison)
  • :http_opts - configuration options passed to the api client
  • :json_parser - codec used to encode and decode JSON (default: :poison)
  • :path - URI path to make requests to (default: v2)
  • :port - HTTP port to make requests to
  • :protocol - HTTP protocol to use when making requests (default: https)

Supported Resources

Link to this section Summary

Functions

Perform a request against the EasyPost API

Link to this section Functions

Link to this function request(operation, overrides \\ [])
request(ExEasyPost.Operation.t(), Keyword.t()) ::
  {:ok, term()} | {:error, term()}

Perform a request against the EasyPost API.

Build an operation from an EasyPost resource, and then pass it to this function to execute it.

If you want to build an operation manually, see: ExEasyPost.Operation

This functions takes an optional second parameter of configuration overrides. This is useful if you want to have certain configuration changed on a per request basis.