Class: Robomart::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/robomart.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key, base_url: DEFAULT_BASE_URL, api_version: DEFAULT_API_VERSION) ⇒ Client

Returns a new instance of Client.



32
33
34
35
36
# File 'lib/robomart.rb', line 32

def initialize(api_key, base_url: DEFAULT_BASE_URL, api_version: DEFAULT_API_VERSION)
  @api_key = api_key
  @base_url = base_url.sub(%r{/\z}, "")
  @api_version = api_version
end

Instance Method Details

#balanceObject

Wallet reads. Cents throughout.



75
76
77
# File 'lib/robomart.rb', line 75

def balance
  get("/v1/balance")
end

#book(input, idempotency_key:) ⇒ Object

One-step booking at the posted price. The idempotency key makes a retried call replay the original booking instead of double booking.



45
46
47
# File 'lib/robomart.rb', line 45

def book(input, idempotency_key:)
  post("/v1/deliveries", input, { "Idempotency-Key" => idempotency_key }).fetch("data")
end

#cancel(id) ⇒ Object

Cancel before pickup releases the full posted price. After pickup the trip stays charged and the call is refused.



60
61
62
# File 'lib/robomart.rb', line 60

def cancel(id)
  post("/v1/deliveries/#{id}/cancel").fetch("data")
end

#coverage(input) ⇒ Object

Read-only route preview: eligibility, mode, and the posted fee.



39
40
41
# File 'lib/robomart.rb', line 39

def coverage(input)
  post("/v1/coverage", input)
end

#deliveries(limit: nil) ⇒ Object



53
54
55
56
# File 'lib/robomart.rb', line 53

def deliveries(limit: nil)
  qs = limit ? "?limit=#{limit}" : ""
  get("/v1/deliveries#{qs}").fetch("data")
end

#delivery(id) ⇒ Object



49
50
51
# File 'lib/robomart.rb', line 49

def delivery(id)
  get("/v1/deliveries/#{id}").fetch("data")
end

#ledger(limit: nil) ⇒ Object



79
80
81
82
# File 'lib/robomart.rb', line 79

def ledger(limit: nil)
  qs = limit ? "?limit=#{limit}" : ""
  get("/v1/ledger#{qs}").fetch("data")
end

#proof(id) ⇒ Object

Proof of delivery, available once the delivery is delivered.



65
66
67
# File 'lib/robomart.rb', line 65

def proof(id)
  get("/v1/deliveries/#{id}/proof").fetch("data")
end

#simulate(id, action) ⇒ Object

Sandbox lifecycle driver. Test keys only.



70
71
72
# File 'lib/robomart.rb', line 70

def simulate(id, action)
  post("/v1/deliveries/#{id}/simulate", { action: action }).fetch("data")
end


88
89
90
# File 'lib/robomart.rb', line 88

def topup_link
  post("/v1/topups/link")
end

#topup_preview(amount_credited_cents) ⇒ Object



84
85
86
# File 'lib/robomart.rb', line 84

def topup_preview(amount_credited_cents)
  get("/v1/topups/preview?amount_credited=#{amount_credited_cents}")
end