waqi-ruby 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a60563e2ee0fcc73a9edbb3c6adec3a3d95bee8d735c868dcbdcfd453bceca31
4
+ data.tar.gz: ddff9dcc4bdcebce5bed4ba4a034fb85cb59fed572d4cec50eb857aeddc7fb54
5
+ SHA512:
6
+ metadata.gz: a2260858fe14fd97152ea9c745b121ec237f1d8b28ccae76ff59940b7d2a1ca49f700e98c639d24f75d339c6a63c3f7f58dec7a99e2693bc0dc7571ced3c6283
7
+ data.tar.gz: c1974a135ea87cba25b0ccf04dd761ac9b39e23a7f63e61d2142661dcc2f055d4a06efad306d766562cfc8e8d706b9e23952c2d7526a8cf9da6f73f8ed5dc011
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-09-28
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at doneazy911@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Kolawole Ezekiel
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,39 @@
1
+ # Waqi
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/waqi`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/waqi. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/waqi/blob/main/CODE_OF_CONDUCT.md).
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
36
+
37
+ ## Code of Conduct
38
+
39
+ Everyone interacting in the Waqi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/waqi/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
@@ -0,0 +1,37 @@
1
+ require 'faraday'
2
+ require "waqi/resources/city_feed"
3
+ require "waqi/resources/http_request"
4
+
5
+ module Waqi
6
+ class Client
7
+
8
+ include Waqi::Resource::CityFeed
9
+ include Waqi::Resource::HttpRequest
10
+
11
+ BASE_URL = 'https://api.waqi.info/'
12
+
13
+ attr_reader :api_key, :adapter
14
+
15
+ def initialize(api_key:, adapter: Faraday.default_adapter)
16
+ @api_key = api_key
17
+ @adapter = adapter
18
+ connection
19
+ end
20
+
21
+ private
22
+
23
+ def connection
24
+ @connection ||= Faraday.new do |conn|
25
+ conn.url_prefix = BASE_URL
26
+ conn.request :json
27
+ conn.response :json, content_type: 'application/json'
28
+ conn.response :raise_error, include_request: true
29
+ conn.adapter adapter
30
+ end
31
+ end
32
+
33
+ def inspect
34
+ self
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ module Waqi
2
+ module Errors
3
+ class ArgumentError < StandardError; end
4
+ end
5
+ end
@@ -0,0 +1,68 @@
1
+ require "waqi/errors"
2
+
3
+ module Waqi
4
+ class Resource
5
+ # Module Waqi::Resource::CityFeed provides an API for getting real-time air quality data feed.
6
+ # For more information, visit https://aqicn.org/json-api/doc
7
+ module CityFeed
8
+
9
+ # Get city/station feed
10
+ #
11
+ # @pathparams:
12
+ # @param `city` [String] - Name of the city (eg beijing), or id (eg @7397)
13
+ #
14
+ # @return [Hash] data - The station data.
15
+ # @return [string] status - The status code. can be ok or error.
16
+ def get_city_feed(city)
17
+ get("/feed/#{city}")
18
+ end
19
+
20
+ # Get gelocalized feed based on lat/lng based
21
+ #
22
+ # @pathparams:
23
+ # @param `lat` [Integer] - latitude
24
+ # @param `lng` [Integer] - longitude
25
+ #
26
+ # @return [Hash] data - The real-time air quality infomrmation..
27
+ # @return [string] status - The status code. can be ok or error.
28
+ def get_geo_feed(lat:, lng:)
29
+ get("/feed/geo:#{lat};#{lng}")
30
+ end
31
+
32
+ # Get gelocalized feed based on user's ip address
33
+ #
34
+ # @return [Hash] data - The real-time air quality infomrmation..
35
+ # @return [string] status - The status code. can be ok or error.
36
+ def get_geo_feed_by_ip
37
+ get("/feed/here")
38
+ end
39
+
40
+ # Get gelocalized feed based on user's ip address
41
+ #
42
+ # @queryParams:
43
+ # @param [Array] latlng - map bounds in the format [lat1,lng1,lat2,lng2,...]
44
+ # @param [string] networks - air quality networks list. possible options are 'all', 'official' (or 'hourly') and 'citizen' (or 'airnet').
45
+ #
46
+ # @return [Hash] data - The real-time air quality infomrmation.
47
+ # @return [string] status - The status code. can be ok or error.
48
+ def map_station(latlng:, networks: 'all')
49
+ raise Waqi::Errors::ArgumentError.new("latlng params cannot be empty") if latlng.empty?
50
+
51
+ formattedLatLng = latlng.join(',')
52
+
53
+ get("/map/bounds", params: { latlng: formattedLatLng, networks: networks })
54
+ end
55
+
56
+ # Search station by name
57
+ #
58
+ # @queryParams:
59
+ # @params [string] name - Name of the station to search
60
+ #
61
+ # @return [Hash] data - The list of station result.
62
+ # @return [string] status - The status code. can be ok or error.
63
+ def search_station(name)
64
+ get("/search/", params: { keyword: name })
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,20 @@
1
+ module Waqi
2
+ class Resource
3
+ module HttpRequest
4
+ def get(url, params: {}, headers: {})
5
+ begin
6
+ response = @connection.get(default_url(url), params, headers)
7
+ rescue Faraday::Error => e
8
+ e.response[:status]
9
+ e.response[:body]
10
+ end
11
+
12
+ response.body
13
+ end
14
+
15
+ def default_url(url)
16
+ url+"?token=#{@api_key}"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Waqi
4
+ VERSION = "1.0.0"
5
+ end
data/lib/waqi.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "waqi/version"
4
+ require_relative "waqi/client"
5
+
6
+ module Waqi
7
+ end
data/sig/waqi.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Waqi
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
data/waqi.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/waqi/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "waqi-ruby"
7
+ spec.version = Waqi::VERSION
8
+ spec.authors = ["Kolawole Ezekiel"]
9
+ spec.email = ["doneazy911@gmail.com"]
10
+
11
+ spec.summary = "A ruby client to get Real-time Air Quality data feed"
12
+ spec.description = "A ruby client to get Real-time Air Quality data feed"
13
+ spec.homepage = "https://github.com/waqi-dev-community/waqi-ruby-client"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = "https://github.com/waqi-dev-community/waqi-ruby-client/blob/main/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(__dir__) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (File.expand_path(f) == __FILE__) ||
26
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
27
+ end
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency "activesupport", ">= 6.1"
34
+ spec.add_dependency "faraday", "~> 2.0"
35
+ spec.add_development_dependency "rspec", "~> 3.2"
36
+
37
+ # For more information and examples about making a new gem, check out our
38
+ # guide at: https://bundler.io/guides/creating_gem.html
39
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: waqi-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kolawole Ezekiel
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-03-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '6.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '6.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ description: A ruby client to get Real-time Air Quality data feed
56
+ email:
57
+ - doneazy911@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - CHANGELOG.md
63
+ - CODE_OF_CONDUCT.md
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/waqi.rb
68
+ - lib/waqi/client.rb
69
+ - lib/waqi/errors.rb
70
+ - lib/waqi/resources/city_feed.rb
71
+ - lib/waqi/resources/http_request.rb
72
+ - lib/waqi/version.rb
73
+ - sig/waqi.rbs
74
+ - waqi.gemspec
75
+ homepage: https://github.com/waqi-dev-community/waqi-ruby-client
76
+ licenses:
77
+ - MIT
78
+ metadata:
79
+ homepage_uri: https://github.com/waqi-dev-community/waqi-ruby-client
80
+ source_code_uri: https://github.com/waqi-dev-community/waqi-ruby-client
81
+ changelog_uri: https://github.com/waqi-dev-community/waqi-ruby-client/blob/main/CHANGELOG.md
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 2.6.0
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubygems_version: 3.4.19
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: A ruby client to get Real-time Air Quality data feed
101
+ test_files: []