Skip to content

Instantly share code, notes, and snippets.

@JohnTroony
Forked from geemus/hack-a-thon.md
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohnTroony/a9ebaf1ab83204cfe406 to your computer and use it in GitHub Desktop.
Save JohnTroony/a9ebaf1ab83204cfe406 to your computer and use it in GitHub Desktop.

API Hack-a-thon

heroku

API Team

brandur mfine pedro sclasen geemus

Platform API

stringer

Setup

git clone git://github.com/swanson/stringer.git
cd stringer
heroku create
git push heroku master

heroku config:set SECRET_TOKEN=`openssl rand -hex 20`

heroku run rake db:migrate
heroku restart

heroku addons:add scheduler
heroku addons:open scheduler

superstringer

Establish Connection

heroku = Excon.new(
  'https://api.heroku.com',
  :headers => {
    "Accept"        => "application/vnd.heroku+json; version=3",
    "Authorization" => "Basic #{[':' << password].pack('m').delete("\r\n")}",
    "Content-Type"  => "application/json"
  }
)

Create App

heroku.post(:path => "/apps")

Set SECRET_TOKEN Config Var

heroku.patch(
  :body       => { "SECRET_TOKEN" => SecureRandom.hex(20) }.to_json,
  :path       => "/apps/#{app_data['id']}/config-vars"
)

Migrate Database

run_data = JSON.parse(heroku.post(
  :body => {
    "attach"  => true,
    "command" => "rake db:migrate"
  }.to_json,
  :path => "/apps/#{app_data['id']}/dynos"
).body)
Rendezvous.start(
  :url => run_data['attach_url']
)

Restart

heroku.delete(:path => "/apps/#{app_data['id']}/dynos")

Add Scheduler

heroku.post(
  :body => { "plan" => { "name" => "scheduler:standard" } }.to_json,
  :path => "/apps/#{app_data['id']}/addons"
)

OAuth

Alpha hack-a-thon release!

Web Application Authorization

  • redirect to Heroku
  • recieve redirect back
  • convert to token

Direct Authorization

$ curl -n -X POST https://api.heroku.com/oauth/authorizations \
-H "Accept: application/vnd.heroku+json; version=3" \
-H "Content-Type: application/json" \
-d "{\"description\":\"sample authorization\"}"

log2viz

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment