wolf_core 1.1.28 → 1.1.29
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/wolf_core/infrastructure/geo_location_data_source.rb +57 -0
- data/lib/wolf_core/version.rb +1 -1
- metadata +16 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 88268f4f9a3b3ba94896745e3f19ff7c0d4efd6181b76df3a0e4abfa274ec553
|
|
4
|
+
data.tar.gz: 0abf44fc4a560d04120bcdaee48565fa415ecc3045cd6b650fc4dc1c21587d83
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3f74d13d8600fde7c88cc4f63f236c4458d3fac2d96a5c50571ac81a755f54b332cb4e68c0a81f979d1d4faf9bf5b5555e95c9dc4e21d95ba39c7ac4b58c0feb
|
|
7
|
+
data.tar.gz: 3f1a16a199da3c74271a0ffe277e6475a007ef67a15007fbfb75d7395dd843482ee3ea6f9ed1fe15cb7ce1be217dff9e7f3bf71a656bffb8986c31d0c3ca0564
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "geocoder"
|
|
4
|
+
require_relative "../utils/logging_utils"
|
|
5
|
+
|
|
6
|
+
module WolfCore
|
|
7
|
+
class GeoLocationDataSource
|
|
8
|
+
include WolfCore::LoggingUtils
|
|
9
|
+
|
|
10
|
+
def initialize
|
|
11
|
+
api_key = ENV["GOOGLE_MAPS_API_KEY"]
|
|
12
|
+
if api_key.nil? || api_key.empty?
|
|
13
|
+
raise ArgumentError, "GOOGLE_MAPS_API_KEY environment variable must be configured"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
Geocoder.configure(
|
|
17
|
+
lookup: :google,
|
|
18
|
+
api_key: api_key
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def get_address_coordinates(address_string)
|
|
23
|
+
results = Geocoder.search(address_string)
|
|
24
|
+
return nil if results.empty?
|
|
25
|
+
|
|
26
|
+
result = results.first
|
|
27
|
+
{ latitude: result.latitude, longitude: result.longitude }
|
|
28
|
+
rescue StandardError => e
|
|
29
|
+
log_geocoding_error(address_string, e)
|
|
30
|
+
nil
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def calculate_distance(coord1, coord2)
|
|
34
|
+
lat1, lon1 = coord1[:latitude], coord1[:longitude]
|
|
35
|
+
lat2, lon2 = coord2[:latitude], coord2[:longitude]
|
|
36
|
+
|
|
37
|
+
earth_radius_meters = 6_371_000
|
|
38
|
+
|
|
39
|
+
lat1_rad = lat1 * Math::PI / 180
|
|
40
|
+
lat2_rad = lat2 * Math::PI / 180
|
|
41
|
+
delta_lat = (lat2 - lat1) * Math::PI / 180
|
|
42
|
+
delta_lon = (lon2 - lon1) * Math::PI / 180
|
|
43
|
+
|
|
44
|
+
a = Math.sin(delta_lat / 2)**2 +
|
|
45
|
+
Math.cos(lat1_rad) * Math.cos(lat2_rad) * Math.sin(delta_lon / 2)**2
|
|
46
|
+
c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
|
|
47
|
+
|
|
48
|
+
earth_radius_meters * c
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
def log_geocoding_error(address_string, error)
|
|
54
|
+
log_object("Geocoding error for address: #{address_string}", error: error.message)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
data/lib/wolf_core/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: wolf_core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
4
|
+
version: 1.1.29
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Javier Roncallo
|
|
@@ -121,6 +121,20 @@ dependencies:
|
|
|
121
121
|
- - ">="
|
|
122
122
|
- !ruby/object:Gem::Version
|
|
123
123
|
version: '0'
|
|
124
|
+
- !ruby/object:Gem::Dependency
|
|
125
|
+
name: geocoder
|
|
126
|
+
requirement: !ruby/object:Gem::Requirement
|
|
127
|
+
requirements:
|
|
128
|
+
- - ">="
|
|
129
|
+
- !ruby/object:Gem::Version
|
|
130
|
+
version: '0'
|
|
131
|
+
type: :runtime
|
|
132
|
+
prerelease: false
|
|
133
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
134
|
+
requirements:
|
|
135
|
+
- - ">="
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: '0'
|
|
124
138
|
description: Repository to store shared code among Ruby projects.
|
|
125
139
|
email:
|
|
126
140
|
- jroncallo96@gmail.com
|
|
@@ -153,6 +167,7 @@ files:
|
|
|
153
167
|
- lib/wolf_core/infrastructure/application_repository.rb
|
|
154
168
|
- lib/wolf_core/infrastructure/application_serializer.rb
|
|
155
169
|
- lib/wolf_core/infrastructure/fkm_operations.rb
|
|
170
|
+
- lib/wolf_core/infrastructure/geo_location_data_source.rb
|
|
156
171
|
- lib/wolf_core/infrastructure/http_data_source.rb
|
|
157
172
|
- lib/wolf_core/infrastructure/http_operations.rb
|
|
158
173
|
- lib/wolf_core/infrastructure/in_memory_storage_data_source.rb
|