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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 46dc595364fbe07431b7c7de93d8ba223fa85f6d
4
- data.tar.gz: fbe77ac97806f77eea4ff7f5b43af9b859d9c61c
2
+ SHA256:
3
+ metadata.gz: 4c5b7b54fd42bfdfe74341dc7c3088098aa5d3bb1a173812ec326579b893e80b
4
+ data.tar.gz: 7deac837de5eaf81ac0d690b97c2f81d4a4acb1e46d9be4d4e754199871a94c6
5
5
  SHA512:
6
- metadata.gz: 637f79ab3e7506a161a71a7c61dcf6606fc129ed87ee5a563973f9f9d2630eb6113e39e9d9323b1a8d5349c8a915fe8ee2cbe2d1ffd50c42026f6580e826a662
7
- data.tar.gz: 63eced401a75af6e19bec5f9f39a165cd2b5d1522788b046e4d92ff1042770dfb115163ba839aa9fabd91337f93f789230187e0a8adfe2b59bb93faa99393658
6
+ metadata.gz: f3f30dd476fbb2b583b90803713d9313fc8c67f5d46d505e60813f8abd239c6f9f10ba3135943d72212aab4ac75eb71663f56f397b0f7b267224ee5129176931
7
+ data.tar.gz: a993ced92428ae26023d174a1bf1fd4f0452d0f506f9aa758bee10cb44e92254790a3dfc55ab87f1d701f00103c52b4cf3b13ddfcff31810527efeefc3c07b97
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2017 Luis Ezcurdia
3
+ Copyright (c) 2019 Luis Ezcurdia
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,8 +1,12 @@
1
1
  # 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)
2
+ [![CI](https://github.com/3zcurdia/waqi/actions/workflows/ci.yml/badge.svg)](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().get(token: @token)
27
+ response = Service::City.new.get(token: @token)
26
28
  StationData.parse(response)
27
29
  end
28
30
 
data/lib/waqi/error.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Waqi
4
+ class Error < RuntimeError; end
5
+ end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Waqi
2
- class Attribution < Struct.new(:name, :url)
4
+ Attribution = Struct.new(:name, :url) do
3
5
  def self.parse(hash)
4
6
  new(*hash.values_at(*members))
5
7
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Waqi
2
- class City < Struct.new(:name, :geo, :url)
4
+ City = Struct.new(:name, :geo, :url) do
3
5
  def self.parse(hash)
4
- new(*hash.values_at(*self.members))
6
+ new(*hash.values_at(*members))
5
7
  end
6
8
  end
7
9
  end
@@ -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 = hash[:city] ? City.parse(hash[:city]) : (hash[:name] ? City.parse(hash) : nil)
6
- attributions = hash[:attributions] ? hash[:attributions] : []
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
- wheather_condition = data[:iaqi] ? WeatherCondition.new(data[:iaqi]) : nil
6
- station = data[:station] ? Station.parse(data[:station]) : Station.parse(data)
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: wheather_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]}") rescue nil
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
- class StationPin < Struct.new(:lat, :lon, :uid, :aqi)
4
+ StationPin = Struct.new(:lat, :lon, :uid, :aqi) do
3
5
  def self.parse(hash)
4
- new(*hash.values_at(*self.members))
6
+ new(*hash.values_at(*members))
5
7
  end
6
8
  end
7
9
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Waqi
2
4
  class WeatherCondition
3
5
  attr_reader :carbon_monoxyde, :dew, :relative_humidity, :nitrogen_dioxide,
data/lib/waqi/models.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'waqi/models/attribution'
2
4
  require 'waqi/models/city'
3
5
  require 'waqi/models/station'
@@ -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'.freeze
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(self.path, @params.merge(options)))
16
+ parse(@connection.get(path, @params.merge(options)))
15
17
  end
16
18
 
17
19
  def path
18
- raise "path has not beed defined"
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
@@ -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
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Waqi
2
4
  module Service
3
5
  class Geolocation < Base
4
6
  def initialize(lat, lon)
5
7
  super()
6
- @lat, @lon = lat, lon
8
+ @lat = lat
9
+ @lon = lon
7
10
  end
8
11
 
9
12
  def path
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Waqi
2
4
  module Service
3
5
  class Map < Base
@@ -6,7 +8,7 @@ module Waqi
6
8
  end
7
9
 
8
10
  def path
9
- '/map/bounds/'.freeze
11
+ '/map/bounds/'
10
12
  end
11
13
  end
12
14
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Waqi
2
4
  module Service
3
5
  class Search < Base
@@ -6,7 +8,7 @@ module Waqi
6
8
  end
7
9
 
8
10
  def path
9
- '/search/'.freeze
11
+ '/search/'
10
12
  end
11
13
  end
12
14
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Waqi
2
4
  module Service
3
5
  class Station < City
data/lib/waqi/services.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'waqi/services/base'
2
4
  require 'waqi/services/city'
3
5
  require 'waqi/services/geolocation'
data/lib/waqi/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Waqi
2
- VERSION = '0.0.2'.freeze
4
+ VERSION = '0.1.0'
3
5
  end
data/lib/waqi.rb CHANGED
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'waqi/version'
4
+ require 'waqi/error'
2
5
  require 'waqi/models'
3
6
  require 'waqi/client'
4
7
 
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.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luis Ezcurdia
8
- autorequire:
9
- bindir: exe
8
+ bindir: bin
10
9
  cert_chain: []
11
- date: 2017-03-03 00:00:00.000000000 Z
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
- post_install_message:
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: '2.3'
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
- rubyforge_project:
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
@@ -1,10 +0,0 @@
1
- .DS_Store
2
- /.bundle/
3
- /.yardoc
4
- /Gemfile.lock
5
- /_yardoc/
6
- /coverage/
7
- /doc/
8
- /pkg/
9
- /spec/reports/
10
- /tmp/
data/.travis.yml DELETED
@@ -1,9 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- addons:
4
- code_climate:
5
- repo_token: d61928e11ae93b704d1957348d005a9a87bd9b638f15a791cda062dd11766939
6
- rvm:
7
- - 2.4.0
8
- - 2.3.3
9
- before_install: gem install bundler -v 1.13.2
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in waqi.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1,10 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rake/testtask'
3
-
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << 'test'
6
- t.libs << 'lib'
7
- t.test_files = FileList['test/**/*_test.rb']
8
- end
9
-
10
- task default: :test
data/bin/console DELETED
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'waqi'
5
-
6
- require 'pry'
7
- Pry.start
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
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