waqi 0.0.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 +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +26 -0
- data/Rakefile +10 -0
- data/bin/console +7 -0
- data/bin/setup +8 -0
- data/lib/waqi/client.rb +35 -0
- data/lib/waqi/models/attribution.rb +7 -0
- data/lib/waqi/models/city.rb +7 -0
- data/lib/waqi/models/station.rb +15 -0
- data/lib/waqi/models/station_data.rb +28 -0
- data/lib/waqi/models/station_pin.rb +7 -0
- data/lib/waqi/models/weather_condition.rb +22 -0
- data/lib/waqi/models.rb +6 -0
- data/lib/waqi/services/base.rb +30 -0
- data/lib/waqi/services/city.rb +14 -0
- data/lib/waqi/services/geolocation.rb +14 -0
- data/lib/waqi/services/map.rb +13 -0
- data/lib/waqi/services/search.rb +13 -0
- data/lib/waqi/services.rb +5 -0
- data/lib/waqi/version.rb +3 -0
- data/lib/waqi.rb +6 -0
- data/waqi.gemspec +30 -0
- metadata +181 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3c007eefec0933a9ee71b23f34d1e10fb8ab735c
|
4
|
+
data.tar.gz: e42046b21152bf858860b241a2ae7e69506c1621
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f28fab63e0a514ecf219ead617a9e66beb8d01cec590fec892978fd4b2636265f54169578308366555ab577f90116554e4a5fd7f00f3e45f3dc77553226c1e8a
|
7
|
+
data.tar.gz: 9f2886682a72158aa1af31d4addfa8d2bfbe2e07f3fdd3cd0177f8a98016a26ff5e4cfeef0b91eb92e6d0d33ddd94c8c4b4d39e48df5175aa5616ac9264c4641
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Luis Ezcurdia
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Waqi
|
2
|
+
[](https://travis-ci.org/3zcurdia/waqi)
|
3
|
+
|
4
|
+
Air Quality Open Data Platform gem wrapper
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'waqi'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install waqi
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
TODO: Write usage instructions here
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/3zcurdia/waqi
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
data/lib/waqi/client.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'waqi/services'
|
3
|
+
|
4
|
+
module Waqi
|
5
|
+
class Client
|
6
|
+
def initialize(token:)
|
7
|
+
@token = token
|
8
|
+
end
|
9
|
+
|
10
|
+
def city_feed(city_name)
|
11
|
+
response = Service::City.new(city_name).get(token: @token)
|
12
|
+
StationData.parse(response)
|
13
|
+
end
|
14
|
+
|
15
|
+
def geo_feed(lat, lon)
|
16
|
+
response = Service::Geolocation.new(lat,lon).get(token: @token)
|
17
|
+
StationData.parse(response)
|
18
|
+
end
|
19
|
+
|
20
|
+
def local_feed
|
21
|
+
response = Service::City.new().get(token: @token)
|
22
|
+
StationData.parse(response)
|
23
|
+
end
|
24
|
+
|
25
|
+
def map_stations(*bounds)
|
26
|
+
response = Service::Map.new(*bounds).get(token: @token)
|
27
|
+
response.map { |data| StationPin.parse(data) }
|
28
|
+
end
|
29
|
+
|
30
|
+
def search(keyword)
|
31
|
+
response = Service::Search.new(keyword).get(token: @token)
|
32
|
+
response.map { |data| StationData.parse(data) }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Waqi
|
2
|
+
class Station
|
3
|
+
attr_reader :city, :attributions
|
4
|
+
def self.parse(hash)
|
5
|
+
city = hash[:city] ? City.parse(hash[:city]) : (hash[:name] ? City.parse(hash) : {})
|
6
|
+
attributions = hash[:attributions] ? hash[:attributions] : []
|
7
|
+
new(city: city, attributions: attributions.map { |a| Attribution.parse(a) })
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(city: nil, attributions: nil)
|
11
|
+
@city = city
|
12
|
+
@attributions = attributions
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Waqi
|
2
|
+
class StationData
|
3
|
+
attr_reader :aqi, :idx, :uid, :station, :dominant_pollution, :weather_condition, :timestamp
|
4
|
+
def self.parse(data)
|
5
|
+
wheather_condition = data[:iaqi] ? WeatherCondition.new(data[:iaqi]) : {}
|
6
|
+
station = data[:station] ? Station.parse(data[:station]) : Station.parse(data)
|
7
|
+
new(
|
8
|
+
aqi: data[:aqi],
|
9
|
+
idx: data[:idx],
|
10
|
+
uid: data[:uid],
|
11
|
+
dominant_pollution: data[:dominentpol],
|
12
|
+
station: station,
|
13
|
+
weather_condition: wheather_condition,
|
14
|
+
timestamp: DateTime.parse("#{data[:time][:s] || data[:time][:stime]}#{data[:time][:tz]}")
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(aqi: nil, idx: nil, uid: nil, station: nil, dominant_pollution: nil, weather_condition: nil, timestamp: nil)
|
19
|
+
@aqi = aqi
|
20
|
+
@idx = idx
|
21
|
+
@uid = uid
|
22
|
+
@station = station
|
23
|
+
@dominant_pollution = dominant_pollution
|
24
|
+
@weather_condition = weather_condition
|
25
|
+
@timestamp = timestamp
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Waqi
|
2
|
+
class WeatherCondition
|
3
|
+
attr_reader :carbon_monoxyde, :dew, :relative_humidity, :nitrogen_dioxide,
|
4
|
+
:ozone, :atmospheric_pressure, :pm10, :pm25, :sulphur_dioxide,
|
5
|
+
:temperature, :wind
|
6
|
+
|
7
|
+
def initialize(data)
|
8
|
+
@carbon_monoxyde = data.dig(:co, :v)
|
9
|
+
@dew = data.dig(:d, :v)
|
10
|
+
@relative_humidity = data.dig(:h, :v)
|
11
|
+
@nitrogen_dioxide = data.dig(:no2, :v)
|
12
|
+
@ozone = data.dig(:o3, :v)
|
13
|
+
@atmospheric_pressure = data.dig(:p, :v)
|
14
|
+
@pm10 = data.dig(:pm10, :v)
|
15
|
+
@pm25 = data.dig(:pm25, :v)
|
16
|
+
@sulphur_dioxide = data.dig(:so2, :v)
|
17
|
+
@temperature = data.dig(:t, :v)
|
18
|
+
@wind = data.dig(:w, :v)
|
19
|
+
# @wind_direction = data.dig(:wd, :v) # unkown value?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/waqi/models.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
module Waqi
|
4
|
+
module Service
|
5
|
+
class Base
|
6
|
+
BASE_URL = 'https://api.waqi.info'.freeze
|
7
|
+
|
8
|
+
def initialize(params = {})
|
9
|
+
@connection = Faraday.new(url: BASE_URL)
|
10
|
+
@params = params
|
11
|
+
end
|
12
|
+
|
13
|
+
def get(options = {})
|
14
|
+
parse(@connection.get(self.path, @params.merge(options)))
|
15
|
+
end
|
16
|
+
|
17
|
+
def path
|
18
|
+
raise "path has not beed defined"
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def parse(response)
|
24
|
+
parsed_response = JSON.parse(response.body, symbolize_names: true)
|
25
|
+
raise "API Error: #{parsed_response[:data]}" if parsed_response[:status] == 'error'
|
26
|
+
parsed_response[:data]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/waqi/version.rb
ADDED
data/lib/waqi.rb
ADDED
data/waqi.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'waqi/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'waqi'
|
8
|
+
spec.version = Waqi::VERSION
|
9
|
+
spec.authors = ['Luis Ezcurdia']
|
10
|
+
spec.email = ['ing.ezcurdia@gmail.com']
|
11
|
+
spec.license = 'MIT'
|
12
|
+
spec.summary = 'World Air Quality ruby wrapper'
|
13
|
+
spec.description = 'Air Quality Open Data Platform ruby wrapper'
|
14
|
+
spec.homepage = 'https://github.com/3zcurdia/waqi'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'pry', '~> 0.10.3'
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
25
|
+
spec.add_development_dependency 'vcr', '~> 3.0'
|
26
|
+
spec.add_development_dependency 'webmock', '~> 2.3'
|
27
|
+
|
28
|
+
spec.add_dependency 'faraday', '~> 0.10'
|
29
|
+
spec.add_dependency 'json', '~> 2.0'
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: waqi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Luis Ezcurdia
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.10.3
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.10.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.13'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: vcr
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: faraday
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.10'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.10'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: json
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '2.0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '2.0'
|
125
|
+
description: Air Quality Open Data Platform ruby wrapper
|
126
|
+
email:
|
127
|
+
- ing.ezcurdia@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".travis.yml"
|
134
|
+
- Gemfile
|
135
|
+
- LICENSE
|
136
|
+
- README.md
|
137
|
+
- Rakefile
|
138
|
+
- bin/console
|
139
|
+
- bin/setup
|
140
|
+
- lib/waqi.rb
|
141
|
+
- lib/waqi/client.rb
|
142
|
+
- lib/waqi/models.rb
|
143
|
+
- lib/waqi/models/attribution.rb
|
144
|
+
- lib/waqi/models/city.rb
|
145
|
+
- lib/waqi/models/station.rb
|
146
|
+
- lib/waqi/models/station_data.rb
|
147
|
+
- lib/waqi/models/station_pin.rb
|
148
|
+
- lib/waqi/models/weather_condition.rb
|
149
|
+
- lib/waqi/services.rb
|
150
|
+
- lib/waqi/services/base.rb
|
151
|
+
- lib/waqi/services/city.rb
|
152
|
+
- lib/waqi/services/geolocation.rb
|
153
|
+
- lib/waqi/services/map.rb
|
154
|
+
- lib/waqi/services/search.rb
|
155
|
+
- lib/waqi/version.rb
|
156
|
+
- waqi.gemspec
|
157
|
+
homepage: https://github.com/3zcurdia/waqi
|
158
|
+
licenses:
|
159
|
+
- MIT
|
160
|
+
metadata: {}
|
161
|
+
post_install_message:
|
162
|
+
rdoc_options: []
|
163
|
+
require_paths:
|
164
|
+
- lib
|
165
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
requirements: []
|
176
|
+
rubyforge_project:
|
177
|
+
rubygems_version: 2.6.7
|
178
|
+
signing_key:
|
179
|
+
specification_version: 4
|
180
|
+
summary: World Air Quality ruby wrapper
|
181
|
+
test_files: []
|