waqi 0.0.1 → 0.0.2

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: 3c007eefec0933a9ee71b23f34d1e10fb8ab735c
4
- data.tar.gz: e42046b21152bf858860b241a2ae7e69506c1621
3
+ metadata.gz: 46dc595364fbe07431b7c7de93d8ba223fa85f6d
4
+ data.tar.gz: fbe77ac97806f77eea4ff7f5b43af9b859d9c61c
5
5
  SHA512:
6
- metadata.gz: f28fab63e0a514ecf219ead617a9e66beb8d01cec590fec892978fd4b2636265f54169578308366555ab577f90116554e4a5fd7f00f3e45f3dc77553226c1e8a
7
- data.tar.gz: 9f2886682a72158aa1af31d4addfa8d2bfbe2e07f3fdd3cd0177f8a98016a26ff5e4cfeef0b91eb92e6d0d33ddd94c8c4b4d39e48df5175aa5616ac9264c4641
6
+ metadata.gz: 637f79ab3e7506a161a71a7c61dcf6606fc129ed87ee5a563973f9f9d2630eb6113e39e9d9323b1a8d5349c8a915fe8ee2cbe2d1ffd50c42026f6580e826a662
7
+ data.tar.gz: 63eced401a75af6e19bec5f9f39a165cd2b5d1522788b046e4d92ff1042770dfb115163ba839aa9fabd91337f93f789230187e0a8adfe2b59bb93faa99393658
@@ -1,5 +1,8 @@
1
1
  sudo: false
2
2
  language: ruby
3
+ addons:
4
+ code_climate:
5
+ repo_token: d61928e11ae93b704d1957348d005a9a87bd9b638f15a791cda062dd11766939
3
6
  rvm:
4
7
  - 2.4.0
5
8
  - 2.3.3
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 gem wrapper
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
- TODO: Write usage instructions here
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
 
@@ -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
+
@@ -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)
@@ -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: DateTime.parse("#{data[:time][:s] || data[:time][:stime]}#{data[:time][:tz]}")
14
+ timestamp: parse_time(data[:time])
15
15
  )
16
16
  end
17
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
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
@@ -2,4 +2,5 @@ require 'waqi/services/base'
2
2
  require 'waqi/services/city'
3
3
  require 'waqi/services/geolocation'
4
4
  require 'waqi/services/map'
5
+ require 'waqi/services/station'
5
6
  require 'waqi/services/search'
@@ -7,7 +7,7 @@ module Waqi
7
7
  end
8
8
 
9
9
  def path
10
- "/feed/#{@name}/"
10
+ URI.escape("/feed/#{@name}/")
11
11
  end
12
12
  end
13
13
  end
@@ -0,0 +1,9 @@
1
+ module Waqi
2
+ module Service
3
+ class Station < City
4
+ def initialize(uid)
5
+ super("@#{uid}")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Waqi
2
- VERSION = '0.0.1'.freeze
2
+ VERSION = '0.0.2'.freeze
3
3
  end
@@ -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.1
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-02-16 00:00:00.000000000 Z
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: '0'
171
+ version: '2.3'
170
172
  required_rubygems_version: !ruby/object:Gem::Requirement
171
173
  requirements:
172
174
  - - ">="