iqair_airvisual 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 +4 -4
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +112 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +65 -0
- data/Rakefile +10 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/iqair_airvisual.gemspec +38 -0
- data/lib/iqair_airvisual.rb +11 -0
- data/lib/iqair_airvisual/client.rb +144 -0
- data/lib/iqair_airvisual/community.rb +50 -0
- data/lib/iqair_airvisual/constants.rb +69 -0
- data/lib/iqair_airvisual/version.rb +3 -0
- metadata +17 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 77142172023bfce6f9454c937c14d0078d47a2f0765823d565fae636c86182d4
|
|
4
|
+
data.tar.gz: be8177bd771b1d00aa468fea3e4aac0f19bbcca212934eeb7949edc3b19a4090
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 977db9b50ea308cfa1c1c840c202b637414382bb5a5617c6ee2cb28c90c3e619e7bf058401127c427ca6a33437d594c7b954990fd763ad89ad666515d60e5b32
|
|
7
|
+
data.tar.gz: 424416e63b418036fe52869c35db598745ff2d1ccfc8a3510b16cc567996dde336e256c38c9a2fcb243066505f6e9d78538d43e44219793f3d4c848d6646d189
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behaviour that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behaviour by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualised language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behaviour and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behaviour.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviours that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behaviour may be
|
|
58
|
+
reported by contacting the project team at contact@jasonchalom.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
iqair_airvisual (0.0.2)
|
|
5
|
+
active_attr (~> 0.15)
|
|
6
|
+
httparty (~> 0.18)
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: https://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
actionpack (6.1.3.1)
|
|
12
|
+
actionview (= 6.1.3.1)
|
|
13
|
+
activesupport (= 6.1.3.1)
|
|
14
|
+
rack (~> 2.0, >= 2.0.9)
|
|
15
|
+
rack-test (>= 0.6.3)
|
|
16
|
+
rails-dom-testing (~> 2.0)
|
|
17
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
18
|
+
actionview (6.1.3.1)
|
|
19
|
+
activesupport (= 6.1.3.1)
|
|
20
|
+
builder (~> 3.1)
|
|
21
|
+
erubi (~> 1.4)
|
|
22
|
+
rails-dom-testing (~> 2.0)
|
|
23
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
24
|
+
active_attr (0.15.3)
|
|
25
|
+
actionpack (>= 3.0.2, < 7.0)
|
|
26
|
+
activemodel (>= 3.0.2, < 7.0)
|
|
27
|
+
activesupport (>= 3.0.2, < 7.0)
|
|
28
|
+
activemodel (6.1.3.1)
|
|
29
|
+
activesupport (= 6.1.3.1)
|
|
30
|
+
activesupport (6.1.3.1)
|
|
31
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
32
|
+
i18n (>= 1.6, < 2)
|
|
33
|
+
minitest (>= 5.1)
|
|
34
|
+
tzinfo (~> 2.0)
|
|
35
|
+
zeitwerk (~> 2.3)
|
|
36
|
+
addressable (2.7.0)
|
|
37
|
+
public_suffix (>= 2.0.2, < 5.0)
|
|
38
|
+
ansi (1.5.0)
|
|
39
|
+
builder (3.2.4)
|
|
40
|
+
coderay (1.1.3)
|
|
41
|
+
concurrent-ruby (1.1.8)
|
|
42
|
+
crack (0.4.5)
|
|
43
|
+
rexml
|
|
44
|
+
crass (1.0.6)
|
|
45
|
+
erubi (1.10.0)
|
|
46
|
+
hashdiff (1.0.1)
|
|
47
|
+
httparty (0.18.1)
|
|
48
|
+
mime-types (~> 3.0)
|
|
49
|
+
multi_xml (>= 0.5.2)
|
|
50
|
+
i18n (1.8.10)
|
|
51
|
+
concurrent-ruby (~> 1.0)
|
|
52
|
+
loofah (2.9.1)
|
|
53
|
+
crass (~> 1.0.2)
|
|
54
|
+
nokogiri (>= 1.5.9)
|
|
55
|
+
method_source (1.0.0)
|
|
56
|
+
mime-types (3.3.1)
|
|
57
|
+
mime-types-data (~> 3.2015)
|
|
58
|
+
mime-types-data (3.2021.0225)
|
|
59
|
+
minitest (5.14.4)
|
|
60
|
+
minitest-focus (1.1.2)
|
|
61
|
+
minitest (>= 4, < 6)
|
|
62
|
+
minitest-reporters (1.4.3)
|
|
63
|
+
ansi
|
|
64
|
+
builder
|
|
65
|
+
minitest (>= 5.0)
|
|
66
|
+
ruby-progressbar
|
|
67
|
+
mocha (1.11.2)
|
|
68
|
+
multi_xml (0.6.0)
|
|
69
|
+
nokogiri (1.11.3-x86_64-linux)
|
|
70
|
+
racc (~> 1.4)
|
|
71
|
+
pry (0.14.1)
|
|
72
|
+
coderay (~> 1.1)
|
|
73
|
+
method_source (~> 1.0)
|
|
74
|
+
public_suffix (4.0.6)
|
|
75
|
+
racc (1.5.2)
|
|
76
|
+
rack (2.2.3)
|
|
77
|
+
rack-test (1.1.0)
|
|
78
|
+
rack (>= 1.0, < 3)
|
|
79
|
+
rails-dom-testing (2.0.3)
|
|
80
|
+
activesupport (>= 4.2.0)
|
|
81
|
+
nokogiri (>= 1.6)
|
|
82
|
+
rails-html-sanitizer (1.3.0)
|
|
83
|
+
loofah (~> 2.3)
|
|
84
|
+
rake (13.0.3)
|
|
85
|
+
rexml (3.2.5)
|
|
86
|
+
ruby-progressbar (1.11.0)
|
|
87
|
+
timecop (0.9.4)
|
|
88
|
+
tzinfo (2.0.4)
|
|
89
|
+
concurrent-ruby (~> 1.0)
|
|
90
|
+
webmock (3.8.3)
|
|
91
|
+
addressable (>= 2.3.6)
|
|
92
|
+
crack (>= 0.3.2)
|
|
93
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
|
94
|
+
zeitwerk (2.4.2)
|
|
95
|
+
|
|
96
|
+
PLATFORMS
|
|
97
|
+
x86_64-linux
|
|
98
|
+
|
|
99
|
+
DEPENDENCIES
|
|
100
|
+
bundler (~> 2.2.16)
|
|
101
|
+
iqair_airvisual!
|
|
102
|
+
minitest (~> 5.0)
|
|
103
|
+
minitest-focus (~> 1.1.2)
|
|
104
|
+
minitest-reporters (~> 1.4.2)
|
|
105
|
+
mocha (~> 1.11.2)
|
|
106
|
+
pry (~> 0.13)
|
|
107
|
+
rake (~> 13.0)
|
|
108
|
+
timecop (~> 0.9.1)
|
|
109
|
+
webmock (~> 3.8.3)
|
|
110
|
+
|
|
111
|
+
BUNDLED WITH
|
|
112
|
+
2.2.16
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Jason Chalom
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 trex22
|
|
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,65 @@
|
|
|
1
|
+
# IQAir_AirVisual
|
|
2
|
+
A client for the IQAir AirVisual API.
|
|
3
|
+
|
|
4
|
+
This is an unofficial project and still a work in progress (WIP) ... more to come soon.
|
|
5
|
+
|
|
6
|
+
For API documentation see: https://api-docs.iqair.com/?version=latest
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
Add this line to your application's Gemfile:
|
|
11
|
+
|
|
12
|
+
```ruby
|
|
13
|
+
gem 'iqair_airvisual'
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
And then execute:
|
|
17
|
+
|
|
18
|
+
$ bundle
|
|
19
|
+
|
|
20
|
+
Or install it yourself as:
|
|
21
|
+
|
|
22
|
+
$ gem install iqair_airvisual
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
```ruby
|
|
27
|
+
require 'iqair_airvisual'
|
|
28
|
+
client = IQAir_AirVisual::Client.new(api_key: 'API key from website')
|
|
29
|
+
|
|
30
|
+
client.countries()
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Endpoints
|
|
34
|
+
#### Community
|
|
35
|
+
- Countries
|
|
36
|
+
- States
|
|
37
|
+
- Cities
|
|
38
|
+
- Nearest City (IP Geo-locate)
|
|
39
|
+
- Nearest City (GPS Coordinates)
|
|
40
|
+
- Nearest City (Name)
|
|
41
|
+
|
|
42
|
+
Other endpoints have not been implemented.
|
|
43
|
+
|
|
44
|
+
## Development
|
|
45
|
+
|
|
46
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
47
|
+
|
|
48
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
49
|
+
|
|
50
|
+
### Tests
|
|
51
|
+
To run tests execute:
|
|
52
|
+
|
|
53
|
+
$ rake test
|
|
54
|
+
|
|
55
|
+
## Contributing
|
|
56
|
+
|
|
57
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/trex22/vodacom-client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
62
|
+
|
|
63
|
+
## Code of Conduct
|
|
64
|
+
|
|
65
|
+
Everyone interacting in the IQAir_AirVisual: project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/trex22/IQAir_AirVisual/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "iqair_airvisual"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
require "pry"
|
|
11
|
+
Pry.start
|
data/bin/setup
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
+
require "iqair_airvisual/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "iqair_airvisual"
|
|
7
|
+
spec.version = IqairAirvisual::VERSION
|
|
8
|
+
spec.authors = ["trex22"]
|
|
9
|
+
spec.email = ["contact@jasonchalom.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "A client for using the IQAir_AirVisual API in Ruby."
|
|
12
|
+
spec.description = "A client for using the IQAir_AirVisual API in Ruby. This is an unofficial project."
|
|
13
|
+
spec.homepage = "https://github.com/TRex22/IQAir_AirVisual"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
20
|
+
end
|
|
21
|
+
spec.bindir = "exe"
|
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
23
|
+
spec.require_paths = ["lib"]
|
|
24
|
+
|
|
25
|
+
spec.add_dependency "httparty", "~> 0.18"
|
|
26
|
+
spec.add_dependency "active_attr", "~> 0.15"
|
|
27
|
+
|
|
28
|
+
# Development dependancies
|
|
29
|
+
spec.add_development_dependency "bundler", "~> 2.2.16"
|
|
30
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
|
31
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
|
32
|
+
spec.add_development_dependency "minitest-focus", "~> 1.1.2"
|
|
33
|
+
spec.add_development_dependency "minitest-reporters", "~> 1.4.2"
|
|
34
|
+
spec.add_development_dependency "timecop", "~> 0.9.1"
|
|
35
|
+
spec.add_development_dependency "mocha", "~> 1.11.2"
|
|
36
|
+
spec.add_development_dependency "pry", "~> 0.13"
|
|
37
|
+
spec.add_development_dependency "webmock", "~> 3.8.3"
|
|
38
|
+
end
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
module IqairAirvisual
|
|
2
|
+
class Client
|
|
3
|
+
include ::IqairAirvisual::Constants
|
|
4
|
+
include ::IqairAirvisual::Community
|
|
5
|
+
|
|
6
|
+
# TODO: Air quality guidelines
|
|
7
|
+
# TODO: Units breakdown
|
|
8
|
+
# TODO: Return codes
|
|
9
|
+
# https://api-docs.iqair.com/?version=latest
|
|
10
|
+
# Below are a few example of return codes you may get. This list is not exhaustive.
|
|
11
|
+
# success: returned when JSON file was generated successfully.
|
|
12
|
+
# call_limit_reached: returned when minute/monthly limit is reached.
|
|
13
|
+
# api_key_expired: returned when API key is expired.
|
|
14
|
+
# incorrect_api_key: returned when using wrong API key.
|
|
15
|
+
# ip_location_failed: returned when service is unable to locate IP address of request.
|
|
16
|
+
# no_nearest_station: returned when there is no nearest station within specified radius.
|
|
17
|
+
# feature_not_available: returned when call requests a feature that is not available in chosen subscription plan.
|
|
18
|
+
# too_many_requests: returned when more than 10 calls per second are made.
|
|
19
|
+
|
|
20
|
+
attr_reader :api_key,
|
|
21
|
+
:base_path,
|
|
22
|
+
:port,
|
|
23
|
+
:login_response,
|
|
24
|
+
:raw_cookie,
|
|
25
|
+
:expiry
|
|
26
|
+
|
|
27
|
+
def initialize(api_key:, base_path: BASE_PATH, port: 80)
|
|
28
|
+
@api_key = api_key
|
|
29
|
+
@base_path = base_path
|
|
30
|
+
@port = port
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.compatible_api_version
|
|
34
|
+
'v2'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# This is the version of the API docs this client was built off-of
|
|
38
|
+
def self.api_version
|
|
39
|
+
'v2 2021-04-18'
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def authorise_and_send(http_method:, path:, payload: {}, params: {})
|
|
45
|
+
params.merge!({ key: api_key })
|
|
46
|
+
|
|
47
|
+
start_time = get_micro_second_time
|
|
48
|
+
|
|
49
|
+
response = HTTParty.send(
|
|
50
|
+
http_method.to_sym,
|
|
51
|
+
construct_base_path(path, params),
|
|
52
|
+
body: payload,
|
|
53
|
+
headers: { 'Content-Type': 'application/json' },
|
|
54
|
+
port: port,
|
|
55
|
+
format: :json
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
end_time = get_micro_second_time
|
|
59
|
+
construct_response_object(response, path, start_time, end_time)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def construct_response_object(response, path, start_time, end_time)
|
|
63
|
+
{
|
|
64
|
+
'body' => parse_body(response, path),
|
|
65
|
+
'headers' => response.headers,
|
|
66
|
+
'metadata' => construct_metadata(response, start_time, end_time)
|
|
67
|
+
}
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def construct_metadata(response, start_time, end_time)
|
|
71
|
+
total_time = end_time - start_time
|
|
72
|
+
|
|
73
|
+
{
|
|
74
|
+
'start_time' => start_time,
|
|
75
|
+
'end_time' => end_time,
|
|
76
|
+
'total_time' => total_time
|
|
77
|
+
}
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def body_is_present?(response)
|
|
81
|
+
!body_is_missing?(response)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def body_is_missing?(response)
|
|
85
|
+
response.body.nil? || response.body.empty?
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def parse_body(response, path)
|
|
89
|
+
parsed_response = JSON.parse(response.body) # Purposely not using HTTParty
|
|
90
|
+
|
|
91
|
+
if parsed_response.dig(path.to_s)
|
|
92
|
+
parsed_response.dig(path.to_s)
|
|
93
|
+
else
|
|
94
|
+
parsed_response
|
|
95
|
+
end
|
|
96
|
+
rescue JSON::ParserError => _e
|
|
97
|
+
response.body
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def parse_cookie(set_cookie_str, key)
|
|
101
|
+
value = nil
|
|
102
|
+
expiry = nil
|
|
103
|
+
|
|
104
|
+
set_cookie_str.each do |item|
|
|
105
|
+
if item.include?(key)
|
|
106
|
+
value = item.split('; ').first.split('=').last
|
|
107
|
+
|
|
108
|
+
if item.include?('Expires') || item.include?('expires')
|
|
109
|
+
item.split('; ').each do |sub_item|
|
|
110
|
+
if sub_item.include?('Expires') || sub_item.include?('expires')
|
|
111
|
+
expiry = Time.parse(sub_item.gsub('expires=', '').gsub('Expires=', ''))
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
[value, expiry]
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def process_cookies
|
|
122
|
+
# Cookies are always a single string separated by spaces
|
|
123
|
+
raw_cookie.map { |item| item.split('; ').first }.join('; ')
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def get_micro_second_time
|
|
127
|
+
(Time.now.to_f * 1000000).to_i
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def construct_base_path(path, params)
|
|
131
|
+
constructed_path = "#{base_path}/#{path}"
|
|
132
|
+
|
|
133
|
+
if params == {}
|
|
134
|
+
constructed_path
|
|
135
|
+
else
|
|
136
|
+
"#{constructed_path}?#{process_params(params)}"
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def process_params(params)
|
|
141
|
+
params.keys.map { |key| "#{key}=#{params[key]}" }.join('&')
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
module IqairAirvisual
|
|
2
|
+
module Community
|
|
3
|
+
def countries
|
|
4
|
+
path = 'countries'
|
|
5
|
+
authorise_and_send(http_method: :get, path: path)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def states(country_name)
|
|
9
|
+
path = 'states'
|
|
10
|
+
params = { country: country_name }
|
|
11
|
+
authorise_and_send(http_method: :get, path: path, params: params)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def cities(country_name, state_name)
|
|
15
|
+
path = 'cities'
|
|
16
|
+
params = {
|
|
17
|
+
country: country_name,
|
|
18
|
+
state: state_name
|
|
19
|
+
}
|
|
20
|
+
authorise_and_send(http_method: :get, path: path, params: params)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# IP Geo-locate
|
|
24
|
+
def nearest_city(latitude: nil, longitude: nil)
|
|
25
|
+
if (latitude && !longitude) || (!latitude && longitude)
|
|
26
|
+
raise 'Both latitude and longitude are required if GPS co-ordinates specified.'
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
path = 'nearest_city'
|
|
30
|
+
|
|
31
|
+
params = {}
|
|
32
|
+
if (latitude && longitude)
|
|
33
|
+
params = { lat: latitude, lon: longitude }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
authorise_and_send(http_method: :get, path: path, params: params)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def city(country_name, state_name, city_name)
|
|
40
|
+
path = 'city'
|
|
41
|
+
params = {
|
|
42
|
+
country: country_name,
|
|
43
|
+
state: state_name,
|
|
44
|
+
city: city_name
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
authorise_and_send(http_method: :get, path: path, params: params)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
module IqairAirvisual
|
|
2
|
+
module Constants
|
|
3
|
+
BASE_PATH = 'https://api.airvisual.com/v2'
|
|
4
|
+
IMAGES_PATH = 'https://airvisual.com/images/'
|
|
5
|
+
|
|
6
|
+
# https://api-docs.iqair.com/?version=latest#important-notes
|
|
7
|
+
# https://www.airnow.gov/aqi/aqi-basics/
|
|
8
|
+
# https://www.weather.gov/safety/airquality-aqindex
|
|
9
|
+
AQI_INDEX = {
|
|
10
|
+
good: { lowest_level: 0, highest_level: 50, colour: 'green', description: 'Air quality is satisfactory, and air pollution poses little or no risk.' },
|
|
11
|
+
moderate: { lowest_level: 51, highest_level: 100, colour: 'yellow', description: 'Air quality is acceptable. However, there may be a risk for some people, particularly those who are unusually sensitive to air pollution.' },
|
|
12
|
+
unhealthy_for_sensitive_groups: { lowest_level: 101, highest_level: 150, colour: 'orange', description: 'Members of sensitive groups may experience health effects. The general public is less likely to be affected.' },
|
|
13
|
+
unhealthy: { lowest_level: 151, highest_level: 200, colour: 'red', description: 'Some members of the general public may experience health effects; members of sensitive groups may experience more serious health effects.' },
|
|
14
|
+
very_unhealthy: { lowest_level: 201, highest_level: 300, colour: 'purple', description: 'Health alert: The risk of health effects is increased for everyone.' },
|
|
15
|
+
hazardous: { lowest_level: 301, highest_level: 1000, colour: 'maroon', description: 'Health warning of emergency conditions: everyone is more likely to be affected.' }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
WEATHER_ICON_INDEX = {
|
|
19
|
+
"01d": { filename: '01d.png', url: 'https://airvisual.com/images/01d.png', description: 'clear sky (day)' },
|
|
20
|
+
"01n": { filename: '01n.png', url: 'https://airvisual.com/images/01n.png', description: 'clear sky (night)' },
|
|
21
|
+
"02d": { filename: '02d.png', url: 'https://airvisual.com/images/02d.png', description: 'few clouds (day)' },
|
|
22
|
+
"02n": { filename: '02n.png', url: 'https://airvisual.com/images/02n.png', description: 'few clouds (night)' },
|
|
23
|
+
"03d": { filename: '03d.png', url: 'https://airvisual.com/images/03d.png', description: 'scattered clouds' },
|
|
24
|
+
"04d": { filename: '04d.png', url: 'https://airvisual.com/images/04d.png', description: 'broken clouds' },
|
|
25
|
+
"09d": { filename: '09d.png', url: 'https://airvisual.com/images/09d.png', description: 'shower rain' },
|
|
26
|
+
"10d": { filename: '10d.png', url: 'https://airvisual.com/images/10d.png', description: 'rain (day time)' },
|
|
27
|
+
"10n": { filename: '10n.png', url: 'https://airvisual.com/images/10n.png', description: 'rain (night time)' },
|
|
28
|
+
"11d": { filename: '11d.png', url: 'https://airvisual.com/images/11d.png', description: 'thunderstorm' },
|
|
29
|
+
"13d": { filename: '13d.png', url: 'https://airvisual.com/images/13d.png', description: 'snow' },
|
|
30
|
+
"50d": { filename: '50d.png', url: 'https://airvisual.com/images/50d.png', description: 'mist' }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
WEATHER_CODES = {
|
|
34
|
+
ts: "timestamp",
|
|
35
|
+
aqius: "AQI value based on US EPA standard",
|
|
36
|
+
aqicn: "AQI value based on China MEP standard",
|
|
37
|
+
tp: "temperature in Celsius",
|
|
38
|
+
tp_min: "minimum temperature in Celsius",
|
|
39
|
+
pr: "atmospheric pressure in hPa",
|
|
40
|
+
hu: "humidity %",
|
|
41
|
+
ws: "wind speed (m/s)",
|
|
42
|
+
wd: "wind direction, as an angle of 360° (N=0, E=90, S=180, W=270)",
|
|
43
|
+
ic: "weather icon code, see below for icon index",
|
|
44
|
+
p: "pollutant details",
|
|
45
|
+
pn: "pollutant details",
|
|
46
|
+
p1: "pollutant details",
|
|
47
|
+
p2: "pollutant details",
|
|
48
|
+
p3: "pollutant details",
|
|
49
|
+
p4: "pollutant details",
|
|
50
|
+
conc: "concentration",
|
|
51
|
+
o3: "Ozone O3",
|
|
52
|
+
n2: "Nitrogen dioxide NO2",
|
|
53
|
+
s2: "Sulfur dioxide SO2",
|
|
54
|
+
co: "Carbon monoxide CO"
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
# object containing units information
|
|
58
|
+
UNITS = {
|
|
59
|
+
ugm3: "ug/m, Micrograms per Cubic Meter of Air",
|
|
60
|
+
ppb: "Parts per billion",
|
|
61
|
+
ppm: "Parts per million"
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
def calculate_aqi_range(key)
|
|
65
|
+
value = AQI_INDEX[:key]
|
|
66
|
+
(value.lowest_level..value.highest_level).to_a
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: iqair_airvisual
|
|
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
|
- trex22
|
|
@@ -171,7 +171,22 @@ email:
|
|
|
171
171
|
executables: []
|
|
172
172
|
extensions: []
|
|
173
173
|
extra_rdoc_files: []
|
|
174
|
-
files:
|
|
174
|
+
files:
|
|
175
|
+
- CODE_OF_CONDUCT.md
|
|
176
|
+
- Gemfile
|
|
177
|
+
- Gemfile.lock
|
|
178
|
+
- LICENSE
|
|
179
|
+
- LICENSE.txt
|
|
180
|
+
- README.md
|
|
181
|
+
- Rakefile
|
|
182
|
+
- bin/console
|
|
183
|
+
- bin/setup
|
|
184
|
+
- iqair_airvisual.gemspec
|
|
185
|
+
- lib/iqair_airvisual.rb
|
|
186
|
+
- lib/iqair_airvisual/client.rb
|
|
187
|
+
- lib/iqair_airvisual/community.rb
|
|
188
|
+
- lib/iqair_airvisual/constants.rb
|
|
189
|
+
- lib/iqair_airvisual/version.rb
|
|
175
190
|
homepage: https://github.com/TRex22/IQAir_AirVisual
|
|
176
191
|
licenses:
|
|
177
192
|
- MIT
|