Class: Onetime::Client
- Inherits:
-
Object
- Object
- Onetime::Client
- Defined in:
- lib/onetime/client.rb
Overview
The main entry point for the OnetimeSecret API client.
client = Onetime::Client.new(
base_url: "https://ca.onetimesecret.com",
customer: "ur1abc23def", # customer extid
api_token: ENV["ONETIME_API_TOKEN"],
api_version: :v2, # :v1 or :v2
)
client.secrets.conceal(secret: "hunter2", ttl: 3600)
client.receipts.recent
client.status
A client is safe to share across threads: it holds configuration and a stateless transport, and creates a fresh Net::HTTP connection per request.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#transport ⇒ Object
readonly
Returns the value of attribute transport.
Instance Method Summary collapse
- #api_version ⇒ Object
-
#authcheck ⇒ Object
Verify the configured credentials are valid.
-
#initialize(config: nil, **options) ⇒ Client
constructor
Accepts the same keyword arguments as Onetime::Configuration, or an already-built Configuration via
config:. -
#receipts ⇒ Object
Receipt resource accessor (show/recent/burn/update).
-
#request(method, path, query: nil, body: nil, form: nil, raise_on_error: true) ⇒ Onetime::Response
Issue a request against the configured API version.
-
#secrets ⇒ Object
Secret resource accessor (conceal/generate/reveal/show/status).
-
#status ⇒ Object
Service status.
-
#supported_locales ⇒ Object
Locales supported by the service.
-
#version ⇒ Object
Service version.
Constructor Details
#initialize(config: nil, **options) ⇒ Client
Accepts the same keyword arguments as Onetime::Configuration, or an
already-built Configuration via config:.
29 30 31 32 33 |
# File 'lib/onetime/client.rb', line 29 def initialize(config: nil, **) @config = config || Configuration.new(**) @config.validate! @transport = @config.transport || Transport.new(@config) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
25 26 27 |
# File 'lib/onetime/client.rb', line 25 def config @config end |
#transport ⇒ Object (readonly)
Returns the value of attribute transport.
25 26 27 |
# File 'lib/onetime/client.rb', line 25 def transport @transport end |
Instance Method Details
#api_version ⇒ Object
35 36 37 |
# File 'lib/onetime/client.rb', line 35 def api_version config.api_version end |
#authcheck ⇒ Object
Verify the configured credentials are valid. (v1 only)
69 70 71 72 |
# File 'lib/onetime/client.rb', line 69 def authcheck require_version!(:v1, "authcheck") request(:get, "/authcheck") end |
#receipts ⇒ Object
Receipt resource accessor (show/recent/burn/update).
45 46 47 |
# File 'lib/onetime/client.rb', line 45 def receipts @receipts ||= Resources::Receipts.new(self) end |
#request(method, path, query: nil, body: nil, form: nil, raise_on_error: true) ⇒ Onetime::Response
Issue a request against the configured API version. The path is relative to the version prefix (e.g. "/secret/conceal").
80 81 82 83 84 85 |
# File 'lib/onetime/client.rb', line 80 def request(method, path, query: nil, body: nil, form: nil, raise_on_error: true) transport.request( method, full_path(path), query: query, body: body, form: form, raise_on_error: raise_on_error ) end |
#secrets ⇒ Object
Secret resource accessor (conceal/generate/reveal/show/status).
40 41 42 |
# File 'lib/onetime/client.rb', line 40 def secrets @secrets ||= Resources::Secrets.new(self) end |
#status ⇒ Object
Service status. Available on both v1 and v2.
52 53 54 |
# File 'lib/onetime/client.rb', line 52 def status request(:get, "/status") end |
#supported_locales ⇒ Object
Locales supported by the service. (v2 only)
63 64 65 66 |
# File 'lib/onetime/client.rb', line 63 def supported_locales require_version!(:v2, "supported_locales") request(:get, "/supported-locales") end |
#version ⇒ Object
Service version. (v2 only)
57 58 59 60 |
# File 'lib/onetime/client.rb', line 57 def version require_version!(:v2, "version") request(:get, "/version") end |