Class: Onetime::Resources::Receipts

Inherits:
Object
  • Object
show all
Defined in:
lib/onetime/resources/receipts.rb

Overview

Receipt operations (creator-facing secret metadata): show, recent, burn, update.

"Receipt" is the modern vocabulary; the v1 API also accepts the legacy /private and /metadata aliases, but this client uses the canonical /receipt paths that both versions support.

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Receipts

Returns a new instance of Receipts.



12
13
14
# File 'lib/onetime/resources/receipts.rb', line 12

def initialize(client)
  @client = client
end

Instance Method Details

#burn(key, passphrase: nil, continue: true, guest: false) ⇒ Object

Burn (destroy) an unread secret by its receipt key.



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/onetime/resources/receipts.rb', line 34

def burn(key, passphrase: nil, continue: true, guest: false)
  identifier = key.to_s
  case version
  when :v1
    form = compact(passphrase: passphrase, continue: continue)
    @client.request(:post, "/receipt/#{identifier}/burn", form: form)
  when :v2
    path = guest ? "/guest/receipt/#{identifier}/burn" : "/receipt/#{identifier}/burn"
    @client.request(:post, path, body: compact(passphrase: passphrase, continue: continue))
  end
end

#recentObject

List the authenticated customer's recent receipts.



29
30
31
# File 'lib/onetime/resources/receipts.rb', line 29

def recent
  @client.request(:get, "/receipt/recent")
end

#show(key, guest: false) ⇒ Object

Show a receipt by its key.



17
18
19
20
21
22
23
24
25
26
# File 'lib/onetime/resources/receipts.rb', line 17

def show(key, guest: false)
  identifier = key.to_s
  case version
  when :v1
    @client.request(:get, "/receipt/#{identifier}")
  when :v2
    path = guest ? "/guest/receipt/#{identifier}" : "/receipt/#{identifier}"
    @client.request(:get, path)
  end
end

#update(key, memo:) ⇒ Object

Update a receipt's memo. (v2 only)



47
48
49
50
# File 'lib/onetime/resources/receipts.rb', line 47

def update(key, memo:)
  require_version!(:v2, "receipts.update")
  @client.request(:patch, "/receipt/#{key}", body: { memo: memo })
end