Class: IngvQuake::Resource
- Inherits:
-
Object
- Object
- IngvQuake::Resource
- Defined in:
- lib/ingv_quake/resource.rb
Overview
The Resource class serves as a base class for working with resources from the INGV Earthquake web services API. It provides a client to make requests, handle responses, and parse the response data.
The Resource class should not be used directly but should be subclassed for specific resources like events.
Direct Known Subclasses
Constant Summary collapse
- ERROR_MESSAGES =
Hash containing error messages for specific HTTP status codes.
{ 400 => 'Your request was malformed', 404 => 'No results were found for your request', 413 => 'Request entity too large', 429 => 'Your request exceeded the API rate limit', 500 => 'We were unable to perform the request due to server-side problems', 503 => 'You have been rate limited, try again in a minute' }.freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#get_events_request(params: {}) ⇒ Array
Sends a GET request to the specified API endpoint to retrieve events and handles the response.
-
#initialize(client) ⇒ Resource
constructor
Initializes a new Resource instance with a given client.
Constructor Details
#initialize(client) ⇒ Resource
Initializes a new Resource instance with a given client.
26 27 28 |
# File 'lib/ingv_quake/resource.rb', line 26 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
11 12 13 |
# File 'lib/ingv_quake/resource.rb', line 11 def client @client end |
Instance Method Details
#get_events_request(params: {}) ⇒ Array
Sends a GET request to the specified API endpoint to retrieve events and handles the response.
35 36 37 |
# File 'lib/ingv_quake/resource.rb', line 35 def get_events_request(params: {}) handle_response client.connection.get('/fdsnws/event/1/query', params) end |