regio 0.1.1 → 0.3.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: 503356adbc6069f1dfd5cc6c965aef1dcd3a85bc4cf2600551bf050d45af3900
4
- data.tar.gz: 198f74020d181bbb107a00f25d933e99e54daceaa73726300f1fa76a8efb9df2
3
+ metadata.gz: 86ff1a4469844d4dac8bb93c443ea9fe502f6ccc9c797527b084632b07ea1782
4
+ data.tar.gz: 927ccf0892657b996638c674626891d52e3fb7150e2c3958745eefcab2fccc41
5
5
  SHA512:
6
- metadata.gz: f844a02af39777cf32a749b4b5df59a50a95a584359711535fcbf38b222b1e0a8a2f41530e2f1ee5718b5ca0868130c2da4c9bee718a1c84a1b5dab7c226c5c2
7
- data.tar.gz: 709352194bbb875a6e2394fdb85c22fd6bf42c74c50cd06516cac6faa39c4ab99ae4a3c3f7d78572ca97405c6d5a0857c872949381bbd31ee256e2b9de8f4e6e
6
+ metadata.gz: 4e303ab24fb83061ab0356d4aae680513c60ffd61e5160132865b562d75918b2835b506c1d63adf2ce0db914cfab84ea4160065650c22d477b747881bb949ee1
7
+ data.tar.gz: '048f9e3a8a809f4faed5e312900231f4d94ecf343eac3be83188db7ce0f76b48a38ce6a8d2b39b806fed7d7c3d993baf65b22afe1d8f5d8c6c4feb13acd006bf'
@@ -7,13 +7,17 @@ concurrency:
7
7
  cancel-in-progress: true
8
8
  jobs:
9
9
  rspec:
10
- name: RSpec
10
+ name: RSpec with ruby ${{matrix.ruby}}
11
11
  runs-on: ubuntu-latest
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ ruby: ['2.6', '2.7', '3.0', '3.1', head]
12
16
  steps:
13
17
  - uses: actions/checkout@v3
14
18
  - uses: ruby/setup-ruby@v1
15
19
  with:
16
- ruby-version: 3.1.2
20
+ ruby-version: ${{matrix.ruby}}
17
21
  bundler-cache: true
18
22
  - name: Test with RSpec
19
23
  run: COVERAGE=true bundle exec rspec
data/CHANGELOG.md CHANGED
@@ -1,12 +1,25 @@
1
1
  # Change log
2
2
 
