Class: PagerDuty::Agent

Inherits:
Object
  • Object
show all
Defined in:
lib/pagerduty_tools/pagerduty.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAgent

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.expand_path(COOKIE_FILE)
  @agent       = Mechanize.new

  load_cookies
  find_domain
end

Instance Attribute Details

#domainObject

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 =  page
  end

  if @cookie_file
    @agent.cookie_jar.save_as(@cookie_file)
    File.chmod(0600, @cookie_file)
  end

  return page
end