Git Product home page Git Product logo

happi's Introduction

Happi

Happi is a collection of Elixir structs for the Heroku API useable by the Napper JSON REST API application.

Happi defines structs for most of the resources exposed by Heroku's API, and a few functions that are above and beyond the standard list/get/update/delete REST API calls.

Installation

First, add Happi to your mix.exs dependencies:

def deps do
  [{:happi, git: "https://github.com/chloeandisabel/happi.git"}]
end

and run $ mix deps.get. Now, list the :happi application as your application dependency:

def applications do
  [applications: [:happi]]
end

Configuration

We need to tell Napper about Heroku's API. This example assumes you've defined the environment variable HEROKU_API_KEY.

config :napper,
  url: "https://api.heroku.com",
  auth: "Bearer #{System.get_env("HEROKU_API_KEY")}",
  accept: "application/vnd.heroku+json; version=3",
  master_prefix: "/apps",
  master_id: "prod-app-name"

Using Happi

First we create a client using Napper.

iex> client = Napper.api_client

The example config file defines a default application name and the "/apps" endpoint. This means that when using a struct such as Dyno you don't need to specify the application name. To use a different application, specify a different master_id in the client.

iex> client = Napper.api_client(master_id: "another_app_name")
iex> # ...or, starting with an existing client...
iex> client = %{client | master_id: "another_app_name"}

Heroku's API limits the number of requests per hour. Let's find out how many we have left:

iex> client |> Happi.rate_limit
#=> 2400

What applications do we have?

iex> client |> Happi.Heroku.App.list
#=> [%Happi.Heroku.App{...}]

What dynos does the "app-name-or-id" application have?

iex> ds = client |> Happi.Heroku.Dyno.list
#=> [%Happi.Heroku.Dyno{...}]

Note that we didn't have to pass in the app name or id because it's already stored in the client.

Let's fetch a particular dyno.

iex> d = client |> Happi.Heroku.Dyno.get("my_dyno_name.1")
#=> %Happi.Heroku.Dyno{...}

How many dynos do we have of each dyno type? (You could also use the Formation resource to get this information a bit easier.)

iex> client |> Happi.Heroku.Dyno.list |> Enum.reduce(%{}, fn d, m ->
...>   Map.put(m, d.type, Map.get(m, d.type, 0) + 1)
...> end
#=> %{"web" => 2, "schedule_workers" => 2, "others" => 5}

To Do

  • More endpoints
  • Handle 206 Partial Content responses
  • Handle ranges (name, order, max, etc.) in get requests

happi's People

Watchers

 avatar  avatar  avatar  avatar

Forkers

jimm

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.