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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 73898a54030f68363373cb9957a2135f7b195759cf89dde835f40fab9131f22e
4
- data.tar.gz: a28570193121f60c5207b58a7091b9a4165e5aa308bf821c3c1e992c901dae80
3
+ metadata.gz: 8d2ee830f85ef9f5228849abb55453b48936fc798b6bb0eb0788669702ad3cd5
4
+ data.tar.gz: a61db4e5869f1905fe5afbc8644e1be3308be94bd9c613357c1a2d2abb7c60fa
5
5
  SHA512:
6
- metadata.gz: b22dc1e6c55787e670d0ac1203accbf04508aa8c9ec7c3efe857e9da5bb775eaaa737b2385f499b320fcac9c019f9b9ec2dfff14775a5776696c497198dd5a4a
7
- data.tar.gz: a7314deb5134b4e41a53b7ee33c1324cb7ff1fb646a51ba990cecc5d06ae1b58cce7ef38b292e76be6d246a6b1e5456f97b40f1ada9b55ae589f0451d760e20b
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
- %i[latitude longitude] if latitude.present? && longitude.present?
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
- require "httparty"
1
+ require "httparty"
2
2
 
3
- module Bscf
4
- module Core
5
- class GebetaMapsService
6
- include HTTParty
7
- base_uri "https://mapapi.gebeta.app/api/"
3
+ module Bscf
4
+ module Core
5
+ class GebetaMapsService
6
+ include HTTParty
7
+ base_uri "https://mapapi.gebeta.app/api"
8
8
 
9
- def initialize
10
- @api_key = ENV["GEBETA_API_KEY"] || Rails.application.credentials.gebeta_api_key
11
- end
9
+ def initialize
10
+ @api_key = Rails.application.credentials.gebeta_api_key || ENV["GEBETA_API_KEY"]
11
+ end
12
12
 
13
- # One-to-Many (ONM) API for route optimization
14
- def optimize_route(origin_address, destination_addresses)
15
- return {} if destination_addresses.empty?
16
-
17
- # Extract coordinates
18
- origin = origin_address.coordinates
19
- destinations = destination_addresses.map(&:coordinates).compact
20
-
21
- return {} if origin.nil? || destinations.empty?
22
-
23
- # Prepare destinations in the format expected by Gebeta Maps
24
- destinations_json = destinations.map.with_index do |coords, index|
25
- {
26
- id: index,
27
- point: {
28
- lat: coords[0],
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
- private
30
+ private
48
31
 
49
- def handle_response(response)
50
- if response.success?
51
- JSON.parse(response.body)
52
- else
53
- Rails.logger.error("Gebeta Maps API error: #{response.code} - #{response.body}")
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
@@ -1,5 +1,5 @@
1
1
  module Bscf
2
2
  module Core
3
- VERSION = "0.4.3"
3
+ VERSION = "0.4.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bscf-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Asrat