Class: StatusPage::API::Base

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

Direct Known Subclasses

Component, ComponentList

Instance Method Summary collapse

Instance Method Details

#execute(path, method:, **options) ⇒ Object

sends request to status page API for given path and method, passing any other options through to RestClient parses the response and returns as a ruby hash or array



6
7
8
9
10
11
# File 'lib/status_page/api/base.rb', line 6

def execute(path, method:, **options)
  default_options = {headers: headers, method: method, url: get_full_url(path)}
  JSON.parse(RestClient::Request.execute(default_options.merge(options)))
rescue ::RestClient::Exception => e
  raise Exception.new(e)
end

#get_resourceObject

sends GET request for subclass’s resource_path and returns json result as hash



14
15
16
# File 'lib/status_page/api/base.rb', line 14

def get_resource
  execute(resource_path, method: :get)
end

#patch_resource(payload) ⇒ Object

sends PATCH request for subclass’s resource_path and returns json result as hash; accepts a payload parameter to convert to JSON body



20
21
22
# File 'lib/status_page/api/base.rb', line 20

def patch_resource(payload)
  execute(resource_path, method: :patch, payload: payload.to_json)
end