Class: PurpleAirApi::V1::Client
- Inherits:
-
Object
- Object
- PurpleAirApi::V1::Client
- Defined in:
- lib/purple_air_api/V1/client.rb
Overview
Client class for interfacing with the V1 PurpleAir API. Refer to the instance methods to learn more about what methods and API options are available.
Constant Summary collapse
- API_URL =
The base URL for the PurpleAir API
'https://api.purpleair.com/v1/'
Instance Attribute Summary collapse
-
#read_client ⇒ Object
readonly
Returns the value of attribute read_client.
-
#write_client ⇒ Object
readonly
Returns the value of attribute write_client.
Instance Method Summary collapse
-
#initialize(read_token: , write_token: ) ⇒ Client
constructor
Creates a read and write client to interface with the Purple Air API.
-
#request_sensor(sensor_index, read_key: nil) ⇒ PurpleAirApi::GetSensor
Makes a request to the individual sensor SHOW endpoint and returns an instance of the V1::GetSensors class.
-
#request_sensors(options) ⇒ PurpleAirApi::GetSensors
Makes a request to the sensors INDEX endpoint and returns an instance of the V1::GetSensors class.
Constructor Details
#initialize(read_token: , write_token: ) ⇒ Client
Creates a read and write client to interface with the Purple Air API.
21 22 23 24 |
# File 'lib/purple_air_api/V1/client.rb', line 21 def initialize(read_token:, write_token: nil) @read_client = create_http_client(read_token) @write_client = create_http_client(write_token) unless write_token.nil? end |
Instance Attribute Details
#read_client ⇒ Object (readonly)
Returns the value of attribute read_client.
9 10 11 |
# File 'lib/purple_air_api/V1/client.rb', line 9 def read_client @read_client end |
#write_client ⇒ Object (readonly)
Returns the value of attribute write_client.
9 10 11 |
# File 'lib/purple_air_api/V1/client.rb', line 9 def write_client @write_client end |
Instance Method Details
#request_sensor(sensor_index, read_key: nil) ⇒ PurpleAirApi::GetSensor
Makes a request to the individual sensor SHOW endpoint and returns an instance of the V1::GetSensors class.
59 60 61 |
# File 'lib/purple_air_api/V1/client.rb', line 59 def request_sensor(sensor_index:, read_key: nil) GetSensor.call(client: read_client, sensor_index: sensor_index, read_key: read_key) end |
#request_sensors(options) ⇒ PurpleAirApi::GetSensors
Makes a request to the sensors INDEX endpoint and returns an instance of the V1::GetSensors class.
45 46 47 |
# File 'lib/purple_air_api/V1/client.rb', line 45 def request_sensors( = {}) GetSensors.call(client: read_client, **) end |