Skip to content
master
Switch branches/tags
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
doc
 
 
 
 
 
 
 
 
 
 

README.md

easypost-clj

A simple Clojure library for interacting with Easypost's shipping API.

Install

Add easypost-clj to project.clj in your Leiningen project. Click here to get the newest version.

Usage

Easypost-clj is an early-stage library for interfacing with Easypost's elegant shipping API. The library currently supports:

  1. Creating records representing Easypost objects, and POST'ing them to Easypost's API.
  2. Buying shipping labels and batch shipping labels.

easypost-clj.core

Easypost-clj's functionality roughly corresponds to the tutorials found in Easypost's Getting Started Guide.

Require the core library, and make sure you have an Easypost API token handy:

(require '[easypost-clj.core :as ep])

(def token "your API key here")

Addresses

Create addresses.

(def from (ep/address {:company "Banzai, Inc."
                       :street1 "2545 N. Canyon Rd."
                       :street2 "Ste. 210"
                       :city "Provo"
                       :state "UT"
                       :zip "84604"
                       :phone "888.822.6924"}))
(ep/create! from token)

Verify addresses. Easypost lets you verify addresses you've already created with an ID. Easypost-clj, however, only supports the Easypost's stateless verification:

(def token "abcd123")
(ep/verify (ep/address {:street1 "159 W 100 S"
                        :city "Springville"
                        :state "Utah"
                        :zip "84663"}) token)

Parcels

(def parcel (ep/parcel {:length 9
                        :width 6
                        :height 2
                        :weight 10}))
(ep/create! parcel token)

Shipments

Three API methods for shipments: show, create!, and buy!. buy! takes three arguments: a Shipment, a Rate, and your token.

(def shipment (-> (ep/shipment {:to_address to
                                :from_address from
                                :parcel parcel})
                  (ep/create! token))

(ep/fetch shipment token)

(def rates (:rates shipment))

(ep/buy! shipment (first rates) token))

Batches

(def batch (ep/batch {:shipments [shipment]}))
(ep/create! batch token)

;; Wait, wait, wait for webhook...

(ep/buy! batch token)

;; Wait, wait, wait for webhook...

(ep/labels! batch token "zpl") ; The file format is optional. Omitting the argument defaults to "pdf".

easypost-clj.webhooks

The easypost-clj.webhooks namespace provides a few convenience methods for handling Easypost Webhook requests.

;; Make sure your request has been converted from string based keys to keywords.
;; If you're using Ring, you should be able to transparently pass the full
;; request into the `event` constructor function.

(def req {:id ...
          :result {:object "Tracker"
                   ...}})

(event req)

=> (easypost_clj.webhooks.Event {...})

License

Copyright © 2014 Banzai, Inc.

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

About

Clojure library for interfacing with Easypost's API

Resources

License

Releases

No releases published

Packages

No packages published