3
+ ## v0.3.0 (02.01.2023)
4
+
5
+ * 2 major enhancements:
6
+ * Regio [routing](https://api.regio.ee/documentation/#docs/routing_and_directions)
7
+ * Regio [gazetteer](https://api.regio.ee/documentation/#docs/gazetteer)
8
+ * Minor refactoring
9
+
10
+ ## v0.2.0 (15.10.2022)
11
+
12
+ * 1 major enhancement:
13
+ * Regio [reverse geocode](https://api.regio.ee/documentation/#docs/reverse_geocode)
14
+ * Minor refactoring
15
+
3
16
  ## v0.1.1 (9.10.2022)
4
17
 
5
18
  * 1 major enhancement:
6
19
  * Regio [geocode](https://api.regio.ee/documentation/#docs/geocode)
7
20
  * Minor improvements
8
21
 
9
- ## v0.1.0 (8.10.2022)
22
+ ## v0.1.0 (9.10.2022)
10
23
 
11
24
  * 1 major enhancement:
12
25
  * Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- regio (0.1.1)
4
+ regio (0.3.0)
5
5
  httparty (~> 0.20.0)
6
6
 
7
7
  GEM
@@ -18,51 +18,51 @@ GEM
18
18
  httparty (0.20.0)
19
19
  mime-types (~> 3.0)
20
20
  multi_xml (>= 0.5.2)
21
- json (2.6.2)
21
+ json (2.6.3)
22
22
  mime-types (3.4.1)
23
23
  mime-types-data (~> 3.2015)
24
24
  mime-types-data (3.2022.0105)
25
25
  multi_xml (0.6.0)
26
26
  parallel (1.22.1)
27
- parser (3.1.2.1)
27
+ parser (3.1.3.0)
28
28
  ast (~> 2.4.1)
29
29
  public_suffix (5.0.0)
30
30
  rainbow (3.1.1)
31
31
  rake (13.0.6)
32
- regexp_parser (2.6.0)
32
+ regexp_parser (2.6.1)
33
33
  rexml (3.2.5)
34
- rspec (3.11.0)
35
- rspec-core (~> 3.11.0)
36
- rspec-expectations (~> 3.11.0)
37
- rspec-mocks (~> 3.11.0)
38
- rspec-core (3.11.0)
39
- rspec-support (~> 3.11.0)
40
- rspec-expectations (3.11.1)
34
+ rspec (3.12.0)
35
+ rspec-core (~> 3.12.0)
36
+ rspec-expectations (~> 3.12.0)
37
+ rspec-mocks (~> 3.12.0)
38
+ rspec-core (3.12.0)
39
+ rspec-support (~> 3.12.0)
40
+ rspec-expectations (3.12.0)
41
41
  diff-lcs (>= 1.2.0, < 2.0)
42
- rspec-support (~> 3.11.0)
43
- rspec-mocks (3.11.1)
42
+ rspec-support (~> 3.12.0)
43
+ rspec-mocks (3.12.0)
44
44
  diff-lcs (>= 1.2.0, < 2.0)
45
- rspec-support (~> 3.11.0)
46
- rspec-support (3.11.1)
47
- rubocop (1.36.0)
45
+ rspec-support (~> 3.12.0)
46
+ rspec-support (3.12.0)
47
+ rubocop (1.41.1)
48
48
  json (~> 2.3)
49
49
  parallel (~> 1.10)
50
50
  parser (>= 3.1.2.1)
51
51
  rainbow (>= 2.2.2, < 4.0)
52
52
  regexp_parser (>= 1.8, < 3.0)
53
53
  rexml (>= 3.2.5, < 4.0)
54
- rubocop-ast (>= 1.20.1, < 2.0)
54
+ rubocop-ast (>= 1.23.0, < 2.0)
55
55
  ruby-progressbar (~> 1.7)
56
56
  unicode-display_width (>= 1.4.0, < 3.0)
57
- rubocop-ast (1.21.0)
57
+ rubocop-ast (1.24.0)
58
58
  parser (>= 3.1.1.0)
59
- rubocop-performance (1.15.0)
59
+ rubocop-performance (1.15.2)
60
60
  rubocop (>= 1.7.0, < 2.0)
61
61
  rubocop-ast (>= 0.4.0)
62
- rubocop-rspec (2.13.2)
62
+ rubocop-rspec (2.16.0)
63
63
  rubocop (~> 1.33)
64
64
  ruby-progressbar (1.11.0)
65
- simplecov (0.21.2)
65
+ simplecov (0.22.0)
66
66
  docile (~> 1.1)
67
67
  simplecov-html (~> 0.11)
68
68
  simplecov_json_formatter (~> 0.1)
@@ -84,11 +84,11 @@ DEPENDENCIES
84
84
  bundler (~> 2.3.0)
85
85
  rake (~> 13.0.6)
86
86
  regio!
87
- rspec (~> 3.11.0)
87
+ rspec (~> 3.12.0)
88
88
  rubocop (~> 1.36)
89
89
  rubocop-performance (~> 1.15)
90
- rubocop-rspec (~> 2.13.2)
91
- simplecov (~> 0.21.2)
90
+ rubocop-rspec (~> 2.16.0)
91
+ simplecov (~> 0.22.0)
92
92
  webmock (~> 3.18.1)
93
93
 
94
94
  BUNDLED WITH
data/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
  Add this line to your application's Gemfile:
12
12
 
13
13
  ```ruby
14
- gem 'regio', '~> 0.1.1'
14
+ gem 'regio', '~> 0.3.0'
15
15
  ```
16
16
 
17
17
  And then execute:
@@ -30,7 +30,18 @@ Get your own API key
30
30
  REGIO_API_KEY=SECRET
31
31
  ```
32
32
 
33
- Use geocode class in your code
33
+ ```
34
+ export REGIO_API_KEY=SECRET && irb -I lib
35
+
36
+ irb(main):001:0> require 'regio'
37
+ => true
38
+
39
+ ...
40
+ ```
41
+
42
+ ### Geocoding
43
+
44
+ Use `Geocode` class in your code
34
45
 
35
46
  ```ruby
36
47
  require 'regio'
@@ -52,6 +63,87 @@ class Geocoding
52
63
  end
53
64
  ```
54
65
 
66
+ Check Regio [geocode](https://api.regio.ee/documentation/#docs/geocode) documentation
67
+
68
+ ### Reverse geocoding
69
+
70
+ Use `ReverseGeocode` class in your code
71
+
72
+ ```ruby
73
+ require 'regio'
74
+
75
+ class Geocoding
76
+
77
+ private
78
+
79
+ def results
80
+ @results ||= Regio::ReverseGeocode.new(options).results
81
+ end
82
+
83
+ def options
84
+ {
85
+ lat: 59.4276340999273,
86
+ lng: 24.7790924770962
87
+ }
88
+ end
89
+ end
90
+ ```
91
+
92
+ Check Regio [reverse geocode](https://api.regio.ee/documentation/#docs/reverse_geocode) documentation
93
+
94
+ ### Gazetteer
95
+
96
+ Use `Gazetteer` class in your code
97
+
98
+ ```ruby
99
+ require 'regio'
100
+
101
+ class Geocoding
102
+
103
+ private
104
+
105
+ def results
106
+ @results ||= Regio::Gazetteer.new(options).results
107
+ end
108
+
109
+ def options
110
+ {
111
+ id: 16004253,
112
+ query: 'address_children'
113
+ }
114
+ end
115
+ end
116
+ ```
117
+
118
+ Check Regio [Gazetteer](https://api.regio.ee/documentation/#docs/gazetteer) documentation
119
+
120
+ ### Routing and directions
121
+
122
+ Use `Routing` class in your code
123
+
124
+ ```ruby
125
+ require 'regio'
126
+
127
+ class Routing
128
+
129
+ private
130
+
131
+ def results
132
+ @results ||= Regio::Routing.new(options).results
133
+ end
134
+
135
+ def options
136
+ {
137
+ coordinates: [[24.649138022268, 59.14048887149], [25.853136227622, 59.00678681919]],
138
+ service: 'optimize',
139
+ overview: 'full'
140
+ }
141
+ end
142
+ end
143
+ ```
144
+
145
+ Check Regio [routing and directions](https://api.regio.ee/documentation/#docs/routing_and_directions) documentation
146
+
55
147
  ## Development
56
148
 
57
149
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/lib/regio/core.rb ADDED
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'httparty'
4
+ require 'json'
5
+
6
+ module Regio
7
+ class Core
8
+ include HTTParty
9
+ base_uri 'https://api.regio.ee'
10
+
11
+ attr_accessor :options
12
+
13
+ def initialize(options = {})
14
+ @options = default_options.merge(options)
15
+ end
16
+
17
+ COMPONENTS = [
18
+ { name: :country, type: 'A0' },
19
+ { name: :county, type: 'A1' },
20
+ { name: :municipality, type: 'A2' },
21
+ { name: :settlement, type: 'A3' },
22
+ { name: :small_place, type: 'A4' },
23
+ { name: :street, type: 'A5' },
24
+ { name: :farmstead, type: 'A6' },
25
+ { name: :house, type: 'A7' },
26
+ { name: :apartment, type: 'A8' }
27
+ ].freeze
28
+
29
+ def run(path, params = {})
30
+ JSON.parse(self.class.get(path, query: params).body, symbolize_names: true)
31
+ end
32
+
33
+ private
34
+
35
+ def transform(result)
36
+ hash = default_hash_for(result)
37
+
38
+ COMPONENTS.each do |component|
39
+ item = result[:components].detect { |o| o[:type] == component[:type] }
40
+ hash[component[:name]] = item.nil? ? nil : item[:name]
41
+ end
42
+
43
+ hash
44
+ end
45
+
46
+ def default_hash_for(result)
47
+ {
48
+ regio_id: result[:id],
49
+ title: result[:address],
50
+ valid: result[:is_valid],
51
+ complete: result[:is_complete],
52
+ zipcode: result[:postcode],
53
+ lat: result[:geometry].last,
54
+ lon: result[:geometry].first
55
+ }
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Regio
4
+ class Gazetteer < Core
5
+ def results
6
+ raise Unprocessable, response[:message] if response[:message]
7
+
8
+ response.merge(
9
+ collection: response[:data]&.map { |result| transform(result) } || []
10
+ )
11
+ end
12
+
13
+ private
14
+
15
+ def response
16
+ @response ||= run('/gazetteer', options)
17
+ end
18
+
19
+ # NOTE: all options described in the documentation
20
+ # https://api.regio.ee/documentation/#docs/gazetteer
21
+ def default_options
22
+ {
23
+ apikey: Configuration.api_key,
24
+ address_format: 'long_address',
25
+ output_format: 'json'
26
+ }
27
+ end
28
+ end
29
+ end
data/lib/regio/geocode.rb CHANGED
@@ -1,31 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'httparty'
4
- require 'json'
5
-
6
3
  module Regio
7
- class Geocode
8
- include HTTParty
9
- base_uri 'https://api.regio.ee'
10
-
11
- COMPONENTS = [
12
- { name: :country, type: 'A0' },
13
- { name: :county, type: 'A1' },
14
- { name: :municipality, type: 'A2' },
15
- { name: :settlement, type: 'A3' },
16
- { name: :small_place, type: 'A4' },
17
- { name: :street, type: 'A5' },
18
- { name: :farmstead, type: 'A6' },
19
- { name: :house, type: 'A7' },
20
- { name: :apartment, type: 'A8' }
21
- ].freeze
22
-
23
- attr_accessor :options
24
-
25
- def initialize(options = {})
26
- @options = default_options.merge(options)
27
- end
28
-
4
+ class Geocode < Core
29
5
  def results
30
6
  raise Unprocessable, response[:message] if response[:message]
31
7
 
@@ -37,7 +13,7 @@ module Regio
37
13
  private
38
14
 
39
15
  def response
40
- JSON.parse(self.class.get('/geocode', query: options).body, symbolize_names: true)
16
+ @response ||= run('/geocode', options)
41
17
  end
42
18
 
43
19
  # NOTE: all options described in the documentation
@@ -52,28 +28,5 @@ module Regio
52
28
  limit: 25
53
29
  }
54
30
  end
55
-
56
- def transform(result)
57
- hash = default_hash_for(result)
58
-
59
- COMPONENTS.each do |component|
60
- item = result[:components].detect { |o| o[:type] == component[:type] }
61
- hash[component[:name]] = item.nil? ? nil : item[:name]
62
- end
63
-
64
- hash
65
- end
66
-
67
- def default_hash_for(result)
68
- {
69
- regio_id: result[:id],
70
- title: result[:address],
71
- valid: result[:is_valid],
72
- complete: result[:is_complete],
73
- zipcode: result[:postcode],
74
- lat: result[:geometry].last,
75
- lon: result[:geometry].first
76
- }
77
- end
78
31
  end
79
32
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Regio
4
+ class ReverseGeocode < Core
5
+ def results
6
+ raise Unprocessable, response[:message] if response[:message]
7
+
8
+ response.merge(
9
+ collection: response[:data]&.map { |result| transform(result) } || []
10
+ )
11
+ end
12
+
13
+ private
14
+
15
+ def response
16
+ @response ||= run('/revgeocode', options)
17
+ end
18
+
19
+ # NOTE: all options described in the documentation
20
+ # https://api.regio.ee/documentation/#docs/reverse_geocode
21
+ def default_options
22
+ {
23
+ apikey: Configuration.api_key,
24
+ address_format: 'long_address',
25
+ details: 'id,address,postcode,type,components,geometry,is_valid,is_complete',
26
+ output_format: 'json',
27
+ limit: 25
28
+ }
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Regio
4
+ class Routing < Core
5
+ def results
6
+ response.tap do |response|
7
+ raise Unprocessable, response[:message] if response[:message]
8
+ end
9
+ end
10
+
11
+ private
12
+
13
+ def response
14
+ options[:coordinates]&.map { |lnglat| lnglat.join(',') }&.join(';')
15
+
16
+ @response ||= run('/routing', options)
17
+ end
18
+
19
+ # NOTE: all options described in the documentation
20
+ # https://api.regio.ee/documentation/#docs/routing_and_directions
21
+ def default_options
22
+ {
23
+ apikey: Configuration.api_key,
24
+ output_format: 'json',
25
+ limit: 25
26
+ }
27
+ end
28
+ end
29
+ end
data/lib/regio/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Regio
4
- VERSION = '0.1.1'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/regio.rb CHANGED
@@ -1,7 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'regio/configuration'
4
+ require 'regio/core'
5
+ require 'regio/gazetteer'
4
6
  require 'regio/geocode'
7
+ require 'regio/reverse_geocode'
8
+ require 'regio/routing'
5
9
  require 'regio/errors/failed'
6
10
  require 'regio/errors/forbidden'
7
11
  require 'regio/errors/not_found'
data/regio.gemspec CHANGED
@@ -41,11 +41,11 @@ Gem::Specification.new do |spec|
41
41
 
42
42
  spec.add_development_dependency 'bundler', '~> 2.3.0'
43
43
  spec.add_development_dependency 'rake', '~> 13.0.6'
44
- spec.add_development_dependency 'rspec', '~> 3.11.0'
44
+ spec.add_development_dependency 'rspec', '~> 3.12.0'
45
45
  spec.add_development_dependency 'rubocop', '~> 1.36'
46
46
  spec.add_development_dependency 'rubocop-performance', '~> 1.15'
47
- spec.add_development_dependency 'rubocop-rspec', '~> 2.13.2'
48
- spec.add_development_dependency 'simplecov', '~> 0.21.2'
47
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.16.0'
48
+ spec.add_development_dependency 'simplecov', '~> 0.22.0'
49
49
  spec.add_development_dependency 'webmock', '~> 3.18.1'
50
50
 
51
51
  spec.metadata['rubygems_mfa_required'] = 'true'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tab
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-09 00:00:00.000000000 Z
11
+ date: 2023-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 3.11.0
61
+ version: 3.12.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 3.11.0
68
+ version: 3.12.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rubocop
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -100,28 +100,28 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 2.13.2
103
+ version: 2.16.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 2.13.2
110
+ version: 2.16.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: simplecov
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 0.21.2
117
+ version: 0.22.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 0.21.2
124
+ version: 0.22.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: webmock
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -162,11 +162,15 @@ files:
162
162
  - bin/setup
163
163
  - lib/regio.rb
164
164
  - lib/regio/configuration.rb
165
+ - lib/regio/core.rb
165
166
  - lib/regio/errors/failed.rb
166
167
  - lib/regio/errors/forbidden.rb
167
168
  - lib/regio/errors/not_found.rb
168
169
  - lib/regio/errors/unprocessable.rb
170
+ - lib/regio/gazetteer.rb
169
171
  - lib/regio/geocode.rb
172
+ - lib/regio/reverse_geocode.rb
173
+ - lib/regio/routing.rb
170
174
  - lib/regio/version.rb
171
175
  - regio.gemspec
172
176
  homepage: https://github.com/tab/regio