Git Product home page Git Product logo

ex_easypost's Introduction

EasyPost for Elixir

Installation

ex_easypost is publbished on Hex. Add it to your list of dependencies in mix.exs:

defp deps do
  [
    { :ex_easypost, "~> 3.0" }
  ]
end

ex_easypost requires you to provide an HTTP client and a JSON codec. hackney and jason are used by default. If you wish to use these defaults you will need add hackney and jason as dependencies as well.

Usage

You can send a request to the EasyPost API by building an EasyPost.Operation struct and passing it as the first argument to EasyPost.request/2 and passing a configuration map as the second argument.

Example

iex> params
...> |> EasyPost.Shipment.create()
...> |> EasyPost.request(%{ api_key: "xxx" })
{ :ok, %EasyPost.Response{} }

An EasyPost.Operation struct can be built using either a resource module (e.g. EasyPost.Shipment) or by building the struct manually. EasyPost.Operation contains fields :method, :params and :path.

  • :method - an HTTP method and can be one of :delete, :get, :post or :put
  • :params - data to be sent as the body of the request
  • :path - the path to send the request to. Must begin with a forward slash.

Configuration

  • :api_key - API key used when making authenticated requests
  • :host - HTTP host to make requests to. Defaults to api.easypost.com.
  • :http_client - the HTTP client used for making requests. Defaults to EasyPost.HTTP.Hackney.
  • :http_client_opts - additional options passed to :http_client. Defaults to [].
  • :json_codec - codec for encoding and decoding JSON payloads. Defaults to Jason.
  • :path - path to prefix on each request. Defaults to /v2.
  • :port - the HTTP port used when making a request
  • :protocol - the HTTP protocol used when making a request. Defaults to https.
  • :retry - whether to automatically retry failed API calls. May be true or false. Defaults to false.
  • :retry_opts - options used when performing retries. Defaults to [].
    • :max_attempts - the maximum number of retry attempts. Defaults to 3.

ex_easypost's People

Contributors

anthonator avatar dependabot[bot] avatar markglenn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.