lita-onewheel-aqi 0.2.2 → 1.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5429d8a42c910188d126792e6f213d9758f950af
4
- data.tar.gz: f422efbd03ed8949ec5de5a8dfae42b851935136
3
+ metadata.gz: 4ee27af471c241b1c0447e1f9b79801575ecdf41
4
+ data.tar.gz: 6de061db874e5abb3d21b07ba9e0954f215f56b8
5
5
  SHA512:
6
- metadata.gz: 13e8f26fad285dbdd7562f00eda382d0bf5257c862c1f98056a52c1b49df08512d173480a52dde958e4d55896bd9061930ef352fad2ad16482b46562cf338e93
7
- data.tar.gz: '08761236735f81bbae79b3fe47ff7388ddb81127f1c276ce72657ef379c499741250c237608c983e2b109c2343e94e8a10cfb880c0681ab07699210e8eb84152'
6
+ metadata.gz: 1974772b9eedf6d118c58e5d6f79f6ccc2f086b36274215dd25f08031ae518f427c7ec3e6b85cc6092c2a42e0abae2c4ad15ab20977bb3c80712e15b37df38d9
7
+ data.tar.gz: 7db2c3b9952cea643791290a0b10c4814b76f50cef3e27e262f4890e88fb4da17f5cd9a08be4e7a33a6ae19303b4325046778fc4cb8db12a948e4472309241a3
@@ -50,35 +50,17 @@ module Lita
50
50
  loc = geo_lookup(location)
51
51
  puts loc.inspect
52
52
 
53
- parameters = {
54
- latitude: loc[:lat],
55
- longitude: loc[:lng],
56
- api_key: config.api_key,
57
- format: 'application/json'
58
- }
59
-
60
- query_string = (parameters.map { |k, v| "#{k}=#{v}" }).join '&'
61
- uri = 'http://airnowapi.org/aq/forecast/latLong/?' + query_string
53
+ api_key = 'd4d71949d26fcaa48783808fdba32fbdc8d367eb'
54
+ uri = "http://api.waqi.info/feed/geo:#{loc[:lat]};#{loc[:lng]}/?token=#{api_key}"
62
55
  Lita.logger.debug "Getting aqi from #{uri}"
63
56
  # forecast_response = RestClient.get(uri)
64
57
  # forecasted_aqi = JSON.parse(forecast_response)
65
58
  # Lita.logger.debug 'Forecast response: ' + forecasted_aqi.inspect
66
59
 
67
- uri = 'http://airnowapi.org/aq/observation/latLong/current/?' + query_string
68
- Lita.logger.debug "Getting aqi observed from #{uri}"
69
60
  observed_response = RestClient.get(uri)
70
61
  observed_aqi = JSON.parse(observed_response)
71
62
  Lita.logger.debug 'Observed response: ' + observed_aqi.inspect
72
63
 
73
- if observed_aqi.nil? # forecasted_aqi.nil? and
74
- response.reply "No AQI data for #{loc[:name]}."
75
- Lita.logger.info "No data found for #{response.matches[0][0]}"
76
- return
77
- end
78
-
79
- # [{"DateObserved":"2015-08-23 ","HourObserved":14,"LocalTimeZone":"PST","ReportingArea":"Portland","StateCode":"OR","Latitude":45.538,"Longitude":-122.656,"ParameterName":"O3","AQI":49,"Category":{"Number":1,"Name":"Good"}},{"DateObserved":"2015-08-23 ","HourObserved":14,"LocalTimeZone":"PST","ReportingArea":"Portland","StateCode":"OR","Latitude":45.538,"Longitude":-122.656,"ParameterName":"PM2.5","AQI":167,"Category":{"Number":4,"Name":"Unhealthy"}}]
80
- # todo: extract today's forecast, not tomorrow's.
81
- # forecasted_aqi = extract_pmtwofive(forecasted_aqi)
82
64
  observed_aqi = extract_pmtwofive(observed_aqi)
83
65
 
84
66
  reply = "AQI for #{loc[:name]}, "
@@ -86,7 +68,7 @@ module Lita
86
68
  # reply += "Forecasted: #{(forecasted_aqi['ActionDay'] == 'true')? 'Action Day! ' : ''}#{forecasted_aqi['AQI']} #{forecasted_aqi['Category']['Name']} "
87
69
  # end
88
70
  unless observed_aqi == []
89
- reply += "Observed: #{color_str(observed_aqi['AQI'])} #{observed_aqi['Category']['Name']} at #{observed_aqi['DateObserved']}#{observed_aqi['HourObserved']}00 hours."
71
+ reply += "Observed: #{color_str(observed_aqi)}"
90
72
  end
91
73
  response.reply reply
92
74
  end
@@ -102,11 +84,7 @@ module Lita
102
84
  end
103
85
 
104
86
  def extract_pmtwofive(aqi)
105
- returned_aqi = aqi
106
- aqi.each do |a|
107
- returned_aqi = a if a['ParameterName'] == 'PM2.5'
108
- end
109
- returned_aqi
87
+ aqi['data']['iaqi']['pm25']['v']
110
88
  end
111
89
 
112
90
  # Geographical stuffs
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'lita-onewheel-aqi'
3
- spec.version = '0.2.2'
3
+ spec.version = '1.0.0'
4
4
  spec.authors = ['Andrew Kreps']
5
5
  spec.email = ['andrew.kreps@gmail.com']
6
6
  spec.description = 'AQI data retrieval bot'
7
- spec.summary = 'Reads the current AQI from aqinowapi.org and displays it.'
7
+ spec.summary = 'Reads the current AQI from aqicn.org and displays it.'
8
8
  spec.homepage = 'https://github.com/onewheelskyward/lita-onewheel-aqi'
9
9
  spec.license = 'MIT'
10
10
  spec.metadata = { 'lita_plugin_type' => 'handler'}
@@ -29,6 +29,6 @@ describe Lita::Handlers::OnewheelAqi, lita_handler: true do
29
29
 
30
30
  it 'queries the aqi' do
31
31
  send_command 'aqi'
32
- expect(replies.last).to include("AQI for Portland, OR, USA, Observed: \u000307118\u0003 Unhealthy for Sensitive Groups at 2017-08-09 1100 hours.")
32
+ expect(replies.last).to include("AQI for Portland, OR, USA, Observed: \u00030876\u0003")
33
33
  end
34
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-onewheel-aqi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kreps
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-09 00:00:00.000000000 Z
11
+ date: 2017-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -177,7 +177,7 @@ rubyforge_project:
177
177
  rubygems_version: 2.6.11
178
178
  signing_key:
179
179
  specification_version: 4
180
- summary: Reads the current AQI from aqinowapi.org and displays it.
180
+ summary: Reads the current AQI from aqicn.org and displays it.
181
181
  test_files:
182
182
  - spec/lita/handlers/onewheel_aqi_spec.rb
183
183
  - spec/spec_helper.rb