Class: PurpleAirApi::V1::GetSensors
- Inherits:
-
Object
- Object
- PurpleAirApi::V1::GetSensors
- Defined in:
- lib/purple_air_api/V1/sensors/get_sensors.rb
Overview
Class for requesting sensor data. This will return different response formats from the API.
Constant Summary collapse
- DEFAULT_FIELDS =
The default value for fields that will be returned by PurpleAir
%w[icon name latitude longitude altitude pm2.5].freeze
- DEFAULT_LOCATION_TYPE =
The default location type for the sensor
%w[outside inside].freeze
- 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.
-
#parsed_response ⇒ Hash
Takes the raw response from PurpleAir and generates a hash indexed by sensor 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: , **options) ⇒ GetSensors
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.
-
#request ⇒ PurpleAirApi::V1::GetSensors
Makes a get request to the PurpleAir Get Sensors Data endpoint api.purpleair.com/v1/sensors.
Constructor Details
#initialize(client: , **options) ⇒ GetSensors
Creates a HTTP friendly options hash depending on your inputs
32 33 34 35 36 |
# File 'lib/purple_air_api/V1/sensors/get_sensors.rb', line 32 def initialize(client:, **) @http_client = client @request_options = {} () 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_sensors.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_sensors.rb', line 7 def http_response @http_response end |
#parsed_response ⇒ Hash
Takes the raw response from PurpleAir and generates a hash indexed by sensor index. You can use this response like a normal hash object. This GetSensorsClass.parsed_response would return a hash of data for sensor 47 with each hash key labelling the associated data.
69 70 71 |
# File 'lib/purple_air_api/V1/sensors/get_sensors.rb', line 69 def parsed_response @parsed_response ||= parse_response end |
#request_options ⇒ Object
Returns the value of attribute request_options.
7 8 9 |
# File 'lib/purple_air_api/V1/sensors/get_sensors.rb', line 7 def @request_options end |
Class Method Details
.call ⇒ Object
Calls initializes the class and requests the data from PurpleAir.
23 24 25 |
# File 'lib/purple_air_api/V1/sensors/get_sensors.rb', line 23 def self.call(...) new(...).request end |
Instance Method Details
#call(...) ⇒ Object
Calls initializes the class and requests the data from PurpleAir.
23 24 25 |
# File 'lib/purple_air_api/V1/sensors/get_sensors.rb', line 23 def self.call(...) new(...).request end |
#json_response ⇒ Hash
Takes the raw response from PurpleAir and parses the JSON into a Hash.
91 92 93 |
# File 'lib/purple_air_api/V1/sensors/get_sensors.rb', line 91 def json_response @json_response ||= FastJsonparser.parse(http_response.body) end |
#request ⇒ PurpleAirApi::V1::GetSensors
Makes a get request to the PurpleAir Get Sensors Data endpoint api.purpleair.com/v1/sensors.
42 43 44 45 |
# File 'lib/purple_air_api/V1/sensors/get_sensors.rb', line 42 def request self.http_response = http_client.get(URL, ) self end |