Class: PagerDuty::Agent
- Inherits:
-
Object
- Object
- PagerDuty::Agent
- Defined in:
- lib/pagerduty_tools/pagerduty.rb
Instance Attribute Summary collapse
-
#domain ⇒ Object
Returns the value of attribute domain.
Instance Method Summary collapse
- #fetch(path) ⇒ Object
-
#initialize ⇒ Agent
constructor
A new instance of Agent.
Constructor Details
#initialize ⇒ Agent
Returns a new instance of Agent.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/pagerduty_tools/pagerduty.rb', line 36 def initialize # Works around a bug in highline, producing "input stream exhausted" errors. See: # http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/939d9f86a18e6f9e/ec1c3f1921cd66ea HighLine.track_eof = false @cookie_file = File.(COOKIE_FILE) @agent = Mechanize.new find_domain end |
Instance Attribute Details
#domain ⇒ Object
Returns the value of attribute domain.
34 35 36 |
# File 'lib/pagerduty_tools/pagerduty.rb', line 34 def domain @domain end |
Instance Method Details
#fetch(path) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/pagerduty_tools/pagerduty.rb', line 48 def fetch(path) uri = URI.parse "https://#{@domain}#{path}" page = @agent.get uri # If we asked for a page and didn't get it, we probably have to log in. # TODO: check for non-login pages, like server error pages. while page.uri.path != uri.path page = login page end if @cookie_file @agent..save_as(@cookie_file) File.chmod(0600, @cookie_file) end return page end |