regio 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 503356adbc6069f1dfd5cc6c965aef1dcd3a85bc4cf2600551bf050d45af3900
4
- data.tar.gz: 198f74020d181bbb107a00f25d933e99e54daceaa73726300f1fa76a8efb9df2
3
+ metadata.gz: 58f1f77fb4ff83302a5591e138bface9f60913e2649727bee81b7460067d8d44
4
+ data.tar.gz: 7e10c3b4eb3826aaf0865888c98507f3cdf5a97e550f3100e8f91beb89bffe41
5
5
  SHA512:
6
- metadata.gz: f844a02af39777cf32a749b4b5df59a50a95a584359711535fcbf38b222b1e0a8a2f41530e2f1ee5718b5ca0868130c2da4c9bee718a1c84a1b5dab7c226c5c2
7
- data.tar.gz: 709352194bbb875a6e2394fdb85c22fd6bf42c74c50cd06516cac6faa39c4ab99ae4a3c3f7d78572ca97405c6d5a0857c872949381bbd31ee256e2b9de8f4e6e
6
+ metadata.gz: 6702d492cb1b10ee6f6795ef16be9c1d7f8e36009d2e3667e513974b642ceed446c41a83e106b832176aa90f7eadc05d7185fb5c5f24b23f1a0e8676bb68975f
7
+ data.tar.gz: a9e6cf6a456cdcda8d5abb1adb718199df81295aca6bc1fe7d488276b5f6a7ba1aa6eb94f35435fb34e551b5c6bc3da9eabab1e26534918dd68bea080914f5e8
data/CHANGELOG.md CHANGED
@@ -1,12 +1,18 @@
1
1
  # Change log
2
2
 
3
+ ## v0.2.0 (15.10.2022)
4
+
5
+ * 1 major enhancement:
6
+ * Regio [reverse geocode](https://api.regio.ee/documentation/#docs/reverse_geocode)
7
+ * Minor refactoring
8
+
3
9
  ## v0.1.1 (9.10.2022)
4
10
 
5
11
  * 1 major enhancement:
6
12
  * Regio [geocode](https://api.regio.ee/documentation/#docs/geocode)
7
13
  * Minor improvements
8
14
 
9
- ## v0.1.0 (8.10.2022)
15
+ ## v0.1.0 (9.10.2022)
10
16
 
11
17
  * 1 major enhancement:
12
18
  * 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.2.0)
5
5
  httparty (~> 0.20.0)
6
6
 
7
7
  GEM
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.2.0'
15
15
  ```
16
16
 
17
17
  And then execute:
@@ -30,7 +30,9 @@ Get your own API key
30
30
  REGIO_API_KEY=SECRET
31
31
  ```
32
32
 
33
- Use geocode class in your code
33
+ ### Geocoding
34
+
35
+ Use `Geocode` class in your code
34
36
 
35
37
  ```ruby
36
38
  require 'regio'
@@ -52,6 +54,35 @@ class Geocoding
52
54
  end
53
55
  ```
54
56
 
57
+ Check Regio [geocode](https://api.regio.ee/documentation/#docs/geocode) documentation
58
+
59
+
60
+ ### Reverse geocoding
61
+
62
+ Use `ReverseGeocode` class in your code
63
+
64
+ ```ruby
65
+ require 'regio'
66
+
67
+ class Geocoding
68
+
69
+ private
70
+
71
+ def results
72
+ @results ||= Regio::ReverseGeocode.new(options).results
73
+ end
74
+
75
+ def options
76
+ {
77
+ lat: 59.4276340999273,
78
+ lng: 24.7790924770962
79
+ }
80
+ end
81
+ end
82
+ ```
83
+
84
+ Check Regio [reverse geocode](https://api.regio.ee/documentation/#docs/reverse_geocode) documentation
85
+
55
86
  ## Development
56
87
 
57
88
  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
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
+ 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
+ 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
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.2.0'
5
5
  end
data/lib/regio.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'regio/configuration'
4
+ require 'regio/core'
4
5
  require 'regio/geocode'
6
+ require 'regio/reverse_geocode'
5
7
  require 'regio/errors/failed'
6
8
  require 'regio/errors/forbidden'
7
9
  require 'regio/errors/not_found'
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.2.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: 2022-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -162,11 +162,13 @@ 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
169
170
  - lib/regio/geocode.rb
171
+ - lib/regio/reverse_geocode.rb
170
172
  - lib/regio/version.rb
171
173
  - regio.gemspec
172
174
  homepage: https://github.com/tab/regio