Apprentice is a collection of Elixir structs for the HireFire API useable by the Napper JSON REST API application.
Apprentice defines structs for all of the resources exposed by HireFire's API.
First, add Apprentice to your mix.exs dependencies:
def deps do
[{:apprentice, git: "https://github.com/chloeandisabel/apprentice.git"}]
endand run $ mix deps.get. Now, list the :apprentice application as your
application dependency:
def applications do
[applications: [:apprentice]]
endWe need to tell Napper about HireFire's API.
config :napper,
url: "https://api.hirefire.io",
auth: "Token #{System.get_env("HIREFIRE_API_KEY")}",
accept: "application/vnd.hirefire.v1+json",
remove_wrapper: trueThat last entry tells Napper to remove the outer wrapper from HireFire responses. When asking for a list of organizations, HireFire returns
{"organizations": [...]}but Napper expects that innter array of objects. Setting remove_wrapper to
true tells Napper to strip off the outer "organizations" object, returning
only the array.
Let's try out Apprentice from within IEX.
$ iex -S mixFirst we create a client using Napper. This example assumes we've used our config file to configure Napper properly.
iex> client = Napper.api_clientWhat organizations do we have?
iex> client |> Apprentice.HireFire.Organization.list
#=> [%Apprentice.HireFire.Organization{...}]