Class: PurpleAirApi::V1::GetSensor
- Inherits:
-
Object
- Object
- PurpleAirApi::V1::GetSensor
- Defined in:
- lib/purple_air_api/V1/sensors/get_sensor.rb
Overview
Class for requesting sensor data for a single sensor. This will return different response formats from the API.
Constant Summary collapse
- URL =
The endpoint URL
'https://api.purpleair.com/v1/sensors/'
Instance Attribute Summary collapse
-
#http_client ⇒ Object
readonly
Returns the value of attribute http_client.
-
#http_response ⇒ Object
Returns the value of attribute http_response.
-
#index ⇒ Object
Returns the value of attribute index.
-
#request_options ⇒ Object
Returns the value of attribute request_options.
Class Method Summary collapse
-
.call ⇒ Object
Calls initializes the class and requests the data from PurpleAir.
Instance Method Summary collapse
-
#call(...) ⇒ Object
Calls initializes the class and requests the data from PurpleAir.
-
#initialize(client: , sensor_index: , read_key: nil) ⇒ GetSensor
constructor
Creates a HTTP friendly options hash depending on your inputs.
-
#json_response ⇒ Hash
Takes the raw response from PurpleAir and parses the JSON into a Hash.
-
#parsed_response ⇒ Object
Delegate to PurpleAirApi::V1::GetSensor.json_response.
-
#request ⇒ PurpleAirApi::V1::GetSensors
Makes a get request to the PurpleAir Get Sensors Data endpoint api.purpleair.com/v1/sensors.
Constructor Details
#initialize(client: , sensor_index: , read_key: nil) ⇒ GetSensor
Creates a HTTP friendly options hash depending on your inputs
26 27 28 29 30 |
# File 'lib/purple_air_api/V1/sensors/get_sensor.rb', line 26 def initialize(client:, sensor_index:, read_key: nil) @http_client = client @request_options = {} (sensor_index, read_key) end |
Instance Attribute Details
#http_client ⇒ Object (readonly)
Returns the value of attribute http_client.
8 9 10 |
# File 'lib/purple_air_api/V1/sensors/get_sensor.rb', line 8 def http_client @http_client end |
#http_response ⇒ Object
Returns the value of attribute http_response.
7 8 9 |
# File 'lib/purple_air_api/V1/sensors/get_sensor.rb', line 7 def http_response @http_response end |
#index ⇒ Object
Returns the value of attribute index.
7 8 9 |
# File 'lib/purple_air_api/V1/sensors/get_sensor.rb', line 7 def index @index end |
#request_options ⇒ Object
Returns the value of attribute request_options.
7 8 9 |
# File 'lib/purple_air_api/V1/sensors/get_sensor.rb', line 7 def @request_options end |
Class Method Details
.call ⇒ Object
Calls initializes the class and requests the data from PurpleAir.
16 17 18 |
# File 'lib/purple_air_api/V1/sensors/get_sensor.rb', line 16 def self.call(...) new(...).request end |
Instance Method Details
#call(...) ⇒ Object
Calls initializes the class and requests the data from PurpleAir.
16 17 18 |
# File 'lib/purple_air_api/V1/sensors/get_sensor.rb', line 16 def self.call(...) new(...).request end |
#json_response ⇒ Hash
Takes the raw response from PurpleAir and parses the JSON into a Hash.
105 106 107 |
# File 'lib/purple_air_api/V1/sensors/get_sensor.rb', line 105 def json_response @json_response ||= FastJsonparser.parse(http_response.body) end |
#parsed_response ⇒ Object
Delegate to PurpleAirApi::V1::GetSensor.json_response
43 44 45 |
# File 'lib/purple_air_api/V1/sensors/get_sensor.rb', line 43 def parsed_response json_response end |
#request ⇒ PurpleAirApi::V1::GetSensors
Makes a get request to the PurpleAir Get Sensors Data endpoint api.purpleair.com/v1/sensors.
36 37 38 39 |
# File 'lib/purple_air_api/V1/sensors/get_sensor.rb', line 36 def request self.http_response = http_client.get(url, ) self end |