air-pollution-gem 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/pollution.rb +81 -0
  3. metadata +47 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 67fd26a7cd72f197d5350b116a418b7bc18a9cd0a707e36108dc7c816c336f7a
4
+ data.tar.gz: aad7425bba719a0dde1bb514988b380f6eea9f2d5f5b4c2e0133081a65884bd3
5
+ SHA512:
6
+ metadata.gz: c37c75d588c56b0ba05bebbd69adae6fb220e1be496b20c118fc387482ec1fc7abecb1cf0a7f6cff2a05f7915c3ec920228f5a6689c31bf5dd848ce865b0552a
7
+ data.tar.gz: 7d1fb6970935504b526c6dd1f5947b1d3a34fef7bbed312383f34ef254cfa389f430b2dcdb62f3d1e492fb30a343ddee7657867a3b647a4b01245060840ea21d
@@ -0,0 +1,81 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ class Pollution
5
+
6
+ @token
7
+
8
+ ##
9
+ # => Initialize the Pollution class and set the token variable.
10
+ ##
11
+ def initialize(token)
12
+ @token = token
13
+ end
14
+
15
+ ##
16
+ # => Returns the air pollution data of the given city or throws an error if the city wasn't found.
17
+ ##
18
+
19
+ def city(cityname)
20
+ data = JSON.parse(Net::HTTP.get('api.waqi.info', "/feed/#{cityname}/?token=#{@token}"))
21
+ if data['status'] == 'error'
22
+ raise data['data']
23
+ else
24
+ return data
25
+ end
26
+ end
27
+
28
+ ##
29
+ # => Returns the air pollution data of the current location (IP Based).
30
+ ##
31
+
32
+ def here
33
+ data = JSON.parse(Net::HTTP.get('api.waqi.info', "/feed/here/?token=#{@token}"))
34
+ if data['status'] == 'error'
35
+ raise data['data']
36
+ else
37
+ return data
38
+ end
39
+ end
40
+
41
+ ##
42
+ # => Returns the air pollution data of the given coordinates.
43
+ ##
44
+
45
+ def geo(latitude, longitude)
46
+ data = JSON.parse(Net::HTTP.get('api.waqi.info', "/feed/geo:#{latitude};#{longitude}/?token=#{@token}"))
47
+ if data['status'] == 'error'
48
+ raise data['data']
49
+ else
50
+ return data
51
+ end
52
+ end
53
+
54
+ ##
55
+ # => Returns the air pollution data of the area between the given coordinates. This method takes 4 arguments: Latitude 1, Longitude 1, Latitude 2, Longitude 2.
56
+ ##
57
+
58
+ def map(latitude_min, longitude_min, latitude_max, longitude_max)
59
+ latlng = latitude_min.to_s + longitude_min.to_s + latitude_max.to_s + longitude_max.to_s
60
+ data = JSON.parse(Net::HTTP.get('api.waqi.info', "/map/bounds/?token=#{@token}&latlng=#{latlng}"))
61
+ if data['status'] == 'error'
62
+ raise data['data']
63
+ else
64
+ return data
65
+ end
66
+ end
67
+
68
+ ##
69
+ # => Returns data about stations near the searched keyword.
70
+ ##
71
+
72
+ def search(keyword)
73
+ data = JSON.parse(Net::HTTP.get('api.waqi.info', "/search/?keyword=#{keyword}&token=#{@token}"))
74
+ if data['status'] == 'error'
75
+ raise data['data']
76
+ else
77
+ return data
78
+ end
79
+ end
80
+
81
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: air-pollution-gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Cosimo Libutti
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-12-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This is a fast and easy-to-use library which makes it easy to make queries
14
+ to the Air Pollution API. It makes it easy to send queries to the API and always
15
+ returns easy to use hashes. It also manages errors. The complete API has been implemented!
16
+ email: cos.libutti@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/pollution.rb
22
+ homepage: https://rubygems.org/gems/example
23
+ licenses:
24
+ - MIT
25
+ metadata:
26
+ source_code_uri: https://github.com/3llish/air-pollution-gem
27
+ api_docs: https://github.com/3llish/air-pollution-gem
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubygems_version: 3.0.3
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Simple wrapper for the Air Pollution API
47
+ test_files: []