Skip to content

Commit

Permalink
Getting Heroku vars for develop.
Browse files Browse the repository at this point in the history
  • Loading branch information
kripy committed Aug 20, 2013
1 parent f62070f commit b1e4890
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ gem "unicorn"
gem "sinatra"
gem "sinatra-support", require: "sinatra/support"
gem "sinatra-assetpack", :require => "sinatra/assetpack"
gem "ruroku"

gem "coffee-script"
gem "compass"
gem "compass-h5bp"
gem "mustache"
gem "httparty"
gem "json"
22 changes: 22 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (3.2.13)
i18n (= 0.6.1)
multi_json (~> 1.0)
backports (3.3.3)
chunky_png (1.2.8)
coffee-script (2.2.0)
coffee-script-source
Expand All @@ -12,18 +16,31 @@ GEM
sass (~> 3.1)
compass-h5bp (0.1.1)
compass
descendants_tracker (0.0.1)
excon (0.25.1)
execjs (1.4.0)
multi_json (~> 1.0)
fssm (0.2.10)
heroku-api (0.3.13)
excon (~> 0.25.0)
httparty (0.11.0)
multi_json (~> 1.0)
multi_xml (>= 0.5.2)
i18n (0.6.1)
jsmin (1.0.1)
json (1.8.0)
kgio (2.7.4)
multi_json (1.7.7)
multi_xml (0.5.3)
mustache (0.99.4)
rack (1.2.2)
rack-test (0.6.2)
rack (>= 1.0)
raindrops (0.10.0)
ruroku (0.0.3)
activesupport (~> 3.2.5)
heroku-api (~> 0.2)
virtus (~> 0.5)
sass (3.2.9)
sinatra (1.2.6)
rack (~> 1.1)
Expand All @@ -40,6 +57,9 @@ GEM
kgio (~> 2.6)
rack
raindrops (~> 0.7)
virtus (0.5.5)
backports (~> 3.3)
descendants_tracker (~> 0.0.1)

PLATFORMS
ruby
Expand All @@ -48,8 +68,10 @@ DEPENDENCIES
coffee-script
compass
compass-h5bp
httparty
json
mustache
ruroku
sinatra
sinatra-assetpack
sinatra-support
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ You'll need to create an ```.env``` file in the root directory of the project fo

```
YSN_ROUTE=switch
YSN_ANSWER=NO
YSN_APP_NAME=boiling-meadow-1520
YSN_APP_KEY=XXX
```

Now fire it up:
Expand Down
29 changes: 18 additions & 11 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
require "sinatra/support"
require "mustache/sinatra"
require "json"
require "httparty"
require "base64"

class App < Sinatra::Base
base = File.dirname(__FILE__)
set :root, base

app_json = "#{base}/app/result.json"

register Sinatra::AssetPack
register Sinatra::CompassSupport
register Mustache::Sinatra
Expand Down Expand Up @@ -55,23 +55,30 @@ def self.get_or_post(path, opts={}, &block)

get "/" do
@page_title = "Website Name"
answer = JSON.parse(File.open(app_json).read)
@answer = answer["answer"]
@answer = ENV["YSN_ANSWER"]

mustache :index
end

# Switches between Yes / No. Handy when you're on the move.
# Email the route to yourself and keep it handy.
# Variable store in .env file.
get "/" + ENV['YSN_ROUTE'] do
answer = JSON.parse(File.open(app_json).read)
answer = answer["answer"]

get "/" + ENV["YSN_ROUTE"] do
answer = ENV["YSN_ANSWER"]

if answer == "yes"
File.open(File.open(app_json), 'w') { |file| file.write("{\"answer\": \"no\"}") }
response = HTTParty.patch("https://api.heroku.com/apps/" + ENV["YSN_APP_NAME"] + "/config-vars",
:body => { :YSN_ANSWER => "no" }.to_json,
:headers => { "Accept" => "application/vnd.heroku+json; version=3",
"Authorization" => ENV["YSN_APP_KEY"],
"Content-Type" => "application/json"})
else
File.open(File.open(app_json), 'w') { |file| file.write("{\"answer\": \"yes\"}") }
response = HTTParty.patch("https://api.heroku.com/apps/" + ENV["YSN_APP_NAME"] + "/config-vars",
:body => { :YSN_ANSWER => "yes" }.to_json,
:headers => { "Accept" => "application/vnd.heroku+json; version=3",
"Authorization" => ENV["YSN_APP_KEY"],
"Content-Type" => "application/json"})
end

mustache :index
end
end

0 comments on commit b1e4890

Please sign in to comment.