Class: LosantRest::Events
- Inherits:
-
Object
- Object
- LosantRest::Events
- Defined in:
- lib/losant_rest/events.rb
Overview
Class containing all the actions for the Events Resource
Instance Method Summary collapse
-
#get(params = {}) ⇒ Object
Returns the events for an application.
-
#initialize(client) ⇒ Events
constructor
A new instance of Events.
-
#most_recent_by_severity(params = {}) ⇒ Object
Returns the first new event ordered by severity and then creation.
-
#patch(params = {}) ⇒ Object
Asynchronously updates information for matching events by subject and/or current state.
-
#post(params = {}) ⇒ Object
Create a new event for an application.
Constructor Details
#initialize(client) ⇒ Events
Returns a new instance of Events.
6 7 8 |
# File 'lib/losant_rest/events.rb', line 6 def initialize(client) @client = client end |
Instance Method Details
#get(params = {}) ⇒ Object
Returns the events for an application
Parameters:
-
string applicationId - ID associated with the application
-
string sortField - Field to sort the results by. Accepted values are: subject, id, creationDate
-
string sortDirection - Direction to sort the results by. Accepted values are: asc, desc
-
string page - Which page of results to return
-
string perPage - How many items to return per page
-
string filterField - Field to filter the results by. Blank or not provided means no filtering. Accepted values are: subject
-
string filter - Filter to apply against the filtered field. Supports globbing. Blank or not provided means no filtering.
-
string state - If provided, return events only in the given state. Accepted values are: new, acknowledged, resolved
-
string losantdomain - Domain scope of request (rarely needed)
-
boolean _actions - Return resource actions in response
-
boolean _links - Return resource link in response
-
boolean _embedded - Return embedded resources in response
Responses:
-
200 - Collection of events (api.losant.com/#/definitions/events)
Errors:
-
400 - Error if malformed request (api.losant.com/#/definitions/error)
-
404 - Error if application was not found (api.losant.com/#/definitions/error)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/losant_rest/events.rb', line 32 def get(params = {}) params = Utils.symbolize_hash_keys(params) query_params = { _actions: false, _links: true, _embedded: true } headers = {} body = nil raise ArgumentError.new("applicationId is required") unless params.has_key?(:applicationId) query_params[:sortField] = params[:sortField] if params.has_key?(:sortField) query_params[:sortDirection] = params[:sortDirection] if params.has_key?(:sortDirection) query_params[:page] = params[:page] if params.has_key?(:page) query_params[:perPage] = params[:perPage] if params.has_key?(:perPage) query_params[:filterField] = params[:filterField] if params.has_key?(:filterField) query_params[:filter] = params[:filter] if params.has_key?(:filter) query_params[:state] = params[:state] if params.has_key?(:state) headers[:losantdomain] = params[:losantdomain] if params.has_key?(:losantdomain) query_params[:_actions] = params[:_actions] if params.has_key?(:_actions) query_params[:_links] = params[:_links] if params.has_key?(:_links) query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded) path = "/applications/#{params[:applicationId]}/events" @client.request( method: :get, path: path, query: query_params, headers: headers, body: body) end |
#most_recent_by_severity(params = {}) ⇒ Object
Returns the first new event ordered by severity and then creation
Parameters:
-
string applicationId - ID associated with the application
-
string filter - Filter to apply against event subjects. Supports globbing. Blank or not provided means no filtering.
-
string losantdomain - Domain scope of request (rarely needed)
-
boolean _actions - Return resource actions in response
-
boolean _links - Return resource link in response
-
boolean _embedded - Return embedded resources in response
Responses:
-
200 - The event, plus count of currently new events
Errors:
-
404 - Error if application was not found (api.losant.com/#/definitions/error)
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/losant_rest/events.rb', line 77 def most_recent_by_severity(params = {}) params = Utils.symbolize_hash_keys(params) query_params = { _actions: false, _links: true, _embedded: true } headers = {} body = nil raise ArgumentError.new("applicationId is required") unless params.has_key?(:applicationId) query_params[:filter] = params[:filter] if params.has_key?(:filter) headers[:losantdomain] = params[:losantdomain] if params.has_key?(:losantdomain) query_params[:_actions] = params[:_actions] if params.has_key?(:_actions) query_params[:_links] = params[:_links] if params.has_key?(:_links) query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded) path = "/applications/#{params[:applicationId]}/events/mostRecentBySeverity" @client.request( method: :get, path: path, query: query_params, headers: headers, body: body) end |
#patch(params = {}) ⇒ Object
Asynchronously updates information for matching events by subject and/or current state
Parameters:
-
string applicationId - ID associated with the application
-
string filterField - Field to filter the events to act on by. Blank or not provided means no filtering. Accepted values are: subject
-
string filter - Filter to apply against the filtered field. Supports globbing. Blank or not provided means no filtering.
-
string state - If provided, act on events only in the given state. Accepted values are: new, acknowledged, resolved
-
hash updates - Object containing updated information for the events (api.losant.com/#/definitions/eventPatch)
-
string losantdomain - Domain scope of request (rarely needed)
-
boolean _actions - Return resource actions in response
-
boolean _links - Return resource link in response
-
boolean _embedded - Return embedded resources in response
Responses:
-
200 - If the bulk update has been successfully started (api.losant.com/#/definitions/success)
Errors:
-
400 - Error if malformed request (api.losant.com/#/definitions/error)
-
404 - Error if application is not found (api.losant.com/#/definitions/error)
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/losant_rest/events.rb', line 120 def patch(params = {}) params = Utils.symbolize_hash_keys(params) query_params = { _actions: false, _links: true, _embedded: true } headers = {} body = nil raise ArgumentError.new("applicationId is required") unless params.has_key?(:applicationId) raise ArgumentError.new("updates is required") unless params.has_key?(:updates) query_params[:filterField] = params[:filterField] if params.has_key?(:filterField) query_params[:filter] = params[:filter] if params.has_key?(:filter) query_params[:state] = params[:state] if params.has_key?(:state) body = params[:updates] if params.has_key?(:updates) headers[:losantdomain] = params[:losantdomain] if params.has_key?(:losantdomain) query_params[:_actions] = params[:_actions] if params.has_key?(:_actions) query_params[:_links] = params[:_links] if params.has_key?(:_links) query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded) path = "/applications/#{params[:applicationId]}/events" @client.request( method: :patch, path: path, query: query_params, headers: headers, body: body) end |
#post(params = {}) ⇒ Object
Create a new event for an application
Parameters:
-
string applicationId - ID associated with the application
-
hash event - New event information (api.losant.com/#/definitions/eventPost)
-
string losantdomain - Domain scope of request (rarely needed)
-
boolean _actions - Return resource actions in response
-
boolean _links - Return resource link in response
-
boolean _embedded - Return embedded resources in response
Responses:
-
201 - Successfully created event (api.losant.com/#/definitions/event)
Errors:
-
400 - Error if malformed request (api.losant.com/#/definitions/error)
-
404 - Error if application was not found (api.losant.com/#/definitions/error)
-
429 - Error if event creation rate limit exceeded (api.losant.com/#/definitions/error)
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/losant_rest/events.rb', line 165 def post(params = {}) params = Utils.symbolize_hash_keys(params) query_params = { _actions: false, _links: true, _embedded: true } headers = {} body = nil raise ArgumentError.new("applicationId is required") unless params.has_key?(:applicationId) raise ArgumentError.new("event is required") unless params.has_key?(:event) body = params[:event] if params.has_key?(:event) headers[:losantdomain] = params[:losantdomain] if params.has_key?(:losantdomain) query_params[:_actions] = params[:_actions] if params.has_key?(:_actions) query_params[:_links] = params[:_links] if params.has_key?(:_links) query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded) path = "/applications/#{params[:applicationId]}/events" @client.request( method: :post, path: path, query: query_params, headers: headers, body: body) end |