airly-client 0.0.1
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 +7 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +19 -0
- data/README.md +12 -0
- data/airly-client.gemspec +16 -0
- data/lib/airly-client.rb +53 -0
- data/lib/api/address.rb +27 -0
- data/lib/api/client.rb +39 -0
- data/lib/api/entity.rb +6 -0
- data/lib/api/installation.rb +31 -0
- data/lib/api/location.rb +11 -0
- data/lib/api/measurements.rb +29 -0
- data/lib/api/single_measurement.rb +50 -0
- data/lib/api/sponsor.rb +23 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1e77d91f6aea92ad07f54d29100bef9c1551ca4b067011d0df318b0079c1eb22
|
4
|
+
data.tar.gz: e6f204f4a04fd461e37c8bdfbf19561d0508f31d66a72ec474bf1e9b974ea83f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 89f18b4a71cee866878661f173da4ca9453a34018b74a901c7fa6e025fba9ab5ab50bcf4c6aa11eac785b3c924bebf46ff541b88e7e2faa19820e24d01007071
|
7
|
+
data.tar.gz: 71ac3c7cfc11622905de62a069f8b265c9d3bd6cb478b5b0200bcdd223692831fc41e88d361188fd8117fb40b0b4614d81e6bfbc0c6be342f718b4f58ee0bf6f
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
httparty (0.17.1)
|
5
|
+
mime-types (~> 3.0)
|
6
|
+
multi_xml (>= 0.5.2)
|
7
|
+
mime-types (3.3)
|
8
|
+
mime-types-data (~> 3.2015)
|
9
|
+
mime-types-data (3.2019.0904)
|
10
|
+
multi_xml (0.6.0)
|
11
|
+
|
12
|
+
PLATFORMS
|
13
|
+
ruby
|
14
|
+
|
15
|
+
DEPENDENCIES
|
16
|
+
httparty (~> 0.17.1)
|
17
|
+
|
18
|
+
BUNDLED WITH
|
19
|
+
1.17.2
|
data/README.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# AirlyClient
|
2
|
+
|
3
|
+
AirlyClient is a ruby client for [airly.eu](https://airly.eu/) API.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
```
|
8
|
+
AirlyClient.set_api_key(key) # Setup API key
|
9
|
+
AirlyClient.nearest_installation(latitude, longtitude, max_distance_km: distance, max_results: results) # Find nearest installations
|
10
|
+
AirlyClient.installation(id) # Get installation data by id
|
11
|
+
AirlyClient.measurements(installation_id) # Get measurements for station
|
12
|
+
```
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'airly-client'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.date = '2019-10-08'
|
5
|
+
s.summary = "Client for airly.eu api"
|
6
|
+
s.description = "Simple client for fetching information from airly.eu"
|
7
|
+
s.authors = ["kuskoman"]
|
8
|
+
s.email = 'kubasurdej@gmail.com'
|
9
|
+
s.files = `git ls-files -z`.split("\x0")
|
10
|
+
s.require_paths = ["lib"]
|
11
|
+
s.homepage =
|
12
|
+
'https://github.com/kuskoman/airly-client'
|
13
|
+
s.license = 'MIT'
|
14
|
+
|
15
|
+
s.add_dependency 'httparty', '~> 0.17.1'
|
16
|
+
end
|
data/lib/airly-client.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require_relative 'api/client'
|
2
|
+
require_relative 'api/entity'
|
3
|
+
require_relative 'api/installation'
|
4
|
+
require_relative 'api/measurements'
|
5
|
+
|
6
|
+
require 'httparty'
|
7
|
+
require 'uri'
|
8
|
+
|
9
|
+
module AirlyClient
|
10
|
+
class << self
|
11
|
+
def api
|
12
|
+
@client ||= ApiClient.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def set_api_key(api_key)
|
16
|
+
api.api_key = api_key
|
17
|
+
end
|
18
|
+
|
19
|
+
def nearest_installation(latitude, longtitude, max_distance_km: 5, max_results: 1)
|
20
|
+
res = api.make_request("installations/nearest",
|
21
|
+
{
|
22
|
+
"lat" => latitude,
|
23
|
+
"lng" => longtitude,
|
24
|
+
"maxDistanceKM" => max_distance_km,
|
25
|
+
"maxResults" => max_results
|
26
|
+
})
|
27
|
+
|
28
|
+
installations = []
|
29
|
+
|
30
|
+
res.each do |raw|
|
31
|
+
installations << Installation.new(raw)
|
32
|
+
end
|
33
|
+
|
34
|
+
installations
|
35
|
+
end
|
36
|
+
|
37
|
+
def installation(id)
|
38
|
+
res = api.make_request("installations/#{id}")
|
39
|
+
|
40
|
+
Installation.new(res)
|
41
|
+
end
|
42
|
+
|
43
|
+
def measurements(installation_id, index_type = 'AIRLY_CAQI')
|
44
|
+
res = api.make_request("measurements/installation",
|
45
|
+
{
|
46
|
+
"installationId" => installation_id,
|
47
|
+
"indexType" => index_type
|
48
|
+
})
|
49
|
+
|
50
|
+
Measurements.new(res)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/api/address.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module AirlyClient
|
2
|
+
class Address < Entity
|
3
|
+
def country
|
4
|
+
@raw['country']
|
5
|
+
end
|
6
|
+
|
7
|
+
def city
|
8
|
+
@raw['city']
|
9
|
+
end
|
10
|
+
|
11
|
+
def street
|
12
|
+
@raw['street']
|
13
|
+
end
|
14
|
+
|
15
|
+
def number
|
16
|
+
@raw['number']
|
17
|
+
end
|
18
|
+
|
19
|
+
def display_address1
|
20
|
+
@raw['displayAddress1']
|
21
|
+
end
|
22
|
+
|
23
|
+
def display_address2
|
24
|
+
@raw['displayAddress2']
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/api/client.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
module AirlyClient
|
2
|
+
class ApiClient
|
3
|
+
attr_writer :api_key
|
4
|
+
def initialize(api_key = nil, base_url = "https://airapi.airly.eu/v2/")
|
5
|
+
@api_key = api_key
|
6
|
+
@base_url = base_url
|
7
|
+
end
|
8
|
+
|
9
|
+
def make_request(resource, params = {})
|
10
|
+
res = fetch(resource, params)
|
11
|
+
JSON.parse(res.body)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def fetch(resource, params)
|
17
|
+
HTTParty.get(
|
18
|
+
@base_url + resource + stringify_params(params),
|
19
|
+
headers: headers
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def headers
|
24
|
+
{
|
25
|
+
'Accept' => 'application/json',
|
26
|
+
'Accept-Language' => 'en',
|
27
|
+
'apikey' => @api_key
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def stringify_params(params)
|
32
|
+
if params.nil?
|
33
|
+
""
|
34
|
+
else
|
35
|
+
"?" + URI.encode_www_form(params)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/api/entity.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'location'
|
2
|
+
require_relative 'address'
|
3
|
+
require_relative 'sponsor'
|
4
|
+
|
5
|
+
module AirlyClient
|
6
|
+
class Installation < Entity
|
7
|
+
def id
|
8
|
+
@raw['id']
|
9
|
+
end
|
10
|
+
|
11
|
+
def location
|
12
|
+
@location ||= Location.new(@raw['location'])
|
13
|
+
end
|
14
|
+
|
15
|
+
def elevation
|
16
|
+
@raw['elevation']
|
17
|
+
end
|
18
|
+
|
19
|
+
def address
|
20
|
+
@address ||= Address.new(@raw['address'])
|
21
|
+
end
|
22
|
+
|
23
|
+
def airly
|
24
|
+
@raw['airly']
|
25
|
+
end
|
26
|
+
|
27
|
+
def sponsor
|
28
|
+
@sponsor ||= Sponsor.new(@raw['sponsor'])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/api/location.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'single_measurement'
|
2
|
+
|
3
|
+
module AirlyClient
|
4
|
+
class Measurements < Entity
|
5
|
+
def current
|
6
|
+
@current ||= SingleMeasurement.new(@raw['current'])
|
7
|
+
end
|
8
|
+
|
9
|
+
def history
|
10
|
+
@history ||= parse_array_of_measurements(@raw['history'])
|
11
|
+
end
|
12
|
+
|
13
|
+
def forecast
|
14
|
+
@forecast ||= parse_array_of_measurements(@raw['forecast'])
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def parse_array_of_measurements(array)
|
20
|
+
parsed = []
|
21
|
+
|
22
|
+
array.each do |measurement|
|
23
|
+
parsed << SingleMeasurement.new(measurement)
|
24
|
+
end
|
25
|
+
|
26
|
+
parsed
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module AirlyClient
|
2
|
+
class SingleMeasurement < Entity
|
3
|
+
def initialize(raw)
|
4
|
+
super
|
5
|
+
parse_values
|
6
|
+
end
|
7
|
+
|
8
|
+
def from_date_time
|
9
|
+
@raw['fromDateTime']
|
10
|
+
end
|
11
|
+
|
12
|
+
def till_date_time
|
13
|
+
@raw['tillDatetime']
|
14
|
+
end
|
15
|
+
|
16
|
+
def pm1
|
17
|
+
@values['PM1']
|
18
|
+
end
|
19
|
+
|
20
|
+
def pm10
|
21
|
+
@values['PM10']
|
22
|
+
end
|
23
|
+
|
24
|
+
def pm25
|
25
|
+
@values['PM25']
|
26
|
+
end
|
27
|
+
|
28
|
+
def pressure
|
29
|
+
@values['PRESSURE']
|
30
|
+
end
|
31
|
+
|
32
|
+
def humidity
|
33
|
+
@values['HUMIDITY']
|
34
|
+
end
|
35
|
+
|
36
|
+
def temperature
|
37
|
+
@values['TEMPERATURE']
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def parse_values
|
43
|
+
@values = {}
|
44
|
+
@raw['values'].each do |value|
|
45
|
+
name = value['name']
|
46
|
+
@values[name] = value['value']
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/api/sponsor.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module AirlyClient
|
2
|
+
class Sponsor < Entity
|
3
|
+
def id
|
4
|
+
@raw['id']
|
5
|
+
end
|
6
|
+
|
7
|
+
def name
|
8
|
+
@raw['name']
|
9
|
+
end
|
10
|
+
|
11
|
+
def description
|
12
|
+
@raw['description']
|
13
|
+
end
|
14
|
+
|
15
|
+
def logo
|
16
|
+
@raw['logo']
|
17
|
+
end
|
18
|
+
|
19
|
+
def link
|
20
|
+
@raw['link']
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: airly-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kuskoman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-10-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.17.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.17.1
|
27
|
+
description: Simple client for fetching information from airly.eu
|
28
|
+
email: kubasurdej@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- Gemfile
|
34
|
+
- Gemfile.lock
|
35
|
+
- README.md
|
36
|
+
- airly-client.gemspec
|
37
|
+
- lib/airly-client.rb
|
38
|
+
- lib/api/address.rb
|
39
|
+
- lib/api/client.rb
|
40
|
+
- lib/api/entity.rb
|
41
|
+
- lib/api/installation.rb
|
42
|
+
- lib/api/location.rb
|
43
|
+
- lib/api/measurements.rb
|
44
|
+
- lib/api/single_measurement.rb
|
45
|
+
- lib/api/sponsor.rb
|
46
|
+
homepage: https://github.com/kuskoman/airly-client
|
47
|
+
licenses:
|
48
|
+
- MIT
|
49
|
+
metadata: {}
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubygems_version: 3.0.3
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: Client for airly.eu api
|
69
|
+
test_files: []
|