opencage-geocoder 3.3.0 → 3.4.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 +4 -4
- data/lib/opencage/error.rb +2 -0
- data/lib/opencage/geocoder/location.rb +4 -2
- data/lib/opencage/geocoder/request.rb +17 -0
- data/lib/opencage/geocoder.rb +11 -4
- data/lib/opencage/version.rb +3 -1
- data/lib/opencage.rb +2 -0
- metadata +8 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f11d2a8240c73511334898f87d7b72387197388e7671ee8b79c8f73a548f1c3d
|
|
4
|
+
data.tar.gz: 77f7af9c4383c989cafe6b543bb58b5c55b068e1c761d514af5fa162e257f32d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d43fc84a8bb9beba2cc2b093e30916d18f6f130db7d46ac515c96c9dd8a9d4c4976a9eababb984501fde644916f23ef380f0075648b3ace946787e03984abb68
|
|
7
|
+
data.tar.gz: 3a0940493d1a0a2c3407749d01efe14340e1c9f88b09cf20dca1811d279d739a6085ed9c2a955a82a205194dcfe754ec3d32c338b255a21d3391bb01d8b23e50
|
data/lib/opencage/error.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module OpenCage
|
|
2
4
|
class Geocoder
|
|
3
5
|
class Location
|
|
@@ -18,13 +20,13 @@ module OpenCage
|
|
|
18
20
|
end
|
|
19
21
|
|
|
20
22
|
def lat
|
|
21
|
-
@result
|
|
23
|
+
@result.dig('geometry', 'lat')&.to_f
|
|
22
24
|
end
|
|
23
25
|
|
|
24
26
|
alias latitude lat
|
|
25
27
|
|
|
26
28
|
def lng
|
|
27
|
-
@result
|
|
29
|
+
@result.dig('geometry', 'lng')&.to_f
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
alias longitude lng
|
|
@@ -1,11 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module OpenCage
|
|
2
4
|
class Geocoder
|
|
3
5
|
class Request
|
|
6
|
+
LOCALHOST_HOSTS = %w[localhost 127.0.0.1 0.0.0.0 ::1 [::1]].freeze
|
|
7
|
+
|
|
4
8
|
def initialize(api_key, query, options = {})
|
|
5
9
|
@host = options.fetch(:host, 'api.opencagedata.com')
|
|
10
|
+
validate_host!(@host)
|
|
6
11
|
@params = options.merge(key: api_key, q: query)
|
|
7
12
|
end
|
|
8
13
|
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def validate_host!(host)
|
|
17
|
+
hostname = host.to_s.downcase.gsub(/(?<=\w):\d+\z/, '')
|
|
18
|
+
return if hostname.end_with?('.opencagedata.com')
|
|
19
|
+
return if LOCALHOST_HOSTS.include?(hostname)
|
|
20
|
+
|
|
21
|
+
raise ArgumentError, "Invalid host: #{host}. Must be a subdomain of opencagedata.com or localhost."
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
public
|
|
25
|
+
|
|
9
26
|
def url
|
|
10
27
|
uri = URI::HTTPS.build(host: @host, path: '/geocode/v1/json')
|
|
11
28
|
uri.query = URI.encode_www_form(@params)
|
data/lib/opencage/geocoder.rb
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'opencage/geocoder/location'
|
|
2
4
|
require 'opencage/geocoder/request'
|
|
3
5
|
require 'opencage/error'
|
|
4
6
|
require 'opencage/version'
|
|
5
7
|
require 'open-uri'
|
|
8
|
+
require 'net/http'
|
|
6
9
|
require 'json'
|
|
7
10
|
|
|
8
11
|
module OpenCage
|
|
@@ -20,12 +23,12 @@ module OpenCage
|
|
|
20
23
|
begin
|
|
21
24
|
results = fetch(request.to_s)
|
|
22
25
|
rescue Errno::ECONNREFUSED
|
|
23
|
-
raise_error("408 Failed to open TCP connection to API #{request}")
|
|
26
|
+
raise_error("408 Failed to open TCP connection to API #{redact_url(request)}")
|
|
24
27
|
rescue Errno::ECONNRESET
|
|
25
28
|
# Connection reset by peer - SSL_connect
|
|
26
|
-
raise_error("408 Failed to open SSL connection to API #{request}")
|
|
29
|
+
raise_error("408 Failed to open SSL connection to API #{redact_url(request)}")
|
|
27
30
|
rescue Net::OpenTimeout
|
|
28
|
-
raise_error("408 Timeout connecting to API #{request}")
|
|
31
|
+
raise_error("408 Timeout connecting to API #{redact_url(request)}")
|
|
29
32
|
end
|
|
30
33
|
|
|
31
34
|
return [] unless results
|
|
@@ -53,7 +56,7 @@ module OpenCage
|
|
|
53
56
|
def fetch(url)
|
|
54
57
|
JSON.parse(URI(url).open(headers).read)['results']
|
|
55
58
|
rescue OpenURI::HTTPError => e
|
|
56
|
-
raise_error(e)
|
|
59
|
+
raise_error(e.io.status.join(' '))
|
|
57
60
|
end
|
|
58
61
|
|
|
59
62
|
def headers
|
|
@@ -66,6 +69,10 @@ module OpenCage
|
|
|
66
69
|
raise klass.new(message: String(error), code: code.to_i)
|
|
67
70
|
end
|
|
68
71
|
|
|
72
|
+
def redact_url(request)
|
|
73
|
+
request.to_s.gsub(/key=([^&]{6})[^&]*/, 'key=\1...[REDACTED]')
|
|
74
|
+
end
|
|
75
|
+
|
|
69
76
|
def to_float(coord)
|
|
70
77
|
Float(coord)
|
|
71
78
|
rescue ArgumentError
|
data/lib/opencage/version.rb
CHANGED
data/lib/opencage.rb
CHANGED
metadata
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: opencage-geocoder
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Samuel Scully
|
|
8
8
|
- Marc Tobias
|
|
9
|
-
autorequire:
|
|
10
9
|
bindir: bin
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 2026-03-29 00:00:00.000000000 Z
|
|
13
12
|
dependencies: []
|
|
14
13
|
description: A client for the OpenCage geocoding API - https://opencagedata.com/
|
|
15
14
|
email: support@opencagedata.com
|
|
@@ -28,7 +27,10 @@ licenses:
|
|
|
28
27
|
- MIT
|
|
29
28
|
metadata:
|
|
30
29
|
source_code_uri: https://github.com/opencagedata/ruby-opencage-geocoder
|
|
31
|
-
|
|
30
|
+
changelog_uri: https://github.com/opencagedata/ruby-opencage-geocoder/blob/master/CHANGES.txt
|
|
31
|
+
bug_tracker_uri: https://github.com/opencagedata/ruby-opencage-geocoder/issues
|
|
32
|
+
homepage_uri: https://opencagedata.com/tutorials/geocode-in-ruby
|
|
33
|
+
rubygems_mfa_required: 'true'
|
|
32
34
|
rdoc_options: []
|
|
33
35
|
require_paths:
|
|
34
36
|
- lib
|
|
@@ -36,15 +38,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
36
38
|
requirements:
|
|
37
39
|
- - ">="
|
|
38
40
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: '3.
|
|
41
|
+
version: '3.2'
|
|
40
42
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
41
43
|
requirements:
|
|
42
44
|
- - ">="
|
|
43
45
|
- !ruby/object:Gem::Version
|
|
44
46
|
version: '0'
|
|
45
47
|
requirements: []
|
|
46
|
-
rubygems_version: 3.
|
|
47
|
-
signing_key:
|
|
48
|
+
rubygems_version: 3.6.2
|
|
48
49
|
specification_version: 4
|
|
49
50
|
summary: A client for the OpenCage geocoder API
|
|
50
51
|
test_files: []
|