Method: Urg::OneTimeSecret#share_secret

Defined in:
lib/one_time_secret.rb

#share_secret(secret, passphrase: nil, ttl: nil, notify_email: nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/one_time_secret.rb', line 5

def share_secret(secret, passphrase:nil, ttl: nil, notify_email: nil)
  secret_params = {
    secret: secret,
    passphrase: passphrase,
    ttl: ttl.presence || default_secret_ttl,
    recipient: notify_email
  }

  conn = Faraday.new(
    url: api_url("/share"),
    params: secret_params,
    headers: api_headers
  )

  resp = conn.post

  unless resp.success?
    raise "OneTimeSecret share_secret request failed with status #{resp.status}, and body `#{resp.body}`"
  end

  JSON.parse(resp.body)
end