kiriminaja 1.0.0 → 1.0.1

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: 362409453e97df85b8dfc075814cb73ea173f96fd3bf8b4468725b3c85bdb463
4
- data.tar.gz: aa4ba1fb9a38da45aef06fc0e498552995382efd0378904c86b5f45ec46b519d
3
+ metadata.gz: 7f91b65e2318ef923ad6c94d68f3ee123169f394fc81d8afc5e72c6701d6f9d6
4
+ data.tar.gz: 334b5eec514bd8dcd42a70c046ee3c3e6d3d53a3dd05b5978c30588c941380a5
5
5
  SHA512:
6
- metadata.gz: d5f7cffea7c8d839dcc9bf2ae3d4edb0ce083b407b9452b63b8546a182e7baa0f6f65b147d16a7506383b32a621764106f55b24dc948026292168da19feedef5
7
- data.tar.gz: c97f455972851b158347fa1ff67e4df4647621666807019010940e403920929674f896067dea5262deae4305020597c277a42ac21bee6760d53081acb63493e0
6
+ metadata.gz: 8fc25cc5e4802430c88fe387e5ed69090dfe9394d5183abb14c5f3f30b53fc9284f81a541fadbde682bc93a2e5a3f4980ae5afc38427abad72bec0978ad8ad8c
7
+ data.tar.gz: ca3bd22133d9bcea3fdc332e129408e6af08fc11d72f3f5b4854f4fccaedfb0b45648e8dd4d49d9760aed0d2d11f1f88061a59ab4183a43b00a8ce09d9bf0207
data/README.md CHANGED
@@ -168,6 +168,23 @@ client.order.express.request_pickup(
168
168
  cod: 0,
169
169
  package_type_id: 7,
170
170
  item_name: "TEST Item name",
171
+ # `items` is optional. When provided, it lists the individual
172
+ # items inside the package. `item_value` is still required.
173
+ items: [
174
+ KiriminAja::Types::RequestPickupItem.new(
175
+ name: "Kaos Polos",
176
+ price: 125000,
177
+ qty: 2,
178
+ weight: 260,
179
+ width: 4,
180
+ length: 4,
181
+ height: 4,
182
+ metadata: KiriminAja::Types::RequestPickupItemMetadata.new(
183
+ sku: "KP-001",
184
+ variant_label: "Merah / L",
185
+ ),
186
+ ),
187
+ ],
171
188
  ),
172
189
  ],
173
190
  )
@@ -242,6 +259,31 @@ client.courier.set_whitelist_services(["jne_reg", "jne_yes"])
242
259
 
243
260
  ---
244
261
 
262
+ ### Credit
263
+
264
+ ```ruby
265
+ # Get the current KiriminAja credit balance
266
+ client.credit.balance
267
+ ```
268
+
269
+ ---
270
+
271
+ ### Utilities — Volumetric
272
+
273
+ Estimate the smallest bounding box (length / width / height) for a
274
+ multi-item package by trying three stacking strategies and returning the
275
+ arrangement with the smallest volume.
276
+
277
+ ```ruby
278
+ dim = KiriminAja::Utils::Volumetric.calculate([
279
+ { qty: 2, length: 10, width: 10, height: 2 },
280
+ { qty: 1, length: 5, width: 5, height: 5 }
281
+ ])
282
+ # dim[:length], dim[:width], dim[:height]
283
+ ```
284
+
285
+ ---
286
+
245
287
  ### Pickup Schedules
246
288
 
