ale_air 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +54 -0
- data/Rakefile +2 -0
- data/ale_air.gemspec +27 -0
- data/lib/ale_air/fetch_json.rb +86 -0
- data/lib/ale_air/version.rb +3 -0
- data/lib/ale_air.rb +5 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 30a9b15792a12c6c8cdd6b82055d379fa25404ac
|
4
|
+
data.tar.gz: b0b754805b2c9832e1a761ee9a8cdef907ca3399
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2131f08b3fa76c9a92971cd45c2e947a035e6b6b33dbda9eb291503526655356dc7159b609eaf6aa37bf35f6a12cf07dd9aafe937790ca6b6f3f00fb9ded51f2
|
7
|
+
data.tar.gz: 7381160866c562fdf33cb713201f79ad199ee7b06bd55cae11cfcc1b042c39861b49cce3340a9535253f50d29071074f451092ff4026bfd3a406fa5e9c57cac8
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
*.swp
|
23
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 eric-an
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Easy Air Quality Ruby Gem for Major Cities
|
2
|
+
|
3
|
+
This is an easy to use Gem for your Ruby projects when you wish to add air quality parameters. It uses World Air Quality Projects open api and parses the responses for ease of use. To use it go to [Air Quality Project](aqicn.org) and apply for a token (you will need it).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this to Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ale_air'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or
|
18
|
+
|
19
|
+
$ gem install ale_air
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
Add
|
23
|
+
|
24
|
+
require 'ale_air'
|
25
|
+
|
26
|
+
Just initialize first with your token
|
27
|
+
|
28
|
+
air_results = AleAir::FetchJSON.new('YOUR_TOKEN')
|
29
|
+
|
30
|
+
Now you can get the air quality where you wish. This will return true if succesful and false if some error occured
|
31
|
+
|
32
|
+
air_results.air_quality('Helsinki')
|
33
|
+
|
34
|
+
Then you can just use the results
|
35
|
+
|
36
|
+
air_results.status -- will return "ok" or "error"
|
37
|
+
air_results.message -- what kind of error occured
|
38
|
+
air_results.location -- the measurement station location
|
39
|
+
air_results.quality -- Air Quality Index scale as defined by the US-EPA 2016
|
40
|
+
air_results.time_measured -- time of measurement
|
41
|
+
air_results.danger_level -- level
|
42
|
+
|
43
|
+
## Development
|
44
|
+
|
45
|
+
Install on locally and start developing.
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
MIT License.
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
Report bugs and pull requests on GitHub at https://github.com/FistOfTheNorthStar/ale_air
|
54
|
+
|
data/Rakefile
ADDED
data/ale_air.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ale_air/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'ale_air'
|
8
|
+
s.version = AleAir::VERSION
|
9
|
+
s.summary = "Air Quality of Major Cities"
|
10
|
+
s.description = "Easy to use air quality of major cities. Everything has been parsed for you and ready to use."
|
11
|
+
s.authors = ["FistOfTheNorthStar"]
|
12
|
+
s.email = ["k.kulvik@gmail.com"]
|
13
|
+
s.homepage =
|
14
|
+
'https://github.com/FistOfTheNorthStar/ale_air'
|
15
|
+
s.license = 'MIT'
|
16
|
+
|
17
|
+
s.files = `git ls-files -z`.split("\x0")
|
18
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_development_dependency('json', '~> 2.1', '>= 2.1.0')
|
23
|
+
s.add_development_dependency('rest-client', '~> 2.0', '>= 2.0.2')
|
24
|
+
s.add_development_dependency('rspec', '~> 3.7', '>= 3.7.0')
|
25
|
+
s.add_development_dependency "rake"
|
26
|
+
s.add_development_dependency "bundler", "~> 1.6"
|
27
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
module AleAir
|
5
|
+
class FetchJSON
|
6
|
+
attr_writer :secret_token
|
7
|
+
attr_reader :status, :message, :time_measured, :location, :quality, :danger_level
|
8
|
+
|
9
|
+
def initialize(token = nil)
|
10
|
+
@secret_token = token
|
11
|
+
end
|
12
|
+
|
13
|
+
def air_quality(city = nil)
|
14
|
+
unless @secret_token.nil?
|
15
|
+
document = JSON.parse(RestClient.get 'https://api.waqi.info/search/?keyword=' + cleaned(city) + '&token=' + @secret_token)
|
16
|
+
get_info(document)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def cleaned(chars = "")
|
22
|
+
URI.encode(chars.downcase.strip)
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_info(document = nil)
|
26
|
+
@status = "error"
|
27
|
+
unless document.nil?
|
28
|
+
if document["status"] == "ok"
|
29
|
+
if document["data"].length > 0
|
30
|
+
document["data"].each do |air|
|
31
|
+
if !air["aqi"].nil? || !air["aqi"].empty?
|
32
|
+
unless is_int(air["aqi"])
|
33
|
+
@message = "Invalid Airquality Value"
|
34
|
+
return false
|
35
|
+
end
|
36
|
+
@status = "ok"
|
37
|
+
@message = "Air Quality"
|
38
|
+
@quality = air["aqi"]
|
39
|
+
@time_measured = air["time"]["stime"] + ' ' + air["time"]["tz"]
|
40
|
+
@location = air["station"]["name"]
|
41
|
+
@danger_level = danger_lev(air["aqi"].to_i)
|
42
|
+
return true
|
43
|
+
else
|
44
|
+
@message = "No Data Available"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
else
|
48
|
+
@message = "No Stations Found"
|
49
|
+
end
|
50
|
+
else
|
51
|
+
if document["message"]
|
52
|
+
@message = document["message"]
|
53
|
+
else
|
54
|
+
@message = "Unknown Error"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
return false
|
59
|
+
end
|
60
|
+
|
61
|
+
def danger_lev(aqi=0)
|
62
|
+
case aqi
|
63
|
+
when 0..50
|
64
|
+
"Good"
|
65
|
+
when 51..100
|
66
|
+
"Moderate"
|
67
|
+
when 101..150
|
68
|
+
"Unhealthy for Sensitive Groups"
|
69
|
+
when 151..200
|
70
|
+
"Unhealthy"
|
71
|
+
when 201..300
|
72
|
+
"Very Unhealthy"
|
73
|
+
else
|
74
|
+
"Hazardous"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def is_int(string)
|
79
|
+
Integer(string).is_a?(Integer)
|
80
|
+
rescue ArgumentError, TypeError
|
81
|
+
false
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
data/lib/ale_air.rb
ADDED
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ale_air
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- FistOfTheNorthStar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.1.0
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.1.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rest-client
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2.0'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 2.0.2
|
43
|
+
type: :development
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '2.0'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 2.0.2
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rspec
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '3.7'
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 3.7.0
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.7'
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 3.7.0
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: rake
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
type: :development
|
81
|
+
prerelease: false
|
82
|
+
version_requirements: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
- !ruby/object:Gem::Dependency
|
88
|
+
name: bundler
|
89
|
+
requirement: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - "~>"
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '1.6'
|
94
|
+
type: :development
|
95
|
+
prerelease: false
|
96
|
+
version_requirements: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - "~>"
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '1.6'
|
101
|
+
description: Easy to use air quality of major cities. Everything has been parsed for
|
102
|
+
you and ready to use.
|
103
|
+
email:
|
104
|
+
- k.kulvik@gmail.com
|
105
|
+
executables: []
|
106
|
+
extensions: []
|
107
|
+
extra_rdoc_files: []
|
108
|
+
files:
|
109
|
+
- ".gitignore"
|
110
|
+
- Gemfile
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- ale_air.gemspec
|
115
|
+
- lib/ale_air.rb
|
116
|
+
- lib/ale_air/fetch_json.rb
|
117
|
+
- lib/ale_air/version.rb
|
118
|
+
homepage: https://github.com/FistOfTheNorthStar/ale_air
|
119
|
+
licenses:
|
120
|
+
- MIT
|
121
|
+
metadata: {}
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 2.6.14
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: Air Quality of Major Cities
|
142
|
+
test_files: []
|