Class: IngvQuake::Client
- Inherits:
-
Object
- Object
- IngvQuake::Client
- Defined in:
- lib/ingv_quake/client.rb
Overview
The Client class is responsible for making HTTP requests to the INGV Earthquake web services API. It provides methods to initialize a connection, retrieve event resources, and configure the underlying Faraday adapter.
Constant Summary collapse
- BASE_URL =
The base URL for the INGV Earthquake web services API.
'https://webservices.ingv.it/'
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
Instance Method Summary collapse
-
#connection ⇒ Faraday::Connection
Initializes a Faraday connection with the INGV Earthquake API base URL and XML headers.
-
#get_events ⇒ EventResource
Initializes an EventResource instance for fetching events from the API.
-
#initialize(adapter: Faraday.default_adapter, stubs: nil) ⇒ Client
constructor
Initializes a new Client instance with an optional adapter and stubs.
Constructor Details
#initialize(adapter: Faraday.default_adapter, stubs: nil) ⇒ Client
Initializes a new Client instance with an optional adapter and stubs.
19 20 21 22 |
# File 'lib/ingv_quake/client.rb', line 19 def initialize(adapter: Faraday.default_adapter, stubs: nil) @adapter = adapter @stubs = stubs end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
11 12 13 |
# File 'lib/ingv_quake/client.rb', line 11 def adapter @adapter end |
Instance Method Details
#connection ⇒ Faraday::Connection
Initializes a Faraday connection with the INGV Earthquake API base URL and XML headers. Configures the response to be parsed as XML and sets the adapter with optional stubs.
40 41 42 43 44 45 |
# File 'lib/ingv_quake/client.rb', line 40 def connection @connection ||= Faraday.new(url: BASE_URL) do |conn| conn.response :xml conn.adapter adapter, @stubs end end |
#get_events ⇒ EventResource
Initializes an EventResource instance for fetching events from the API.
31 32 33 |
# File 'lib/ingv_quake/client.rb', line 31 def get_events EventResource.new(self) end |