bscf-core 0.4.3 → 0.4.4
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/app/models/bscf/core/address.rb +1 -1
- data/app/services/bscf/core/gebeta_maps_service.rb +33 -50
- data/lib/bscf/core/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d2ee830f85ef9f5228849abb55453b48936fc798b6bb0eb0788669702ad3cd5
|
4
|
+
data.tar.gz: a61db4e5869f1905fe5afbc8644e1be3308be94bd9c613357c1a2d2abb7c60fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6276a4c9e805e5042fbbcde086e19391b00033d5226d152b228ddd450a1ff72d5eeb305925d95032a534fc07face0029ef09f3295be453ad2500bd73cae54b8
|
7
|
+
data.tar.gz: c82a5c67f84012e027e43469df1bce6fa0e52b0f3298e1d0e44da2684c8a1e2f4c461fc9095ef5865631b47f84400c5b41857bb33f046565fa1ef4650c096c44
|
@@ -12,7 +12,7 @@ module Bscf
|
|
12
12
|
validates :latitude, :longitude, presence: true, if: :requires_coordinates?
|
13
13
|
|
14
14
|
def coordinates
|
15
|
-
|
15
|
+
[latitude.to_f, longitude.to_f] if latitude.present? && longitude.present?
|
16
16
|
end
|
17
17
|
|
18
18
|
def full_address
|
@@ -1,59 +1,42 @@
|
|
1
|
-
|
1
|
+
require "httparty"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module Bscf
|
4
|
+
module Core
|
5
|
+
class GebetaMapsService
|
6
|
+
include HTTParty
|
7
|
+
base_uri "https://mapapi.gebeta.app/api"
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
def initialize
|
10
|
+
@api_key = Rails.application.credentials.gebeta_api_key || ENV["GEBETA_API_KEY"]
|
11
|
+
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
lng: coords[1]
|
30
|
-
}
|
31
|
-
}
|
32
|
-
end.to_json
|
33
|
-
|
34
|
-
# Make API request
|
35
|
-
response = self.class.get(
|
36
|
-
"/route/onm",
|
37
|
-
query: {
|
38
|
-
origin: "#{origin[0]},#{origin[1]}",
|
39
|
-
json: destinations_json,
|
40
|
-
key: @api_key
|
41
|
-
}
|
42
|
-
)
|
43
|
-
|
44
|
-
handle_response(response)
|
45
|
-
end
|
13
|
+
def optimize_route(origin_address, destination_addresses)
|
14
|
+
return {} if destination_addresses.empty?
|
15
|
+
|
16
|
+
origin = origin_address.coordinates
|
17
|
+
destinations = destination_addresses.map(&:coordinates).compact
|
18
|
+
return {} if origin.nil? || destinations.empty?
|
19
|
+
|
20
|
+
origin_str = "{#{origin[0]},#{origin[1]}}"
|
21
|
+
destinations_str = destinations.map { |lat, lon| "{#{lat},#{lon}}" }.join(",")
|
22
|
+
json_param = "[#{destinations_str}]"
|
23
|
+
|
24
|
+
url = "https://mapapi.gebeta.app/api/route/onm?origin=#{origin_str}&json=#{json_param}&apiKey=#{@api_key}"
|
25
|
+
response = HTTParty.get(url)
|
26
|
+
|
27
|
+
handle_response(response)
|
28
|
+
end
|
46
29
|
|
47
|
-
|
30
|
+
private
|
48
31
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
32
|
+
def handle_response(response)
|
33
|
+
if response.success?
|
34
|
+
JSON.parse(response.body)
|
35
|
+
else
|
36
|
+
Rails.logger.error("Gebeta Maps API error: #{response.code} - #{response.body}")
|
37
|
+
{}
|
56
38
|
end
|
57
39
|
end
|
58
40
|
end
|
59
41
|
end
|
42
|
+
end
|
data/lib/bscf/core/version.rb
CHANGED