purple_air_api 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/Gemfile.lock +1 -1
- data/README.md +143 -11
- data/Rakefile +5 -0
- data/docs/PurpleAirApi.html +488 -0
- data/docs/PurpleAirApi/V1.html +128 -0
- data/docs/PurpleAirApi/V1/ApiError.html +159 -0
- data/docs/PurpleAirApi/V1/ApiKeyError.html +159 -0
- data/docs/PurpleAirApi/V1/BaseError.html +431 -0
- data/docs/PurpleAirApi/V1/Client.html +801 -0
- data/docs/PurpleAirApi/V1/GetSensor.html +1033 -0
- data/docs/PurpleAirApi/V1/GetSensors.html +979 -0
- data/docs/PurpleAirApi/V1/MissingJsonPayloadError.html +159 -0
- data/docs/PurpleAirApi/V1/NotFoundError.html +159 -0
- data/docs/PurpleAirApi/V1/OptionsError.html +135 -0
- data/docs/PurpleAirApi/V1/RaiseHttpException.html +318 -0
- data/docs/PurpleAirApi/V1/ServerError.html +159 -0
- data/docs/_index.html +274 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +497 -0
- data/docs/file.README.html +247 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +247 -0
- data/docs/js/app.js +314 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +315 -0
- data/docs/top-level-namespace.html +110 -0
- data/lib/purple_air_api/V1/client.rb +11 -1
- data/lib/purple_air_api/V1/sensors/get_sensor.rb +5 -4
- data/lib/purple_air_api/V1/sensors/get_sensors.rb +11 -9
- data/lib/purple_air_api/version.rb +1 -1
- data/purple_air_api.gemspec +8 -5
- metadata +37 -8
@@ -0,0 +1,247 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
File: README
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.26
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" />
|
16
|
+
|
17
|
+
<script type="text/javascript">
|
18
|
+
pathId = "README";
|
19
|
+
relpath = '';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="file_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="_index.html">Index</a> »
|
40
|
+
<span class="title">File: README</span>
|
41
|
+
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<div id="search">
|
45
|
+
|
46
|
+
<a class="full_list_link" id="class_list_link"
|
47
|
+
href="class_list.html">
|
48
|
+
|
49
|
+
<svg width="24" height="24">
|
50
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
51
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
52
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
</svg>
|
54
|
+
</a>
|
55
|
+
|
56
|
+
</div>
|
57
|
+
<div class="clear"></div>
|
58
|
+
</div>
|
59
|
+
|
60
|
+
<div id="content"><div id='filecontents'><h1 id="purpleairapi">PurpleAirApi</h1>
|
61
|
+
<p>This is a Ruby wrapper for the PurpleAir API.</p>
|
62
|
+
|
63
|
+
<h2 id="installation">Installation</h2>
|
64
|
+
<p>Add this line to your application’s Gemfile:</p>
|
65
|
+
|
66
|
+
<p><code>ruby
|
67
|
+
gem 'purple_air_api'
|
68
|
+
</code></p>
|
69
|
+
|
70
|
+
<p>And then execute:</p>
|
71
|
+
|
72
|
+
<p><code>bundle install</code></p>
|
73
|
+
|
74
|
+
<p>Or install it yourself as:</p>
|
75
|
+
|
76
|
+
<p><code>gem install purple_air_api</code></p>
|
77
|
+
|
78
|
+
<h2 id="usage">Usage</h2>
|
79
|
+
<p>To use this gem, instantiate an instance of a PurpleAirApi client. The write token is
|
80
|
+
optional and currently no write actions are implemented in this gem.</p>
|
81
|
+
|
82
|
+
<p><code>client = PurpleAirApi.client(read_token: your_read_token, write_token: your_write_token)</code></p>
|
83
|
+
|
84
|
+
<p>You can then use this client to interact with the various API methods under the client:</p>
|
85
|
+
|
86
|
+
<h3 id="requesting-multiple-sensors">Requesting multiple sensors</h3>
|
87
|
+
<p>```ruby
|
88
|
+
# Optional parameters are added using a hash. For a full list of options refer to the documentation.</p>
|
89
|
+
|
90
|
+
<p>nw_lat_long = [37.804930, -122.448382]
|
91
|
+
se_lat_long = [37.794832, -122.393589]
|
92
|
+
fields = %w[icon name latitude longitude altitude pm2.5 pm2.5_10minute pm2.5_30minute pm2.5_60minute]
|
93
|
+
location_type = %w[outside]
|
94
|
+
show_only = [20, 40, 55, 120]</p>
|
95
|
+
|
96
|
+
<p>options = {
|
97
|
+
fields: fields,
|
98
|
+
location_type: location_type,
|
99
|
+
bounding_box: { nw: nw_lat_long, se: se_lat_long },
|
100
|
+
show_only: show_only
|
101
|
+
}</p>
|
102
|
+
|
103
|
+
<p>response = client.request_sensors(options)</p>
|
104
|
+
|
105
|
+
<p>response.parsed_response[:data][40] # access the individual sensor data using the parsed_response hash
|
106
|
+
```</p>
|
107
|
+
|
108
|
+
<h3 id="requesting-a-single-sensor-index">Requesting a single sensor index</h3>
|
109
|
+
<p>```ruby
|
110
|
+
response = client.request_sensor(sensor_index: 1)</p>
|
111
|
+
|
112
|
+
<p>current_air_quality = response.json_response[:sensor][:”pm2.5_a”]
|
113
|
+
```</p>
|
114
|
+
|
115
|
+
<h3 id="a-sample-service-object-for-a-lat-long-bounding-box">A sample service object for a lat-long bounding box</h3>
|
116
|
+
<p>```ruby
|
117
|
+
# frozen_string_literal: true</p>
|
118
|
+
|
119
|
+
<p>require ‘purple_air_api’
|
120
|
+
require ‘dotenv/load’</p>
|
121
|
+
|
122
|
+
<p>module AirQuality
|
123
|
+
# Class for making requests for local sensor data with a lat-long bounding box
|
124
|
+
class GetSensors
|
125
|
+
NW_LAT_LONG = [37.804930, -122.448382].freeze
|
126
|
+
SE_LAT_LONG = [37.794832, -122.393589].freeze
|
127
|
+
DEFAULT_FIELDS = %w[icon name latitude longitude altitude pm2.5 pm2.5_10minute pm2.5_30minute pm2.5_60minute].freeze
|
128
|
+
DEFAULT_LOCATION_TYPE = %w[outside].freeze</p>
|
129
|
+
|
130
|
+
<pre class="code ruby"><code class="ruby">def self.call
|
131
|
+
new.request
|
132
|
+
end
|
133
|
+
|
134
|
+
def request
|
135
|
+
PurpleAirApi.client(read_token: read_token).request_sensors(fields)
|
136
|
+
end
|
137
|
+
|
138
|
+
def read_token
|
139
|
+
ENV['READ_TOKEN']
|
140
|
+
end
|
141
|
+
|
142
|
+
def fields
|
143
|
+
{
|
144
|
+
fields: DEFAULT_FIELDS,
|
145
|
+
location_type: DEFAULT_LOCATION_TYPE,
|
146
|
+
bounding_box: { nw: NW_LAT_LONG, se: SE_LAT_LONG }
|
147
|
+
}
|
148
|
+
end end end ````
|
149
|
+
</code></pre>
|
150
|
+
|
151
|
+
<h3 id="a-sample-service-object-for-a-single-sensor">A sample service object for a single sensor</h3>
|
152
|
+
<p>```ruby
|
153
|
+
# frozen_string_literal: true</p>
|
154
|
+
|
155
|
+
<p>require ‘purple_air_api’
|
156
|
+
require ‘dotenv/load’</p>
|
157
|
+
|
158
|
+
<p>module AirQuality
|
159
|
+
# Class for making requests for an individual sensor
|
160
|
+
class GetSensor
|
161
|
+
SENSOR_INDEX = 54_849</p>
|
162
|
+
|
163
|
+
<pre class="code ruby"><code class="ruby">def self.call
|
164
|
+
new.request
|
165
|
+
end
|
166
|
+
|
167
|
+
def request
|
168
|
+
PurpleAirApi.client(read_token: read_token).request_sensor(sensor_index: SENSOR_INDEX)
|
169
|
+
end
|
170
|
+
|
171
|
+
def read_token
|
172
|
+
ENV['READ_TOKEN']
|
173
|
+
end end end ```
|
174
|
+
</code></pre>
|
175
|
+
|
176
|
+
<h3 id="in-a-sinatra-app">In a Sinatra app</h3>
|
177
|
+
|
178
|
+
<p>```ruby
|
179
|
+
# frozen_string_literal: true</p>
|
180
|
+
|
181
|
+
<p>require ‘sinatra’
|
182
|
+
require “sinatra/json”
|
183
|
+
require ‘dotenv/load’
|
184
|
+
require ‘purple_air_api’</p>
|
185
|
+
|
186
|
+
<p>module HomeHub
|
187
|
+
# App server class for running the HomeHub app
|
188
|
+
class App < Sinatra::Base</p>
|
189
|
+
|
190
|
+
<pre class="code ruby"><code class="ruby">get '/sensors/:id' do
|
191
|
+
json purple_air_client.request_sensor(sensor_index: params[:id].to_i).json_response
|
192
|
+
end
|
193
|
+
|
194
|
+
get '/sensors' do
|
195
|
+
json purple_air_client.request_sensors.json_response
|
196
|
+
end
|
197
|
+
|
198
|
+
def purple_air_client
|
199
|
+
@purple_air_client ||= PurpleAirApi.client(read_token: read_token)
|
200
|
+
end
|
201
|
+
|
202
|
+
def read_token
|
203
|
+
@read_token ||= ENV['READ_TOKEN']
|
204
|
+
end end end ```
|
205
|
+
</code></pre>
|
206
|
+
|
207
|
+
<h2 id="documentation">Documentation</h2>
|
208
|
+
|
209
|
+
<p>Documentation for this gem can be found <a href="https://dkiselbach.github.io/purple_air_api/">here.</a></p>
|
210
|
+
|
211
|
+
<h2 id="purpleair-documentation-and-read-and-write-tokens">PurpleAir Documentation and Read and Write Tokens</h2>
|
212
|
+
|
213
|
+
<p>This wrapper was written using the <a href="https://api.purpleair.com/">PurpleAir API Documentation</a>. You will require a read
|
214
|
+
and write token in order to use the PurpleAir API which can be received by <a href="https://www2.purpleair.com/pages/contact-us">reaching out to PurpleAir</a>.</p>
|
215
|
+
|
216
|
+
<h2 id="development">Development</h2>
|
217
|
+
|
218
|
+
<p>After checking out the repo, run <code>bin/setup</code> to install dependencies. Then, run <code>rake spec</code> to run the tests. You can also run <code>bin/console</code> for an interactive prompt that will allow you to experiment.</p>
|
219
|
+
|
220
|
+
<p>To install this gem onto your local machine, run <code>bundle exec rake install</code>. To release a new version, update the version number in <code>version.rb</code>, and then run <code>bundle exec rake release</code>, which will create a git tag for the version, push git commits and the created tag, and push the <code>.gem</code> file to <a href="https://rubygems.org">rubygems.org</a>.</p>
|
221
|
+
|
222
|
+
<p>Make sure you are updating the Yard docs prior to pushing to master by running <code>rake yard</code>.</p>
|
223
|
+
|
224
|
+
<h2 id="contributing">Contributing</h2>
|
225
|
+
|
226
|
+
<p>Bug reports and pull requests are welcome on GitHub at https://github.com/dkiselbach/purple_air_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the <a href="https://github.com/dkiselbach/purple_air_api/CODE_OF_CONDUCT.md">code of conduct</a>.</p>
|
227
|
+
|
228
|
+
<h2 id="license">License</h2>
|
229
|
+
|
230
|
+
<p>The gem is available as open source under the terms of the <a href="https://opensource.org/licenses/MIT">MIT License</a>.</p>
|
231
|
+
|
232
|
+
<h2 id="code-of-conduct">Code of Conduct</h2>
|
233
|
+
|
234
|
+
<p>Everyone interacting in the PurpleAirApi project’s codebase, issue trackers, chat rooms and mailing lists is expected to follow the <a href="https://github.com/dkiselbach/purple_air_api/blob/master/CODE_OF_CONDUCT.md">code of conduct</a>.</p>
|
235
|
+
|
236
|
+
<p><a href="code_of_conduct.md"><img src="https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg" alt="Contributor Covenant" /></a></p>
|
237
|
+
</div></div>
|
238
|
+
|
239
|
+
<div id="footer">
|
240
|
+
Generated on Fri Mar 12 10:06:10 2021 by
|
241
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
242
|
+
0.9.26 (ruby-3.0.0).
|
243
|
+
</div>
|
244
|
+
|
245
|
+
</div>
|
246
|
+
</body>
|
247
|
+
</html>
|
data/docs/file_list.html
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
5
|
+
<meta charset="utf-8" />
|
6
|
+
|
7
|
+
<link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" />
|
8
|
+
|
9
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" />
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
14
|
+
|
15
|
+
<script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
|
16
|
+
|
17
|
+
|
18
|
+
<title>File List</title>
|
19
|
+
<base id="base_target" target="_parent" />
|
20
|
+
</head>
|
21
|
+
<body>
|
22
|
+
<div id="content">
|
23
|
+
<div class="fixed_header">
|
24
|
+
<h1 id="full_list_header">File List</h1>
|
25
|
+
<div id="full_list_nav">
|
26
|
+
|
27
|
+
<span><a target="_self" href="class_list.html">
|
28
|
+
Classes
|
29
|
+
</a></span>
|
30
|
+
|
31
|
+
<span><a target="_self" href="method_list.html">
|
32
|
+
Methods
|
33
|
+
</a></span>
|
34
|
+
|
35
|
+
<span><a target="_self" href="file_list.html">
|
36
|
+
Files
|
37
|
+
</a></span>
|
38
|
+
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div id="search">Search: <input type="text" /></div>
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<ul id="full_list" class="file">
|
45
|
+
|
46
|
+
|
47
|
+
<li id="object_README" class="odd">
|
48
|
+
<div class="item"><span class="object_link"><a href="index.html" title="README">README</a></span></div>
|
49
|
+
</li>
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
</ul>
|
54
|
+
</div>
|
55
|
+
</body>
|
56
|
+
</html>
|
data/docs/frames.html
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<title>Documentation by YARD 0.9.26</title>
|
6
|
+
</head>
|
7
|
+
<script type="text/javascript">
|
8
|
+
var match = unescape(window.location.hash).match(/^#!(.+)/);
|
9
|
+
var name = match ? match[1] : 'index.html';
|
10
|
+
name = name.replace(/^(\w+):\/\//, '').replace(/^\/\//, '');
|
11
|
+
window.top.location = name;
|
12
|
+
</script>
|
13
|
+
<noscript>
|
14
|
+
<h1>Oops!</h1>
|
15
|
+
<h2>YARD requires JavaScript!</h2>
|
16
|
+
</noscript>
|
17
|
+
</html>
|
data/docs/index.html
ADDED
@@ -0,0 +1,247 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
File: README
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.26
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" />
|
16
|
+
|
17
|
+
<script type="text/javascript">
|
18
|
+
pathId = "README";
|
19
|
+
relpath = '';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="_index.html">Index</a> »
|
40
|
+
<span class="title">File: README</span>
|
41
|
+
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<div id="search">
|
45
|
+
|
46
|
+
<a class="full_list_link" id="class_list_link"
|
47
|
+
href="class_list.html">
|
48
|
+
|
49
|
+
<svg width="24" height="24">
|
50
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
51
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
52
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
</svg>
|
54
|
+
</a>
|
55
|
+
|
56
|
+
</div>
|
57
|
+
<div class="clear"></div>
|
58
|
+
</div>
|
59
|
+
|
60
|
+
<div id="content"><div id='filecontents'><h1 id="purpleairapi">PurpleAirApi</h1>
|
61
|
+
<p>This is a Ruby wrapper for the PurpleAir API.</p>
|
62
|
+
|
63
|
+
<h2 id="installation">Installation</h2>
|
64
|
+
<p>Add this line to your application’s Gemfile:</p>
|
65
|
+
|
66
|
+
<p><code>ruby
|
67
|
+
gem 'purple_air_api'
|
68
|
+
</code></p>
|
69
|
+
|
70
|
+
<p>And then execute:</p>
|
71
|
+
|
72
|
+
<p><code>bundle install</code></p>
|
73
|
+
|
74
|
+
<p>Or install it yourself as:</p>
|
75
|
+
|
76
|
+
<p><code>gem install purple_air_api</code></p>
|
77
|
+
|
78
|
+
<h2 id="usage">Usage</h2>
|
79
|
+
<p>To use this gem, instantiate an instance of a PurpleAirApi client. The write token is
|
80
|
+
optional and currently no write actions are implemented in this gem.</p>
|
81
|
+
|
82
|
+
<p><code>client = PurpleAirApi.client(read_token: your_read_token, write_token: your_write_token)</code></p>
|
83
|
+
|
84
|
+
<p>You can then use this client to interact with the various API methods under the client:</p>
|
85
|
+
|
86
|
+
<h3 id="requesting-multiple-sensors">Requesting multiple sensors</h3>
|
87
|
+
<p>```ruby
|
88
|
+
# Optional parameters are added using a hash. For a full list of options refer to the documentation.</p>
|
89
|
+
|
90
|
+
<p>nw_lat_long = [37.804930, -122.448382]
|
91
|
+
se_lat_long = [37.794832, -122.393589]
|
92
|
+
fields = %w[icon name latitude longitude altitude pm2.5 pm2.5_10minute pm2.5_30minute pm2.5_60minute]
|
93
|
+
location_type = %w[outside]
|
94
|
+
show_only = [20, 40, 55, 120]</p>
|
95
|
+
|
96
|
+
<p>options = {
|
97
|
+
fields: fields,
|
98
|
+
location_type: location_type,
|
99
|
+
bounding_box: { nw: nw_lat_long, se: se_lat_long },
|
100
|
+
show_only: show_only
|
101
|
+
}</p>
|
102
|
+
|
103
|
+
<p>response = client.request_sensors(options)</p>
|
104
|
+
|
105
|
+
<p>response.parsed_response[:data][40] # access the individual sensor data using the parsed_response hash
|
106
|
+
```</p>
|
107
|
+
|
108
|
+
<h3 id="requesting-a-single-sensor-index">Requesting a single sensor index</h3>
|
109
|
+
<p>```ruby
|
110
|
+
response = client.request_sensor(sensor_index: 1)</p>
|
111
|
+
|
112
|
+
<p>current_air_quality = response.json_response[:sensor][:”pm2.5_a”]
|
113
|
+
```</p>
|
114
|
+
|
115
|
+
<h3 id="a-sample-service-object-for-a-lat-long-bounding-box">A sample service object for a lat-long bounding box</h3>
|
116
|
+
<p>```ruby
|
117
|
+
# frozen_string_literal: true</p>
|
118
|
+
|
119
|
+
<p>require ‘purple_air_api’
|
120
|
+
require ‘dotenv/load’</p>
|
121
|
+
|
122
|
+
<p>module AirQuality
|
123
|
+
# Class for making requests for local sensor data with a lat-long bounding box
|
124
|
+
class GetSensors
|
125
|
+
NW_LAT_LONG = [37.804930, -122.448382].freeze
|
126
|
+
SE_LAT_LONG = [37.794832, -122.393589].freeze
|
127
|
+
DEFAULT_FIELDS = %w[icon name latitude longitude altitude pm2.5 pm2.5_10minute pm2.5_30minute pm2.5_60minute].freeze
|
128
|
+
DEFAULT_LOCATION_TYPE = %w[outside].freeze</p>
|
129
|
+
|
130
|
+
<pre class="code ruby"><code class="ruby">def self.call
|
131
|
+
new.request
|
132
|
+
end
|
133
|
+
|
134
|
+
def request
|
135
|
+
PurpleAirApi.client(read_token: read_token).request_sensors(fields)
|
136
|
+
end
|
137
|
+
|
138
|
+
def read_token
|
139
|
+
ENV['READ_TOKEN']
|
140
|
+
end
|
141
|
+
|
142
|
+
def fields
|
143
|
+
{
|
144
|
+
fields: DEFAULT_FIELDS,
|
145
|
+
location_type: DEFAULT_LOCATION_TYPE,
|
146
|
+
bounding_box: { nw: NW_LAT_LONG, se: SE_LAT_LONG }
|
147
|
+
}
|
148
|
+
end end end ````
|
149
|
+
</code></pre>
|
150
|
+
|
151
|
+
<h3 id="a-sample-service-object-for-a-single-sensor">A sample service object for a single sensor</h3>
|
152
|
+
<p>```ruby
|
153
|
+
# frozen_string_literal: true</p>
|
154
|
+
|
155
|
+
<p>require ‘purple_air_api’
|
156
|
+
require ‘dotenv/load’</p>
|
157
|
+
|
158
|
+
<p>module AirQuality
|
159
|
+
# Class for making requests for an individual sensor
|
160
|
+
class GetSensor
|
161
|
+
SENSOR_INDEX = 54_849</p>
|
162
|
+
|
163
|
+
<pre class="code ruby"><code class="ruby">def self.call
|
164
|
+
new.request
|
165
|
+
end
|
166
|
+
|
167
|
+
def request
|
168
|
+
PurpleAirApi.client(read_token: read_token).request_sensor(sensor_index: SENSOR_INDEX)
|
169
|
+
end
|
170
|
+
|
171
|
+
def read_token
|
172
|
+
ENV['READ_TOKEN']
|
173
|
+
end end end ```
|
174
|
+
</code></pre>
|
175
|
+
|
176
|
+
<h3 id="in-a-sinatra-app">In a Sinatra app</h3>
|
177
|
+
|
178
|
+
<p>```ruby
|
179
|
+
# frozen_string_literal: true</p>
|
180
|
+
|
181
|
+
<p>require ‘sinatra’
|
182
|
+
require “sinatra/json”
|
183
|
+
require ‘dotenv/load’
|
184
|
+
require ‘purple_air_api’</p>
|
185
|
+
|
186
|
+
<p>module HomeHub
|
187
|
+
# App server class for running the HomeHub app
|
188
|
+
class App < Sinatra::Base</p>
|
189
|
+
|
190
|
+
<pre class="code ruby"><code class="ruby">get '/sensors/:id' do
|
191
|
+
json purple_air_client.request_sensor(sensor_index: params[:id].to_i).json_response
|
192
|
+
end
|
193
|
+
|
194
|
+
get '/sensors' do
|
195
|
+
json purple_air_client.request_sensors.json_response
|
196
|
+
end
|
197
|
+
|
198
|
+
def purple_air_client
|
199
|
+
@purple_air_client ||= PurpleAirApi.client(read_token: read_token)
|
200
|
+
end
|
201
|
+
|
202
|
+
def read_token
|
203
|
+
@read_token ||= ENV['READ_TOKEN']
|
204
|
+
end end end ```
|
205
|
+
</code></pre>
|
206
|
+
|
207
|
+
<h2 id="documentation">Documentation</h2>
|
208
|
+
|
209
|
+
<p>Documentation for this gem can be found <a href="https://dkiselbach.github.io/purple_air_api/">here.</a></p>
|
210
|
+
|
211
|
+
<h2 id="purpleair-documentation-and-read-and-write-tokens">PurpleAir Documentation and Read and Write Tokens</h2>
|
212
|
+
|
213
|
+
<p>This wrapper was written using the <a href="https://api.purpleair.com/">PurpleAir API Documentation</a>. You will require a read
|
214
|
+
and write token in order to use the PurpleAir API which can be received by <a href="https://www2.purpleair.com/pages/contact-us">reaching out to PurpleAir</a>.</p>
|
215
|
+
|
216
|
+
<h2 id="development">Development</h2>
|
217
|
+
|
218
|
+
<p>After checking out the repo, run <code>bin/setup</code> to install dependencies. Then, run <code>rake spec</code> to run the tests. You can also run <code>bin/console</code> for an interactive prompt that will allow you to experiment.</p>
|
219
|
+
|
220
|
+
<p>To install this gem onto your local machine, run <code>bundle exec rake install</code>. To release a new version, update the version number in <code>version.rb</code>, and then run <code>bundle exec rake release</code>, which will create a git tag for the version, push git commits and the created tag, and push the <code>.gem</code> file to <a href="https://rubygems.org">rubygems.org</a>.</p>
|
221
|
+
|
222
|
+
<p>Make sure you are updating the Yard docs prior to pushing to master by running <code>rake yard</code>.</p>
|
223
|
+
|
224
|
+
<h2 id="contributing">Contributing</h2>
|
225
|
+
|
226
|
+
<p>Bug reports and pull requests are welcome on GitHub at https://github.com/dkiselbach/purple_air_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the <a href="https://github.com/dkiselbach/purple_air_api/CODE_OF_CONDUCT.md">code of conduct</a>.</p>
|
227
|
+
|
228
|
+
<h2 id="license">License</h2>
|
229
|
+
|
230
|
+
<p>The gem is available as open source under the terms of the <a href="https://opensource.org/licenses/MIT">MIT License</a>.</p>
|
231
|
+
|
232
|
+
<h2 id="code-of-conduct">Code of Conduct</h2>
|
233
|
+
|
234
|
+
<p>Everyone interacting in the PurpleAirApi project’s codebase, issue trackers, chat rooms and mailing lists is expected to follow the <a href="https://github.com/dkiselbach/purple_air_api/blob/master/CODE_OF_CONDUCT.md">code of conduct</a>.</p>
|
235
|
+
|
236
|
+
<p><a href="code_of_conduct.md"><img src="https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg" alt="Contributor Covenant" /></a></p>
|
237
|
+
</div></div>
|
238
|
+
|
239
|
+
<div id="footer">
|
240
|
+
Generated on Fri Mar 12 10:06:10 2021 by
|
241
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
242
|
+
0.9.26 (ruby-3.0.0).
|
243
|
+
</div>
|
244
|
+
|
245
|
+
</div>
|
246
|
+
</body>
|
247
|
+
</html>
|