kiriminaja 1.0.3 → 1.0.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: 310f2dc37e8e014ca682e32a2bbbbd96073675dcaa78ca1126818932bec782b6
4
- data.tar.gz: 81087fafb216e7e6df106c989936cec02cdf6f8c740e6219c1c30c27957f14ee
3
+ metadata.gz: b5ce875592b502dd58ab9365d005f1186de68b3157c7e32c60b4b0b4943e7408
4
+ data.tar.gz: 18938db8939f403812baf9b3e90c7291c16fb0b1e21e953961aaa86e96a086bd
5
5
  SHA512:
6
- metadata.gz: 6ec28f0546d8bb24c207d365d3bbc2e2925258c7f0d9dcc9c687144f47f6d219911b1812fbe2aeb71fbdac47e7a1b5d93a64b12515c0d2ffbfa815c80603ed4b
7
- data.tar.gz: 106cab76b95896ba2e2c16e4ee855f2b281812157de98b1d3c7df7c118ce13b0cb6534991639de8cecfb2fea59a765821011a8da8905ba8b5900de1783b94d10
6
+ metadata.gz: 9b4ce2ac22137dc25a619d58bedbafce6f76f34fddf2301d4d3d0910af44dd2ec5797382098549d5807b55818886e0ffb9cbd9a51117e54320136cfb2d17c9f9
7
+ data.tar.gz: c34ab254fb98eab2178bb60c2751ed01dd23f805efe2fd50c358ecc933863edf029f48caa7f6f256524653900a4279f76cbeb5eb14b7be990db54e12218bedcf
@@ -16,10 +16,11 @@ require_relative "services/order/order"
16
16
  require_relative "services/payment/payment"
17
17
  require_relative "services/pickup/pickup"
18
18
  require_relative "services/profile/profile"
19
+ require_relative "services/preference/preference"
19
20
 
20
21
  module KiriminAja
21
22
  class Client
22
- attr_reader :address, :awb, :calculations, :coverage_area, :courier, :credit, :order, :payment, :pickup, :profile
23
+ attr_reader :address, :awb, :calculations, :coverage_area, :courier, :credit, :order, :payment, :pickup, :profile, :preference
23
24
 
24
25
  def initialize(env: Config::ENV_SANDBOX, api_key: nil, base_url: nil, http_client: nil)
