Class: Escobar::Heroku::App
- Inherits:
-
Object
- Object
- Escobar::Heroku::App
- Defined in:
- lib/escobar/heroku/app.rb
Overview
Class representing a heroku application
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #build_request_for(pipeline) ⇒ Object
- #cache_key ⇒ Object
- #config_vars ⇒ Object
- #current_release_ref ⇒ Object
- #dashboard_url ⇒ Object
- #direct_to_drain? ⇒ Boolean
- #drain ⇒ Object
- #drain_token ⇒ Object
- #dynos ⇒ Object
- #heroku_drain_url_pattern ⇒ Object
- #info ⇒ Object
-
#initialize(client, id) ⇒ App
constructor
A new instance of App.
- #locked? ⇒ Boolean
- #log_drains ⇒ Object
- #log_url ⇒ Object
- #name ⇒ Object
-
#preauth(second_factor) ⇒ Object
Accepts either google authenticator or yubikey second_factor formatting.
- #releases ⇒ Object
- #releases_json ⇒ Object
Constructor Details
#initialize(client, id) ⇒ App
Returns a new instance of App.
6 7 8 9 |
# File 'lib/escobar/heroku/app.rb', line 6 def initialize(client, id) @id = id @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/escobar/heroku/app.rb', line 5 def client @client end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/escobar/heroku/app.rb', line 5 def id @id end |
Instance Method Details
#build_request_for(pipeline) ⇒ Object
80 81 82 |
# File 'lib/escobar/heroku/app.rb', line 80 def build_request_for(pipeline) Escobar::Heroku::BuildRequest.new(pipeline, id) end |
#cache_key ⇒ Object
51 52 53 |
# File 'lib/escobar/heroku/app.rb', line 51 def cache_key "escobar-app-#{id}" end |
#config_vars ⇒ Object
39 40 41 |
# File 'lib/escobar/heroku/app.rb', line 39 def config_vars @config_vars ||= Escobar::Heroku::ConfigVars.new(client, id) end |
#current_release_ref ⇒ Object
31 32 33 |
# File 'lib/escobar/heroku/app.rb', line 31 def current_release_ref releases.first.ref end |
#dashboard_url ⇒ Object
47 48 49 |
# File 'lib/escobar/heroku/app.rb', line 47 def dashboard_url "https://dashboard.heroku.com/apps/#{name}" end |
#direct_to_drain? ⇒ Boolean
68 69 70 |
# File 'lib/escobar/heroku/app.rb', line 68 def direct_to_drain? !log_drains.is_a?(Array) end |
#drain ⇒ Object
84 85 86 87 88 |
# File 'lib/escobar/heroku/app.rb', line 84 def drain @drain ||= log_drains.find do |drain| drain["url"].match(heroku_drain_url_pattern) end end |
#drain_token ⇒ Object
72 73 74 |
# File 'lib/escobar/heroku/app.rb', line 72 def drain_token @drain_token ||= drain && drain["token"] end |
#dynos ⇒ Object
35 36 37 |
# File 'lib/escobar/heroku/app.rb', line 35 def dynos @dynos ||= Escobar::Heroku::Dynos.new(client, id) end |
#heroku_drain_url_pattern ⇒ Object
90 91 92 |
# File 'lib/escobar/heroku/app.rb', line 90 def heroku_drain_url_pattern %r{forward\.log\.herokai\.com:9999|logs\.herokai\.com\/logs} end |
#info ⇒ Object
15 16 17 |
# File 'lib/escobar/heroku/app.rb', line 15 def info @info ||= heroku.get("/apps/#{id}") end |
#locked? ⇒ Boolean
60 61 62 63 64 65 66 |
# File 'lib/escobar/heroku/app.rb', line 60 def locked? response = heroku.get("/apps/#{id}/config-vars") response["id"] == "two_factor" rescue Escobar::Client::HTTPError => e response = JSON.parse(e.response.body) response["id"] == "two_factor" end |
#log_drains ⇒ Object
43 44 45 |
# File 'lib/escobar/heroku/app.rb', line 43 def log_drains @log_drains ||= heroku.get("/apps/#{id}/log-drains") end |
#log_url ⇒ Object
76 77 78 |
# File 'lib/escobar/heroku/app.rb', line 76 def log_url @log_url ||= "#{dashboard_url}/logs" end |
#name ⇒ Object
11 12 13 |
# File 'lib/escobar/heroku/app.rb', line 11 def name info["name"] end |
#preauth(second_factor) ⇒ Object
Accepts either google authenticator or yubikey second_factor formatting
56 57 58 |
# File 'lib/escobar/heroku/app.rb', line 56 def preauth(second_factor) heroku.put("/apps/#{id}/pre-authorizations", {}, second_factor).none? end |
#releases ⇒ Object
25 26 27 28 29 |
# File 'lib/escobar/heroku/app.rb', line 25 def releases @releases ||= releases_json.map do |release| Escobar::Heroku::Release.new(client, id, nil, release["id"]) end end |
#releases_json ⇒ Object
19 20 21 22 23 |
# File 'lib/escobar/heroku/app.rb', line 19 def releases_json @releases_json ||= heroku.get_range( "/apps/#{id}/releases", "version; order=desc,max=25;" ) end |