waqi 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/README.md +43 -3
- data/changelog.md +14 -0
- data/lib/waqi/client.rb +5 -1
- data/lib/waqi/models/station.rb +1 -1
- data/lib/waqi/models/station_data.rb +14 -10
- data/lib/waqi/services.rb +1 -0
- data/lib/waqi/services/city.rb +1 -1
- data/lib/waqi/services/station.rb +9 -0
- data/lib/waqi/version.rb +1 -1
- data/waqi.gemspec +2 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46dc595364fbe07431b7c7de93d8ba223fa85f6d
|
4
|
+
data.tar.gz: fbe77ac97806f77eea4ff7f5b43af9b859d9c61c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 637f79ab3e7506a161a71a7c61dcf6606fc129ed87ee5a563973f9f9d2630eb6113e39e9d9323b1a8d5349c8a915fe8ee2cbe2d1ffd50c42026f6580e826a662
|
7
|
+
data.tar.gz: 63eced401a75af6e19bec5f9f39a165cd2b5d1522788b046e4d92ff1042770dfb115163ba839aa9fabd91337f93f789230187e0a8adfe2b59bb93faa99393658
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Waqi
|
2
|
-
[![Build Status](https://travis-ci.org/3zcurdia/waqi.svg?branch=master)](https://travis-ci.org/3zcurdia/waqi)
|
2
|
+
[![Build Status](https://travis-ci.org/3zcurdia/waqi.svg?branch=master)](https://travis-ci.org/3zcurdia/waqi) [![Code Climate](https://lima.codeclimate.com/github/3zcurdia/waqi/badges/gpa.svg)](https://lima.codeclimate.com/github/3zcurdia/waqi)
|
3
3
|
|
4
|
-
Air Quality Open Data Platform
|
4
|
+
[Air Quality Open Data Platform](http://aqicn.org/api/) ruby wrapper
|
5
5
|
|
6
6
|
## Installation
|
7
7
|
|
@@ -19,7 +19,47 @@ Or install it yourself as:
|
|
19
19
|
|
20
20
|
## Usage
|
21
21
|
|
22
|
-
|
22
|
+
Initialize the client
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'waqi'
|
26
|
+
client = Waqi::Client.new(token: 'secret token')
|
27
|
+
```
|
28
|
+
City feed, it returns StationData
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
client.city_feed('shanghai')
|
32
|
+
```
|
33
|
+
|
34
|
+
Station feed, it returns StationData
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
client.station_feed(400)
|
38
|
+
```
|
39
|
+
|
40
|
+
Geolocalized feed, it returns StationData
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
client.geo_feed(37.774929, -122.419416)
|
44
|
+
```
|
45
|
+
|
46
|
+
Local feed, it returns the nearest StationData
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
client.local_feed
|
50
|
+
```
|
51
|
+
|
52
|
+
Feed map within bounds, it returns an array of StationPin
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
client.map_stations(39.379436, 116.091230, 40.235643, 116.784382)
|
56
|
+
```
|
57
|
+
|
58
|
+
Search by keyword, it returns an array of StationData
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
client.search('bangalore')
|
62
|
+
```
|
23
63
|
|
24
64
|
## Contributing
|
25
65
|
|
data/changelog.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## v0.0.1..v0.0.2
|
4
|
+
|
5
|
+
* [de87561](https://github.com/3zcurdia/waqi/commit/de875614abdfd1c01b73ae8d73b9e16be6916e1b) update version [Luis Ezcurdia](mailto:ing.ezcurdia@gmail.com)
|
6
|
+
* [ca6765c](https://github.com/3zcurdia/waqi/commit/ca6765cab08de087f8101948abdd92bf90c7dc46) update readme [Luis Ezcurdia](mailto:ing.ezcurdia@gmail.com)
|
7
|
+
* [105b7c9](https://github.com/3zcurdia/waqi/commit/105b7c9dda8cf8021b94cb83e074d43ed59889cd) station feed wrapper [Luis Ezcurdia](mailto:ing.ezcurdia@gmail.com)
|
8
|
+
* [a937425](https://github.com/3zcurdia/waqi/commit/a93742511df0d9702d7547b4c3cedb5fadf45261) specify ruby required version [Luis Ezcurdia](mailto:ing.ezcurdia@gmail.com)
|
9
|
+
* [7c2bde1](https://github.com/3zcurdia/waqi/commit/7c2bde1ddec85502edb6268221c2106f74e80ad8) minor parsing corrections [Luis Ezcurdia](mailto:ing.ezcurdia@gmail.com)
|
10
|
+
* [4e30065](https://github.com/3zcurdia/waqi/commit/4e30065aec714a5ad4c14425342d71217f040410) add usage on readme [Luis Ezcurdia](mailto:ing.ezcurdia@gmail.com)
|
11
|
+
* [c7bf946](https://github.com/3zcurdia/waqi/commit/c7bf9460cfad0ab1b56e0c43cf58ec4f9ca76a11) clearup args [Luis Ezcurdia](mailto:ing.ezcurdia@gmail.com)
|
12
|
+
* [066c736](https://github.com/3zcurdia/waqi/commit/066c736b2ffbde1442b0e79d3b6cfd67e95ce2d8) create stations service [Luis Ezcurdia](mailto:ing.ezcurdia@gmail.com)
|
13
|
+
* [8927258](https://github.com/3zcurdia/waqi/commit/89272584dec40048f33481425b11c763811971eb) Update README.md [Luis Ezcurdia](mailto:ing.ezcurdia@gmail.com)
|
14
|
+
|
data/lib/waqi/client.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'json'
|
2
1
|
require 'waqi/services'
|
3
2
|
|
4
3
|
module Waqi
|
@@ -7,6 +6,11 @@ module Waqi
|
|
7
6
|
@token = token
|
8
7
|
end
|
9
8
|
|
9
|
+
def station_feed(station_id)
|
10
|
+
response = Service::Station.new(station_id).get(token: @token)
|
11
|
+
StationData.parse(response)
|
12
|
+
end
|
13
|
+
|
10
14
|
def city_feed(city_name)
|
11
15
|
response = Service::City.new(city_name).get(token: @token)
|
12
16
|
StationData.parse(response)
|
data/lib/waqi/models/station.rb
CHANGED
@@ -2,7 +2,7 @@ module Waqi
|
|
2
2
|
class Station
|
3
3
|
attr_reader :city, :attributions
|
4
4
|
def self.parse(hash)
|
5
|
-
city = hash[:city] ? City.parse(hash[:city]) : (hash[:name] ? City.parse(hash) :
|
5
|
+
city = hash[:city] ? City.parse(hash[:city]) : (hash[:name] ? City.parse(hash) : nil)
|
6
6
|
attributions = hash[:attributions] ? hash[:attributions] : []
|
7
7
|
new(city: city, attributions: attributions.map { |a| Attribution.parse(a) })
|
8
8
|
end
|
@@ -2,7 +2,7 @@ module Waqi
|
|
2
2
|
class StationData
|
3
3
|
attr_reader :aqi, :idx, :uid, :station, :dominant_pollution, :weather_condition, :timestamp
|
4
4
|
def self.parse(data)
|
5
|
-
wheather_condition = data[:iaqi] ? WeatherCondition.new(data[:iaqi]) :
|
5
|
+
wheather_condition = data[:iaqi] ? WeatherCondition.new(data[:iaqi]) : nil
|
6
6
|
station = data[:station] ? Station.parse(data[:station]) : Station.parse(data)
|
7
7
|
new(
|
8
8
|
aqi: data[:aqi],
|
@@ -11,18 +11,22 @@ module Waqi
|
|
11
11
|
dominant_pollution: data[:dominentpol],
|
12
12
|
station: station,
|
13
13
|
weather_condition: wheather_condition,
|
14
|
-
timestamp:
|
14
|
+
timestamp: parse_time(data[:time])
|
15
15
|
)
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
@
|
24
|
-
@
|
25
|
-
@
|
18
|
+
def self.parse_time(time_data)
|
19
|
+
DateTime.parse("#{time_data[:s] || time_data[:stime]}#{time_data[:tz]}") rescue nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(args = {})
|
23
|
+
@aqi = args[:aqi]
|
24
|
+
@idx = args[:idx]
|
25
|
+
@uid = args[:uid]
|
26
|
+
@station = args[:station]
|
27
|
+
@dominant_pollution = args[:dominant_pollution]
|
28
|
+
@weather_condition = args[:weather_condition]
|
29
|
+
@timestamp = args[:timestamp]
|
26
30
|
end
|
27
31
|
end
|
28
32
|
end
|
data/lib/waqi/services.rb
CHANGED
data/lib/waqi/services/city.rb
CHANGED
data/lib/waqi/version.rb
CHANGED
data/waqi.gemspec
CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
+
spec.required_ruby_version = '~> 2.3'
|
22
|
+
|
21
23
|
spec.add_development_dependency 'pry', '~> 0.10.3'
|
22
24
|
spec.add_development_dependency 'bundler', '~> 1.13'
|
23
25
|
spec.add_development_dependency 'rake', '~> 10.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: waqi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luis Ezcurdia
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -137,6 +137,7 @@ files:
|
|
137
137
|
- Rakefile
|
138
138
|
- bin/console
|
139
139
|
- bin/setup
|
140
|
+
- changelog.md
|
140
141
|
- lib/waqi.rb
|
141
142
|
- lib/waqi/client.rb
|
142
143
|
- lib/waqi/models.rb
|
@@ -152,6 +153,7 @@ files:
|
|
152
153
|
- lib/waqi/services/geolocation.rb
|
153
154
|
- lib/waqi/services/map.rb
|
154
155
|
- lib/waqi/services/search.rb
|
156
|
+
- lib/waqi/services/station.rb
|
155
157
|
- lib/waqi/version.rb
|
156
158
|
- waqi.gemspec
|
157
159
|
homepage: https://github.com/3zcurdia/waqi
|
@@ -164,9 +166,9 @@ require_paths:
|
|
164
166
|
- lib
|
165
167
|
required_ruby_version: !ruby/object:Gem::Requirement
|
166
168
|
requirements:
|
167
|
-
- - "
|
169
|
+
- - "~>"
|
168
170
|
- !ruby/object:Gem::Version
|
169
|
-
version: '
|
171
|
+
version: '2.3'
|
170
172
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
173
|
requirements:
|
172
174
|
- - ">="
|