class StatusCake
Constants
- SUPPORTED_QUERIES
We can only filter on these in the API. Hopefully they will support more.
Public Class Methods
new(opts)
click to toggle source
# File lib/status_cake/status_cake.rb, line 15 def initialize(opts) @auth = {'Username' => opts[:username], 'API' => opts[:api_key]} end
Public Instance Methods
contact_groups(options={})
click to toggle source
# File lib/status_cake/status_cake.rb, line 19 def contact_groups(options={}) @opts = {headers:@auth} filter_opts = options contact_groups = respond(self.class.get("/ContactGroups", @opts)) || [] unless filter_opts.empty? contact_groups.find_all { |t| (t & filter_opts) == filter_opts } else contact_groups end end
delete_test(test={})
click to toggle source
# File lib/status_cake/status_cake.rb, line 62 def delete_test(test={}) @opts = {headers:@auth, body:{ 'TestID' => test['TestID'] } } respond(self.class.delete("/Tests/Details",@opts)) end
find_test(id)
click to toggle source
# File lib/status_cake/status_cake.rb, line 52 def find_test(id) @opts = {headers:@auth, query:{ 'TestID' => id }} respond(self.class.get("/Tests/Details", @opts)) end
pause_test(t)
click to toggle source
# File lib/status_cake/status_cake.rb, line 67 def pause_test(t) if t t['Paused'] = '1' update_test(t) end end
tests(options={})
click to toggle source
# File lib/status_cake/status_cake.rb, line 37 def tests(options={}) # Hash#slice w/o activesupport query_opts = options.select { |k,v| SUPPORTED_QUERIES.index(k) } filter_opts = options.reject { |k,v| SUPPORTED_QUERIES.index(k) } @opts = {headers:@auth, query:query_opts} tests = respond(self.class.get("/Tests", @opts)) || [] unless filter_opts.empty? tests.find_all { |t| (t & filter_opts) == filter_opts } else tests end end
unpause_test(t)
click to toggle source
# File lib/status_cake/status_cake.rb, line 74 def unpause_test(t) if t t['Paused'] = '0' update_test(t) end end
update_contact_group(contact_group={})
click to toggle source
# File lib/status_cake/status_cake.rb, line 32 def update_contact_group(contact_group={}) @opts = {headers:@auth, body:contact_group } respond(self.class.put("/ContactGroups/Update",@opts)) end
update_test(test={})
click to toggle source
# File lib/status_cake/status_cake.rb, line 57 def update_test(test={}) @opts = {headers:@auth, body:test } respond(self.class.put("/Tests/Update",@opts)) end
Protected Instance Methods
respond(response)
click to toggle source
# File lib/status_cake/status_cake.rb, line 83 def respond(response) if response.success? if response.is_a?(Hash) && response.has_key?('Error') raise response["Error"] else response end else raise response.response end end