25
26
  config = Config::ClientConfig.new(
@@ -40,6 +41,7 @@ module KiriminAja
40
41
  @payment = Services::PaymentService.new(http)
41
42
  @pickup = Services::PickupService.new(http)
42
43
  @profile = Services::ProfileService.new(http)
44
+ @preference = Services::PreferenceService.new(http)
43
45
  end
44
46
  end
45
47
  end
@@ -6,6 +6,17 @@ require "json"
6
6
 
7
7
  module KiriminAja
8
8
  module Http
9
+ # Preserve RuntimeError compatibility while exposing diagnostic response data.
10
+ class Error < RuntimeError
11
+ attr_reader :status, :body
12
+
13
+ def initialize(response)
14
+ @status = response.code.to_i
15
+ @body = response.body
16
+ super("Request failed: #{response.code} #{response.message}")
17
+ end
18
+ end
19
+
9
20
  class Request
10
21
  def initialize(config)
11
22
  @config = config
@@ -20,25 +31,31 @@ module KiriminAja
20
31
 
21
32
  response = http.request(req)
22
33
 
23
- unless response.is_a?(Net::HTTPSuccess)
24
- raise "Request failed: #{response.code} #{response.message}"
34
+ unless (200..299).cover?(response.code.to_i)
35
+ raise Error.new(response)
25
36
  end
26
37
 
27
38
  JSON.parse(response.body)
28
39
  end
29
40
 
30
- def post_json(path, body = nil)
41
+ def post_json(path, body = nil, **kwargs)
42
+ body = kwargs unless kwargs.empty?
31
43
  request_json(path, method: "POST", body: body)
32
44
  end
33
45
 
34
- def get_json(path)
35
- request_json(path, method: "GET")
46
+ def get_json(path, query: nil)
47
+ request_json(path, method: "GET", query: query)
36
48
  end
37
49
 
38
50
  def delete_json(path)
39
51
  request_json(path, method: "DELETE")
40
52
  end
41
53
 
54
+ def put_json(path, body = nil, **kwargs)
55
+ body = kwargs unless kwargs.empty?
56
+ request_json(path, method: "PUT", body: body)
57
+ end
58
+
42
59
  private
43
60
 
44
61
  def build_url(path, query)
@@ -47,7 +64,7 @@ module KiriminAja
47
64
  url = "#{base}#{normalized_path}"
48
65
  if query && !query.empty?
49
66
  params = URI.encode_www_form(query)
50
- url += "?#{params}"
67
+ url += "#{url.include?("?") ? "&" : "?"}#{params}"
51
68
  end
52
69
  url
53
70
  end
@@ -63,14 +80,15 @@ module KiriminAja
63
80
  when "GET" then Net::HTTP::Get
64
81
  when "POST" then Net::HTTP::Post
65
82
  when "DELETE" then Net::HTTP::Delete
83
+ when "PUT" then Net::HTTP::Put
66
84
  else raise ArgumentError, "Unsupported HTTP method: #{method}"
67
85
  end
68
86
 
69
87
  req = klass.new(uri)
70
88
  req["Accept"] = "application/json"
89
+ req["Content-Type"] = "application/json"
71
90
 
72
91
  if body && !%w[GET DELETE].include?(method.upcase)
73
- req["Content-Type"] = "application/json"
74
92
  req.body = JSON.generate(body)
75
93
  end
76
94
 
@@ -7,6 +7,12 @@ module KiriminAja
7
7
  @http.post_json("/api/mitra/v6.1/shipping_price", payload.to_h)
8
8
  end
9
9
 
10
+ # Full express pricing uses the same API endpoint, but is kept as a
11
+ # named operation to match the PHP SDK's public surface.
12
+ def full_shipping_price(payload)
13
+ pricing_express(payload)
14
+ end
15
+
10
16
  def pricing_instant(payload)
11
17
  @http.post_json("/api/mitra/v4/instant/pricing", payload.to_h)
12
18
  end
@@ -10,6 +10,43 @@ module KiriminAja
10
10
  def balance
11
11
  @http.get_json("/api/mitra/v6.2/credit/balance")
12
12
  end
13
+
14
+ # Extract the numeric balance from all response envelope variants seen
15
+ # by the API. `balance` remains raw for backward compatibility.
16
+ def amount
17
+ response = balance
18
+ unless response.is_a?(Hash)
19
+ raise "Credit balance is missing from the API response"
20
+ end
21
+ if response["status"] == false
22
+ raise(response["text"] || response["message"] || "Failed to fetch credit balance")
23
+ end
24
+
25
+ %w[results result data payload].each do |key|
26
+ value = response[key]
27
+ next unless value.is_a?(Hash)
28
+
29
+ amount = numeric(value["balance"])
30
+ return amount unless amount.nil?
31
+ end
32
+ amount = numeric(response["balance"])
33
+ return amount unless amount.nil?
34
+
35
+ raise "Credit balance is missing from the API response"
36
+ end
37
+
38
+ private
39
+
40
+ def numeric(value)
41
+ return value if value.is_a?(Numeric)
42
+ if value.is_a?(String) && value.strip.match?(/\A[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?\z/)
43
+ return value.strip.to_i if value.strip.match?(/\A[+-]?\d+\z/)
44
+
45
+ return value.to_f
46
+ end
47
+
48
+ nil
49
+ end
13
50
  end
14
51
  end
15
52
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KiriminAja
4
+ module Services
5
+ # Account-level preferences exposed by the PHP SDK's PreferenceRepository.
6
+ class PreferenceService
7
+ def initialize(http)
8
+ @http = http
9
+ end
10
+
11
+ def set_whitelist_services(services)
12
+ @http.post_json("/api/mitra/v3/set_whitelist_services", { services: services })
13
+ end
14
+
15
+ alias set_whitelist_expedition set_whitelist_services
16
+
17
+ # Register the URL to which shipment callbacks are sent.
18
+ def set_callback(url)
19
+ @http.post_json("/api/mitra/set_callback", { url: url })
20
+ end
21
+ end
22
+ end
23
+ end
@@ -10,6 +10,25 @@ module KiriminAja
10
10
  def get
11
11
  @http.get_json("/api/mitra/v6.2/profile")
12
12
  end
13
+
14
+ # Return the profile object regardless of whether the API wraps it in
15
+ # results, result, or data. `get` remains raw for backward compatibility.
16
+ def normalized
17
+ response = get
18
+ unless response.is_a?(Hash)
19
+ raise "Profile data is missing from the API response"
20
+ end
21
+ if response["status"] == false
22
+ raise(response["text"] || response["message"] || "Failed to fetch profile")
23
+ end
24
+
25
+ %w[results result data].each do |key|
26
+ return response[key] if response[key].is_a?(Hash)
27
+ end
28
+ return response if %w[id name email metadata].any? { |key| response.key?(key) }
29
+
30
+ raise "Profile data is missing from the API response"
31
+ end
13
32
  end
14
33
  end
15
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kiriminaja
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - KiriminAja Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-06-05 00:00:00.000000000 Z
11
+ date: 2026-10-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby SDK for the KiriminAja logistics API. Supports address lookup, coverage
14
14
  area pricing, order management (express & instant), courier services, pickup scheduling,
@@ -36,6 +36,7 @@ files:
36
36
  - lib/kiriminaja/services/order/order.rb
37
37
  - lib/kiriminaja/services/payment/payment.rb
38
38
  - lib/kiriminaja/services/pickup/pickup.rb
39
+ - lib/kiriminaja/services/preference/preference.rb
39
40
  - lib/kiriminaja/services/profile/profile.rb
40
41
  - lib/kiriminaja/types/address.rb
41
42
  - lib/kiriminaja/types/enums.rb