Class: PagerDuty::Full

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

Direct Known Subclasses

Resource::Incident, Resource::Schedule

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(apikey, subdomain) ⇒ Full

Returns a new instance of Full.



10
11
12
13
# File 'lib/pagerduty/base.rb', line 10

def initialize(apikey, subdomain)
  @apikey = apikey
  @subdomain = subdomain
end

Instance Attribute Details

#apikeyObject (readonly)

Returns the value of attribute apikey.



8
9
10
# File 'lib/pagerduty/base.rb', line 8

def apikey
  @apikey
end

#subdomainObject (readonly)

Returns the value of attribute subdomain.



8
9
10
# File 'lib/pagerduty/base.rb', line 8

def subdomain
  @subdomain
end

Instance Method Details

#api_call(path, params) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/pagerduty/base.rb', line 15

def api_call(path, params)

  uri = URI.parse("https://#{@subdomain}.pagerduty.com/api/v1/#{path}")
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE

  # This is probably stupid
  query_string = ""
  params.each do |key, val|
    next unless val != nil
    query_string << '&' unless key == params.keys.first
    query_string << "#{URI.encode(key.to_s)}=#{URI.encode(params[key])}"
  end
  uri.query = query_string

  req = Net::HTTP::Get.new(uri.request_uri)

  res = http.get(uri.to_s, {
    'Content-type'  => 'application/json',
    'Authorization' => "Token token=#{@apikey}"
  })
end

#IncidentObject



39
40
41
# File 'lib/pagerduty/base.rb', line 39

def Incident()
  PagerDuty::Resource::Incident.new(@apikey, @subdomain)
end

#ScheduleObject



43
44
45
# File 'lib/pagerduty/base.rb', line 43

def Schedule()
  PagerDuty::Resource::Schedule.new(@apikey, @subdomain)
end