waqi 0.0.2 → 0.1.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 +5 -5
- data/LICENSE +1 -1
- data/README.md +17 -1
- data/changelog.md +17 -0
- data/lib/waqi/client.rb +4 -2
- data/lib/waqi/error.rb +5 -0
- data/lib/waqi/models/attribution.rb +3 -1
- data/lib/waqi/models/city.rb +4 -2
- data/lib/waqi/models/station.rb +9 -2
- data/lib/waqi/models/station_data.rb +11 -4
- data/lib/waqi/models/station_pin.rb +4 -2
- data/lib/waqi/models/weather_condition.rb +2 -0
- data/lib/waqi/models.rb +2 -0
- data/lib/waqi/services/base.rb +9 -4
- data/lib/waqi/services/city.rb +5 -1
- data/lib/waqi/services/geolocation.rb +4 -1
- data/lib/waqi/services/map.rb +3 -1
- data/lib/waqi/services/search.rb +3 -1
- data/lib/waqi/services/station.rb +2 -0
- data/lib/waqi/services.rb +2 -0
- data/lib/waqi/version.rb +3 -1
- data/lib/waqi.rb +3 -0
- metadata +12 -116
- data/.gitignore +0 -10
- data/.travis.yml +0 -9
- data/Gemfile +0 -4
- data/Rakefile +0 -10
- data/bin/console +0 -7
- data/bin/setup +0 -8
- data/waqi.gemspec +0 -32
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 4c5b7b54fd42bfdfe74341dc7c3088098aa5d3bb1a173812ec326579b893e80b
|
|
4
|
+
data.tar.gz: 7deac837de5eaf81ac0d690b97c2f81d4a4acb1e46d9be4d4e754199871a94c6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f3f30dd476fbb2b583b90803713d9313fc8c67f5d46d505e60813f8abd239c6f9f10ba3135943d72212aab4ac75eb71663f56f397b0f7b267224ee5129176931
|
|
7
|
+
data.tar.gz: a993ced92428ae26023d174a1bf1fd4f0452d0f506f9aa758bee10cb44e92254790a3dfc55ab87f1d701f00103c52b4cf3b13ddfcff31810527efeefc3c07b97
|
data/LICENSE
CHANGED
data/README.md
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
# Waqi
|
|
2
|
-
[](https://github.com/3zcurdia/waqi/actions/workflows/ci.yml)
|
|
3
3
|
|
|
4
4
|
[Air Quality Open Data Platform](http://aqicn.org/api/) ruby wrapper
|
|
5
5
|
|
|
6
|
+
## Requirements
|
|
7
|
+
|
|
8
|
+
Ruby >= 4.0.0
|
|
9
|
+
|
|
6
10
|
## Installation
|
|
7
11
|
|
|
8
12
|
```ruby
|
|
@@ -61,6 +65,18 @@ Search by keyword, it returns an array of StationData
|
|
|
61
65
|
client.search('bangalore')
|
|
62
66
|
```
|
|
63
67
|
|
|
68
|
+
## Error handling
|
|
69
|
+
|
|
70
|
+
API errors raise `Waqi::Error`, a subclass of `RuntimeError`:
|
|
71
|
+
|
|
72
|
+
```ruby
|
|
73
|
+
begin
|
|
74
|
+
client.city_feed('shanghai')
|
|
75
|
+
rescue Waqi::Error => e
|
|
76
|
+
puts e.message
|
|
77
|
+
end
|
|
78
|
+
```
|
|
79
|
+
|
|
64
80
|
## Contributing
|
|
65
81
|
|
|
66
82
|
Bug reports and pull requests are welcome on GitHub at https://github.com/3zcurdia/waqi
|
data/changelog.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v0.1.0
|
|
4
|
+
|
|
5
|
+
### Breaking changes
|
|
6
|
+
- Minimum supported Ruby version is now 4.0.0; Ruby 2.3–3.x are no longer supported.
|
|
7
|
+
- Upgraded Faraday from 1.x to 2.x (`~> 2.0`).
|
|
8
|
+
- Development dependencies upgraded to minitest 6.x, pry 0.16.x, and webmock 4.x.
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- Replaced deprecated `URI.escape` with `URI::RFC2396_PARSER.escape` in `Waqi::Service::City`.
|
|
12
|
+
- Updated RuboCop target Ruby version to 4.0.
|
|
13
|
+
- Moved development dependencies from the gemspec to the `Gemfile`.
|
|
14
|
+
- Added gemspec metadata (homepage, source code, changelog URIs, MFA required).
|
|
15
|
+
- Replaced `git ls-files` with an explicit file list in the gemspec.
|
|
16
|
+
- Added `Waqi::Error` (subclass of `RuntimeError`) raised for API and JSON parse errors.
|
|
17
|
+
- Replaced Travis CI with GitHub Actions (`.github/workflows/ci.yml`).
|
|
18
|
+
- Removed `.travis.yml`.
|
|
19
|
+
|
|
3
20
|
## v0.0.1..v0.0.2
|
|
4
21
|
|
|
5
22
|
* [de87561](https://github.com/3zcurdia/waqi/commit/de875614abdfd1c01b73ae8d73b9e16be6916e1b) update version [Luis Ezcurdia](mailto:ing.ezcurdia@gmail.com)
|
data/lib/waqi/client.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'waqi/services'
|
|
2
4
|
|
|
3
5
|
module Waqi
|
|
@@ -17,12 +19,12 @@ module Waqi
|
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
def geo_feed(lat, lon)
|
|
20
|
-
response = Service::Geolocation.new(lat,lon).get(token: @token)
|
|
22
|
+
response = Service::Geolocation.new(lat, lon).get(token: @token)
|
|
21
23
|
StationData.parse(response)
|
|
22
24
|
end
|
|
23
25
|
|
|
24
26
|
def local_feed
|
|
25
|
-
response = Service::City.new
|
|
27
|
+
response = Service::City.new.get(token: @token)
|
|
26
28
|
StationData.parse(response)
|
|
27
29
|
end
|
|
28
30
|
|
data/lib/waqi/error.rb
ADDED
data/lib/waqi/models/city.rb
CHANGED
data/lib/waqi/models/station.rb
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Waqi
|
|
2
4
|
class Station
|
|
3
5
|
attr_reader :city, :attributions
|
|
6
|
+
|
|
4
7
|
def self.parse(hash)
|
|
5
|
-
city =
|
|
6
|
-
|
|
8
|
+
city = if hash[:city]
|
|
9
|
+
City.parse(hash[:city])
|
|
10
|
+
elsif hash[:name]
|
|
11
|
+
City.parse(hash)
|
|
12
|
+
end
|
|
13
|
+
attributions = hash[:attributions] || []
|
|
7
14
|
new(city: city, attributions: attributions.map { |a| Attribution.parse(a) })
|
|
8
15
|
end
|
|
9
16
|
|
|
@@ -1,22 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'date'
|
|
4
|
+
|
|
1
5
|
module Waqi
|
|
2
6
|
class StationData
|
|
3
7
|
attr_reader :aqi, :idx, :uid, :station, :dominant_pollution, :weather_condition, :timestamp
|
|
8
|
+
|
|
4
9
|
def self.parse(data)
|
|
5
|
-
|
|
6
|
-
station =
|
|
10
|
+
weather_condition = data[:iaqi] ? WeatherCondition.new(data[:iaqi]) : nil
|
|
11
|
+
station = Station.parse(data[:station] || data)
|
|
7
12
|
new(
|
|
8
13
|
aqi: data[:aqi],
|
|
9
14
|
idx: data[:idx],
|
|
10
15
|
uid: data[:uid],
|
|
11
16
|
dominant_pollution: data[:dominentpol],
|
|
12
17
|
station: station,
|
|
13
|
-
weather_condition:
|
|
18
|
+
weather_condition: weather_condition,
|
|
14
19
|
timestamp: parse_time(data[:time])
|
|
15
20
|
)
|
|
16
21
|
end
|
|
17
22
|
|
|
18
23
|
def self.parse_time(time_data)
|
|
19
|
-
DateTime.parse("#{time_data[:s] || time_data[:stime]}#{time_data[:tz]}")
|
|
24
|
+
DateTime.parse("#{time_data[:s] || time_data[:stime]}#{time_data[:tz]}")
|
|
25
|
+
rescue StandardError
|
|
26
|
+
nil
|
|
20
27
|
end
|
|
21
28
|
|
|
22
29
|
def initialize(args = {})
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Waqi
|
|
2
|
-
|
|
4
|
+
StationPin = Struct.new(:lat, :lon, :uid, :aqi) do
|
|
3
5
|
def self.parse(hash)
|
|
4
|
-
new(*hash.values_at(*
|
|
6
|
+
new(*hash.values_at(*members))
|
|
5
7
|
end
|
|
6
8
|
end
|
|
7
9
|
end
|
data/lib/waqi/models.rb
CHANGED
data/lib/waqi/services/base.rb
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'faraday'
|
|
2
4
|
require 'json'
|
|
3
5
|
module Waqi
|
|
4
6
|
module Service
|
|
5
7
|
class Base
|
|
6
|
-
BASE_URL = 'https://api.waqi.info'
|
|
8
|
+
BASE_URL = 'https://api.waqi.info'
|
|
7
9
|
|
|
8
10
|
def initialize(params = {})
|
|
9
11
|
@connection = Faraday.new(url: BASE_URL)
|
|
@@ -11,19 +13,22 @@ module Waqi
|
|
|
11
13
|
end
|
|
12
14
|
|
|
13
15
|
def get(options = {})
|
|
14
|
-
parse(@connection.get(
|
|
16
|
+
parse(@connection.get(path, @params.merge(options)))
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
def path
|
|
18
|
-
raise
|
|
20
|
+
raise NotImplementedError, 'path has not been defined'
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
private
|
|
22
24
|
|
|
23
25
|
def parse(response)
|
|
24
26
|
parsed_response = JSON.parse(response.body, symbolize_names: true)
|
|
25
|
-
raise "API Error: #{parsed_response[:data]}" if parsed_response[:status] == 'error'
|
|
27
|
+
raise Waqi::Error, "API Error: #{parsed_response[:data]}" if parsed_response[:status] == 'error'
|
|
28
|
+
|
|
26
29
|
parsed_response[:data]
|
|
30
|
+
rescue JSON::ParserError
|
|
31
|
+
raise Waqi::Error, "Invalid JSON response (HTTP #{response.status})"
|
|
27
32
|
end
|
|
28
33
|
end
|
|
29
34
|
end
|
data/lib/waqi/services/city.rb
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'uri'
|
|
4
|
+
|
|
1
5
|
module Waqi
|
|
2
6
|
module Service
|
|
3
7
|
class City < Base
|
|
@@ -7,7 +11,7 @@ module Waqi
|
|
|
7
11
|
end
|
|
8
12
|
|
|
9
13
|
def path
|
|
10
|
-
URI.escape("/feed/#{@name}/")
|
|
14
|
+
URI::RFC2396_PARSER.escape("/feed/#{@name}/")
|
|
11
15
|
end
|
|
12
16
|
end
|
|
13
17
|
end
|
data/lib/waqi/services/map.rb
CHANGED
data/lib/waqi/services/search.rb
CHANGED
data/lib/waqi/services.rb
CHANGED
data/lib/waqi/version.rb
CHANGED
data/lib/waqi.rb
CHANGED
metadata
CHANGED
|
@@ -1,115 +1,16 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: waqi
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Luis Ezcurdia
|
|
8
|
-
|
|
9
|
-
bindir: exe
|
|
8
|
+
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
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
12
|
- !ruby/object:Gem::Dependency
|
|
98
13
|
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
14
|
requirement: !ruby/object:Gem::Requirement
|
|
114
15
|
requirements:
|
|
115
16
|
- - "~>"
|
|
@@ -129,17 +30,12 @@ executables: []
|
|
|
129
30
|
extensions: []
|
|
130
31
|
extra_rdoc_files: []
|
|
131
32
|
files:
|
|
132
|
-
- ".gitignore"
|
|
133
|
-
- ".travis.yml"
|
|
134
|
-
- Gemfile
|
|
135
33
|
- LICENSE
|
|
136
34
|
- README.md
|
|
137
|
-
- Rakefile
|
|
138
|
-
- bin/console
|
|
139
|
-
- bin/setup
|
|
140
35
|
- changelog.md
|
|
141
36
|
- lib/waqi.rb
|
|
142
37
|
- lib/waqi/client.rb
|
|
38
|
+
- lib/waqi/error.rb
|
|
143
39
|
- lib/waqi/models.rb
|
|
144
40
|
- lib/waqi/models/attribution.rb
|
|
145
41
|
- lib/waqi/models/city.rb
|
|
@@ -155,29 +51,29 @@ files:
|
|
|
155
51
|
- lib/waqi/services/search.rb
|
|
156
52
|
- lib/waqi/services/station.rb
|
|
157
53
|
- lib/waqi/version.rb
|
|
158
|
-
- waqi.gemspec
|
|
159
54
|
homepage: https://github.com/3zcurdia/waqi
|
|
160
55
|
licenses:
|
|
161
56
|
- MIT
|
|
162
|
-
metadata:
|
|
163
|
-
|
|
57
|
+
metadata:
|
|
58
|
+
homepage_uri: https://github.com/3zcurdia/waqi
|
|
59
|
+
source_code_uri: https://github.com/3zcurdia/waqi
|
|
60
|
+
changelog_uri: https://github.com/3zcurdia/waqi/blob/master/changelog.md
|
|
61
|
+
rubygems_mfa_required: 'true'
|
|
164
62
|
rdoc_options: []
|
|
165
63
|
require_paths:
|
|
166
64
|
- lib
|
|
167
65
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
168
66
|
requirements:
|
|
169
|
-
- - "
|
|
67
|
+
- - ">="
|
|
170
68
|
- !ruby/object:Gem::Version
|
|
171
|
-
version:
|
|
69
|
+
version: 4.0.0
|
|
172
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
71
|
requirements:
|
|
174
72
|
- - ">="
|
|
175
73
|
- !ruby/object:Gem::Version
|
|
176
74
|
version: '0'
|
|
177
75
|
requirements: []
|
|
178
|
-
|
|
179
|
-
rubygems_version: 2.6.7
|
|
180
|
-
signing_key:
|
|
76
|
+
rubygems_version: 4.0.20
|
|
181
77
|
specification_version: 4
|
|
182
78
|
summary: World Air Quality ruby wrapper
|
|
183
79
|
test_files: []
|
data/.gitignore
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
data/bin/console
DELETED
data/bin/setup
DELETED
data/waqi.gemspec
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
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.required_ruby_version = '~> 2.3'
|
|
22
|
-
|
|
23
|
-
spec.add_development_dependency 'pry', '~> 0.10.3'
|
|
24
|
-
spec.add_development_dependency 'bundler', '~> 1.13'
|
|
25
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
|
26
|
-
spec.add_development_dependency 'minitest', '~> 5.0'
|
|
27
|
-
spec.add_development_dependency 'vcr', '~> 3.0'
|
|
28
|
-
spec.add_development_dependency 'webmock', '~> 2.3'
|
|
29
|
-
|
|
30
|
-
spec.add_dependency 'faraday', '~> 0.10'
|
|
31
|
-
spec.add_dependency 'json', '~> 2.0'
|
|
32
|
-
end
|