Class: IngvQuake::Resource

Inherits:
Object
  • Object
show all
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

EventResource

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Resource

Initializes a new Resource instance with a given client.

Parameters:



26
27
28
# File 'lib/ingv_quake/resource.rb', line 26

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (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.

Parameters:

  • params (Hash) (defaults to: {})

    Optional query parameters for the request.

Returns:

  • (Array)

    An array of parsed event objects.



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