Code Monkey home page Code Monkey logo

easypost-elixir's Introduction

CircleCI

Elixir Easypost Client

# config/config.exs

config :my_app, easypost_endpoint: "https://api.easypost.com/v2/",
                easypost_key: "##############",
                easypost_test_key: "############"

Use

defmodule MyApp.Somemodule do
  use Easypost.Client, endpoint: Application.get_env(:my_app, :easypost_endpoint),                    
 					   key: Application.get_env(:my_app, :easypost_key)

  #add an address, where address is map like %{"name" => "something", "street1" => "something" ...etc} returned map has easypost address id
  def add_shipping_address(user) do
    user =  create_address(user.address)
    #result is {:ok, %Easypost.User{key: "val", key: "val"}}
    or
    {:error, %Easypost.Error{code: "code", message: "message", errors: []}}
  end

  #get quotes for shipment when shipment is map like %{"from_address" => %{"name" => "something"}, "to_address" => %{"name" => "something"}, "parcel" => %{"width" => "something"}}
  def get_shipping_quotes(shipment) do
    shipment =  create_shipment(shipment)
    #result is {:ok, %Easypost.Shipment{key: "val", key: "val"}}
    or
    {:error, %Easypost.Error{code: "code", message: "message", errors: []}}
  end

  #returns postage label with print url when rate is like: %{"id" => "id of chosen rate"}
  def ship_package(shipment_id, rate) do
    shipment =  buy_shipment(shipment_id, rate)
    #result is {:ok, %Easypost.Shipment{key: "val", key: "val"}}
    or
    {:error, %Easypost.Error{code: "code", message: "message", errors: []}}
  end

  #create batch shipment when shipments is list like [%{"from_address" => %{"name" => "something"}, "to_address" => %{"name" => "something"}, "parcel" => %{"width" => "something"}}, %{"id" => "12346"}]
  def start_batch(shipments) do
    batch =  create_batch(shipments)
    #result is {:ok, %Easypost.Batch{key: "val", key: "val"}}
    or
    {:error, %Easypost.Error{code: "code", message: "message", errors: []}}
  end
end

Please visit easypost api documentation to see requred fields for each request at https://www.easypost.com/docs/api

Installation

def deps do
  [{:easypost, "~> 0.0.1"}]
end

Notes

  • Some tests are disabled and can only be used in production mode. You may remove the the exlusion in the unit test and use your production API, but remember this will create shipments you probably don't want!

  • The "insure shipment" test occasionally fails with the code SHIPMENT.POSTAGE.REQUIRED. I think this has to do with the timing of the requests in the test suite.

easypost-elixir's People

Contributors

dania02525 avatar kevinkoltz avatar mahcloud avatar

Watchers

James Cloos avatar  avatar

Forkers

mazz

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.