Class: Whacamole::HerokuWrapper
- Inherits:
-
Object
- Object
- Whacamole::HerokuWrapper
- Defined in:
- lib/whacamole/heroku_wrapper.rb
Constant Summary collapse
- RESTART_RATE_LIMIT =
30*60
Instance Attribute Summary collapse
-
#api_token ⇒ Object
Returns the value of attribute api_token.
-
#app_name ⇒ Object
Returns the value of attribute app_name.
Instance Method Summary collapse
- #authorization ⇒ Object
- #create_log_session ⇒ Object
-
#initialize(app_name, api_token) ⇒ HerokuWrapper
constructor
A new instance of HerokuWrapper.
- #recently_restarted?(process) ⇒ Boolean
- #restart(process) ⇒ Object
Constructor Details
#initialize(app_name, api_token) ⇒ HerokuWrapper
Returns a new instance of HerokuWrapper.
11 12 13 14 |
# File 'lib/whacamole/heroku_wrapper.rb', line 11 def initialize(app_name, api_token) self.app_name = app_name self.api_token = api_token end |
Instance Attribute Details
#api_token ⇒ Object
Returns the value of attribute api_token.
7 8 9 |
# File 'lib/whacamole/heroku_wrapper.rb', line 7 def api_token @api_token end |
#app_name ⇒ Object
Returns the value of attribute app_name.
7 8 9 |
# File 'lib/whacamole/heroku_wrapper.rb', line 7 def app_name @app_name end |
Instance Method Details
#authorization ⇒ Object
27 28 29 |
# File 'lib/whacamole/heroku_wrapper.rb', line 27 def "Basic " + Base64.encode64(":#{api_token}").gsub("\n", '') end |
#create_log_session ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/whacamole/heroku_wrapper.rb', line 16 def create_log_session uri = URI(log_sessions_url) req = Net::HTTP::Post.new(uri.path) req['Authorization'] = req['Content-type'] = content_type req['Accept'] = accept req.set_form_data({'tail' => true}) res = Net::HTTP.start(uri.host, uri.port, :use_ssl => (uri.scheme == "https")) {|http| http.request(req)} JSON.parse(res.body)['logplex_url'] end |
#recently_restarted?(process) ⇒ Boolean
46 47 48 |
# File 'lib/whacamole/heroku_wrapper.rb', line 46 def recently_restarted?(process) restarts[process] > (Time.now - RESTART_RATE_LIMIT) end |
#restart(process) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/whacamole/heroku_wrapper.rb', line 31 def restart(process) return false if recently_restarted?(process) uri = URI(dyno_url(process)) req = Net::HTTP::Delete.new(uri.path) req['Authorization'] = req['Content-type'] = content_type req['Accept'] = accept res = Net::HTTP.start(uri.host, uri.port, :use_ssl => (uri.scheme == "https")) {|http| http.request(req)} restarts[process] = Time.now true end |