247
289
  ```ruby
@@ -9,13 +9,14 @@ require_relative "types/order"
9
9
  require_relative "services/address/address"
10
10
  require_relative "services/coverage_area/coverage_area"
11
11
  require_relative "services/courier/courier"
12
+ require_relative "services/credit/credit"
12
13
  require_relative "services/order/order"
13
14
  require_relative "services/payment/payment"
14
15
  require_relative "services/pickup/pickup"
15
16
 
16
17
  module KiriminAja
17
18
  class Client
18
- attr_reader :address, :coverage_area, :courier, :order, :payment, :pickup
19
+ attr_reader :address, :coverage_area, :courier, :credit, :order, :payment, :pickup
19
20
 
20
21
  def initialize(env: Config::ENV_SANDBOX, api_key: nil, base_url: nil, http_client: nil)
21
22
  config = Config::ClientConfig.new(
@@ -29,6 +30,7 @@ module KiriminAja
29
30
  @address = Services::AddressService.new(http)
30
31
  @coverage_area = Services::CoverageAreaService.new(http)
31
32
  @courier = Services::CourierService.new(http)
33
+ @credit = Services::CreditService.new(http)
32
34
  @order = Services::OrderService.new(http)
33
35
  @payment = Services::PaymentService.new(http)
34
36
  @pickup = Services::PickupService.new(http)
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KiriminAja
4
+ module Services
5
+ class CreditService
6
+ def initialize(http)
7
+ @http = http
8
+ end
9
+
10
+ def balance
11
+ @http.get_json("/api/mitra/v6.2/credit/balance")
12
+ end
13
+ end
14
+ end
15
+ end
@@ -2,20 +2,66 @@
2
2
 
3
3
  module KiriminAja
4
4
  module Types
5
+ class RequestPickupItemMetadata
6
+ attr_accessor :sku, :variant_label
7
+
8
+ def initialize(sku: nil, variant_label: nil)
9
+ @sku = sku
10
+ @variant_label = variant_label
11
+ end
12
+
13
+ def to_h
14
+ d = {}
15
+ d[:sku] = @sku unless @sku.nil?
16
+ d[:variant_label] = @variant_label unless @variant_label.nil?
17
+ d
18
+ end
19
+ end
20
+
21
+ class RequestPickupItem
22
+ attr_accessor :name, :price, :qty, :weight, :width, :length, :height, :metadata
23
+
24
+ def initialize(name:, price:, qty:, weight:,
25
+ width: nil, length: nil, height: nil, metadata: nil)
26
+ @name = name
27
+ @price = price
28
+ @qty = qty
29
+ @weight = weight
30
+ @width = width
31
+ @length = length
32
+ @height = height
33
+ @metadata = metadata
34
+ end
35
+
36
+ def to_h
37
+ d = {
38
+ name: @name,
39
+ price: @price,
40
+ qty: @qty,
41
+ weight: @weight,
42
+ }
43
+ d[:width] = @width unless @width.nil?
44
+ d[:length] = @length unless @length.nil?
45
+ d[:height] = @height unless @height.nil?
46
+ d[:metadata] = @metadata.to_h unless @metadata.nil?
47
+ d
48
+ end
49
+ end
50
+
5
51
  class RequestPickupPackage
6
52
  attr_accessor :order_id, :destination_name, :destination_phone, :destination_address,
7
53
  :destination_kecamatan_id, :weight, :width, :length, :height,
8
54
  :item_value, :shipping_cost, :service, :service_type, :cod,
9
55
  :package_type_id, :item_name,
10
56
  :destination_kelurahan_id, :destination_zipcode, :qty,
11
- :insurance_amount, :drop, :note
57
+ :insurance_amount, :drop, :note, :items
12
58
 
13
59
  def initialize(order_id:, destination_name:, destination_phone:, destination_address:,
14
60
  destination_kecamatan_id:, weight:, width:, length:, height:,
15
61
  item_value:, shipping_cost:, service:, service_type:, cod:,
16
62
  package_type_id:, item_name:,
17
63
  destination_kelurahan_id: nil, destination_zipcode: nil, qty: nil,
18
- insurance_amount: nil, drop: nil, note: nil)
64
+ insurance_amount: nil, drop: nil, note: nil, items: nil)
19
65
  @order_id = order_id
20
66
  @destination_name = destination_name
21
67
  @destination_phone = destination_phone
@@ -38,6 +84,7 @@ module KiriminAja
38
84
  @insurance_amount = insurance_amount
39
85
  @drop = drop
40
86
  @note = note
87
+ @items = items
41
88
  end
42
89
 
43
90
  def to_h
@@ -65,6 +112,7 @@ module KiriminAja
65
112
  d[:insurance_amount] = @insurance_amount unless @insurance_amount.nil?
66
113
  d[:drop] = @drop unless @drop.nil?
67
114
  d[:note] = @note unless @note.nil?
115
+ d[:items] = @items.map(&:to_h) unless @items.nil?
68
116
  d
69
117
  end
70
118
  end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KiriminAja
4
+ module Utils
5
+ module Volumetric
6
+ module_function
7
+
8
+ # Returns { length:, width:, height: } as the smallest bounding box
9
+ # across vertical / horizontal / side-by-side stacking strategies.
10
+ #
11
+ # Each item is a Hash with keys: :qty, :length, :width, :height
12
+ # (string keys are also accepted). Missing values default to 0; qty < 1
13
+ # is treated as 1.
14
+ def calculate(items)
15
+ return { length: 0, width: 0, height: 0 } if items.nil? || items.empty?
16
+
17
+ l_vert = w_vert = h_vert = 0
18
+ l_hor = w_hor = h_hor = 0
19
+ l_side = w_side = h_side = 0
20
+
21
+ items.each do |it|
22
+ qty = (fetch(it, :qty) || 1).to_i
23
+ qty = 1 if qty < 1
24
+ l = fetch(it, :length) || 0
25
+ w = fetch(it, :width) || 0
26
+ h = fetch(it, :height) || 0
27
+
28
+ h_vert += h * qty
29
+ l_vert = l if l > l_vert
30
+ w_vert = w if w > w_vert
31
+
32
+ l_hor += l * qty
33
+ h_hor = h if h > h_hor
34
+ w_hor = w if w > w_hor
35
+
36
+ w_side += w * qty
37
+ h_side = h if h > h_side
38
+ l_side = l if l > l_side
39
+ end
40
+
41
+ vol_vert = l_vert * w_vert * h_vert
42
+ vol_hor = l_hor * w_hor * h_hor
43
+ vol_side = l_side * w_side * h_side
44
+
45
+ if vol_vert <= vol_hor && vol_vert <= vol_side
46
+ { length: l_vert, width: w_vert, height: h_vert }
47
+ elsif vol_hor <= vol_side
48
+ { length: l_hor, width: w_hor, height: h_hor }
49
+ else
50
+ { length: l_side, width: w_side, height: h_side }
51
+ end
52
+ end
53
+
54
+ def fetch(item, key)
55
+ item[key] || item[key.to_s]
56
+ end
57
+ private_class_method :fetch
58
+ end
59
+ end
60
+ end
data/lib/kiriminaja.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "kiriminaja/client"
4
+ require_relative "kiriminaja/utils/volumetric"
4
5
 
5
6
  module KiriminAja
6
7
  VERSION = begin
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.0
4
+ version: 1.0.1
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-04-14 00:00:00.000000000 Z
11
+ date: 2026-04-23 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,
@@ -30,12 +30,14 @@ files:
30
30
  - lib/kiriminaja/services/address/address.rb
31
31
  - lib/kiriminaja/services/courier/courier.rb
32
32
  - lib/kiriminaja/services/coverage_area/coverage_area.rb
33
+ - lib/kiriminaja/services/credit/credit.rb
33
34
  - lib/kiriminaja/services/order/order.rb
34
35
  - lib/kiriminaja/services/payment/payment.rb
35
36
  - lib/kiriminaja/services/pickup/pickup.rb
36
37
  - lib/kiriminaja/types/address.rb
37
38
  - lib/kiriminaja/types/enums.rb
38
39
  - lib/kiriminaja/types/order.rb
40
+ - lib/kiriminaja/utils/volumetric.rb
39
41
  homepage: https://developer.kiriminaja.com
40
42
  licenses:
41
43
  - MIT