Class: Urg::OneTimeSecret
- Inherits:
-
Object
- Object
- Urg::OneTimeSecret
- Defined in:
- lib/one_time_secret.rb
Instance Method Summary collapse
- #fetch_secret(secret_key, passphrase: nil) ⇒ Object
- #share_secret(secret, passphrase: nil, ttl: nil, notify_email: nil) ⇒ Object
Instance Method Details
#fetch_secret(secret_key, passphrase: nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/one_time_secret.rb', line 28 def fetch_secret(secret_key, passphrase: nil) secret_params = { passphrase: passphrase } conn = Faraday.new( url: api_url("/secret/#{secret_key}"), params: secret_params, headers: api_headers ) resp = conn.post unless resp.success? raise "OneTimeSecret fetch_secret request failed with status #{resp.status}#{' (it\'s possible that the secret has already been consumed)' if resp.status == 404}, and body `#{resp.body}`" end JSON.parse(resp.body) end |
#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 |