openaq-client 0.1.1 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53cc2eb6ba11d375be248fcb0390094518d4277615bea4b3c39e10fff0193afd
4
- data.tar.gz: dd1a59b861c8f44a8b2ece8fc36c7925be0712ccc02441f716618ca6c5e04755
3
+ metadata.gz: ec3e7d818623feb605f38ba22af1b82494a5d1f5e9297f9ea6f3f173805cd0e2
4
+ data.tar.gz: 91dc07c5d332c7f51e5ac548f19502507754e401d4123250ae8f188c151cd15c
5
5
  SHA512:
6
- metadata.gz: c9655a124435f37b4be0a34971c43b950b4f92b9b40975dba4ff29cb85be153c4ae9098645ff1fbe46d4e87738288693c6409bcaa34b4602563b9e25bfafc1bb
7
- data.tar.gz: a43f13591566e50856860775050bffbaceaa9e96e288c4181b0b25b0faa089990acbe94dde3c562378b6a55b1776a4cee8247748102e14933f180ecca5976466
6
+ metadata.gz: 76c35714120362bfd846e900037ac384e023c4d3c592bfe6614673fac2584719c4e9ccb64353a37080f0fc2ef08e698c078826171de2a5cce84a634d35e27692
7
+ data.tar.gz: 0ea92b91687f3ba1faf2fe327006263199a66bb4f2451187d6438a331a68c2f2521a19e9a0accdf58ef38b6e2f35d35c2c7c984f0603bd5d1325fcc1e4fe4078
@@ -4,7 +4,7 @@ module Openaq
4
4
  class Client
5
5
  include Networking
6
6
 
7
- [
7
+ ENDPOINTS = [
8
8
  :cities,
9
9
  :countries,
10
10
  :fetches,
@@ -13,15 +13,119 @@ module Openaq
13
13
  :measurements,
14
14
  :parameters,
15
15
  :sources,
16
- ].each do |name|
17
- define_method(name) do |params={}|
16
+ ].freeze
17
+
18
+ private_constant :ENDPOINTS
19
+
20
+ class << self
21
+
22
+ # @!method all_cities(params = {})
23
+ # Returns an Enumerator of {.cities}
24
+ #
25
+ # @param params please read the {https://docs.openaq.org Api Documentation}
26
+ # @return [Enumerator]
27
+
28
+ # @!method all_countries(params = {})
29
+ # Returns an Enumerator of {.countries}
30
+ #
31
+ # @param params please read the {https://docs.openaq.org Api Documentation}
32
+ # @return [Enumerator]
33
+
34
+ # @!method all_fetches(params = {})
35
+ # Returns an Enumerator of {.fetches}
36
+ #
37
+ # @param params please read the {https://docs.openaq.org Api Documentation}
38
+ # @return [Enumerator]
39
+
40
+ # @!method all_latest(params = {})
41
+ # Returns an Enumerator of {.latest}
42
+ #
43
+ # @param params please read the {https://docs.openaq.org Api Documentation}
44
+ # @return [Enumerator]
45
+
46
+ # @!method all_locations(params = {})
47
+ # Returns an Enumerator of {.locations}
48
+ #
49
+ # @param params please read the {https://docs.openaq.org Api Documentation}
50
+ # @return [Enumerator]
51
+
52
+ # @!method all_measurements(params = {})
53
+ # Returns an Enumerator of {.measurements}
54
+ #
55
+ # @param params please read the {https://docs.openaq.org Api Documentation}
56
+ # @return [Enumerator]
57
+
58
+ # @!method all_parameters(params = {})
59
+ # Returns an Enumerator of {.parameters}
60
+ #
61
+ # @param params please read the {https://docs.openaq.org Api Documentation}
62
+ # @return [Enumerator]
63
+
64
+ # @!method all_sources(params = {})
65
+ # Returns an Enumerator of {.sources}
66
+ #
67
+ # @param params please read the {https://docs.openaq.org Api Documentation}
68
+ # @return [Enumerator]
69
+
70
+ # @!method cities(params = {})
71
+ # Provides a simple listing of cities within the platform.
72
+ #
73
+ # @param params please read the {https://docs.openaq.org Api Documentation}
74
+ # @return [Array<Hash>]
75
+
76
+ # @!method countries(params = {})
77
+ # Provides a simple listing of countries within the platform.
78
+ #
79
+ # @param params please read the {https://docs.openaq.org Api Documentation}
80
+ # @return [Array<Hash>]
81
+
82
+ # @!method fetches(params = {})
83
+ # Providing data about individual fetch operations that are used to populate data in the platform.
84
+ #
85
+ # @param params please read the {https://docs.openaq.org Api Documentation}
86
+ # @return [Array<Hash>]
87
+
88
+ # @!method latest(params = {})
89
+ # Provides the latest value of each available parameter for every location in the system.
90
+ #
91
+ # @param params please read the {https://docs.openaq.org Api Documentation}
92
+ # @return [Array<Hash>]
93
+
94
+ # @!method locations(params = {})
95
+ # Provides a list of measurement locations and their meta data.
96
+ #
97
+ # @param params please read the {https://docs.openaq.org Api Documentation}
98
+ # @return [Array<Hash>]
99
+
100
+ # @!method measurements(params = {})
101
+ # Provides data about individual measurements
102
+ #
103
+ # @param params please read the {https://docs.openaq.org Api Documentation}
104
+ # @return [<Hash>]
105
+
106
+ # @!method parameters(params = {})
107
+ # Provides a simple listing of parameters within the platform.
108
+ #
109
+ # @param params please read the {https://docs.openaq.org Api Documentation}
110
+ # @return [Array<Hash>]
111
+
112
+ # @!method sources(params = {})
113
+ # Provides a list of data sources.
114
+ #
115
+ # @param params please read the {https://docs.openaq.org Api Documentation}
116
+ # @return [Array<Hash>]
117
+ end
118
+
119
+ ENDPOINTS.each do |name|
120
+ define_method(name) do |**params|
18
121
  get("/#{name}", params)
19
122
  end
20
123
 
21
- define_method(:"all_#{name}") do |params={}|
124
+ define_method(:"all_#{name}") do |**params|
22
125
  paginated_get("/#{name}", params)
23
126
  end
24
127
  end
25
128
 
129
+
26
130
  end
27
131
  end
@@ -1,6 +1,8 @@
1
1
  module Openaq
2
2
  module Networking
3
3
 
4
+ # @raise [Openaq::Error] if the request is not successful
5
+
4
6
  def get(path, params={})
5
7
  uri = URI(Openaq.url + path)
6
8
  uri.query = URI.encode_www_form(params)
@@ -19,6 +21,8 @@ module Openaq
19
21
  parsed_response["results"]
20
22
  end
21
23
 
24
+ # @raise [StopIteration] when there are no more results
25
+
22
26
  def paginated_get(path, params={})
23
27
  Enumerator.new do |yielder|
24
28
  page = 1
@@ -1,3 +1,3 @@
1
1
  module Openaq
2
- VERSION = "0.1.1".freeze
2
+ VERSION = "0.2.0".freeze
3
3
  end
@@ -2,7 +2,7 @@ RSpec.describe Openaq do
2
2
 
3
3
  it "has a version number" do
4
4
  expect(Openaq::VERSION).not_to be nil
5
- expect(Openaq::VERSION).to eql "0.1.1"
5
+ expect(Openaq::VERSION).to eql "0.2.0"
6
6
  end
7
7
 
8
8
  describe ".client" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openaq-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yiorgos Michokostas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-26 00:00:00.000000000 Z
11
+ date: 2018-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler