Class: RunscopeStatuspage::RunscopeAPI

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/runscope_statuspage/runscope_api.rb

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ RunscopeAPI

Set credentials



11
12
13
# File 'lib/runscope_statuspage/runscope_api.rb', line 11

def initialize(token)
  @options = { headers: {"Authorization" => "Bearer #{token}"} }
end

Instance Method Details

#bucket_id_by_name(name) ⇒ Object

Get bucket ID by name



28
29
30
31
32
# File 'lib/runscope_statuspage/runscope_api.rb', line 28

def bucket_id_by_name(name)
  self.buckets.each do |bucket|
    return bucket["key"] if bucket["name"] == name
  end
end

#bucketsObject

Get list of buckets



16
17
18
19
20
21
22
23
24
25
# File 'lib/runscope_statuspage/runscope_api.rb', line 16

def buckets
  buckets = self.class.get('/buckets', @options)
  if buckets.has_key?('meta') and buckets.has_key?('data')
    if buckets['meta']['status'] == 'success'
      buckets['data']
    else
      raise RunscopeAPIException.new, buckets['error']
    end
  end
end

#get_radar(bucket, radar) ⇒ Object

Get a radar, from a bucket.



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/runscope_statuspage/runscope_api.rb', line 47

def get_radar(bucket, radar)
  get_radar = self.class.get("/buckets/#{bucket}/radar/#{radar}", @options)
  if get_radar.has_key?('meta') and get_radar.has_key?('data')
    if get_radar['meta']['status'] == 'success'
      get_radar['data']
    else
      raise RunscopeAPIException.new,
            "Error attempting to get radar info for #{bucket}, #{radar}: #{get_radar['error']}"
    end
  end
end

#latest_radar_result(bucket, radar) ⇒ Object

Get latest result from radar



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/runscope_statuspage/runscope_api.rb', line 60

def latest_radar_result(bucket, radar)
  lrr = self.class.get("/buckets/#{bucket}/radar/#{radar}/results/latest", @options)
  if lrr.has_key?('meta') and lrr.has_key?('data')
    if lrr['meta']['status'] == 'success'
      lrr['data']
    else
      raise RunscopeAPIException.new,
            "Error attempting to fetch latest radar result for #{bucket}, #{radar}: #{lrr['error']}"
    end
  end
end

#message_detail(bucket, message) ⇒ Object

Get message detail



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/runscope_statuspage/runscope_api.rb', line 86

def message_detail(bucket, message)
  detail = self.class.get("/buckets/#{bucket}/messages/#{message}", @options)
  if detail.has_key?('meta') and detail.has_key?('data')
    if detail['meta']['status'] == 'success'
      detail['data']
    else
      raise RunscopeAPIException.new,
            "Error attempting to fetch message detail for #{bucket}, #{message}: #{detail['error']}"
    end
  end
end

#messages(bucket, count) ⇒ Object

Get latest messages



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/runscope_statuspage/runscope_api.rb', line 73

def messages(bucket, count)
  messages = self.class.get("/buckets/#{bucket_id_by_name(bucket)}/messages?count=#{count}", @options)
  if messages.has_key?('meta') and messages.has_key?('data')
    if messages['meta']['status'] == 'success'
      messages['data']
    else
      raise RunscopeAPIException.new,
            "Error attempting to fetch messages for #{bucket}: #{detail['error']}"
    end
  end
end

#radars(bucket) ⇒ Object

Get list of radars for bucket



35
36
37
38
39
40
41
42
43
44
# File 'lib/runscope_statuspage/runscope_api.rb', line 35

def radars(bucket)
  radars = self.class.get("/buckets/#{bucket}/radar", @options)
  if radars.has_key?('meta') and radars.has_key?('data')
    if radars['meta']['status'] == 'success'
      radars['data']
    else
      raise RunscopeAPIException.new, radars['error']
    end
  end
end