Class: StatusPage::API::Base
- Inherits:
-
Object
- Object
- StatusPage::API::Base
- Defined in:
- lib/status_page/api/base.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#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.
-
#get_resource ⇒ Object
sends GET request for subclass’s resource_path and returns json result as hash.
-
#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.
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:, **) = {headers: headers, method: method, url: get_full_url(path)} JSON.parse(RestClient::Request.execute(.merge())) rescue ::RestClient::Exception => e raise Exception.new(e) end |
#get_resource ⇒ Object
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 |