Class: Apertur::Client
- Inherits:
-
Object
- Object
- Apertur::Client
- Defined in:
- lib/apertur/client.rb
Overview
Main client for the Apertur API.
Provides access to all API resources through lazily initialized accessors. Automatically detects the environment (live vs. sandbox) from the API key prefix and selects the appropriate base URL.
Constant Summary collapse
- DEFAULT_BASE_URL =
"https://api.aptr.ca"- SANDBOX_BASE_URL =
"https://sandbox.api.aptr.ca"
Instance Attribute Summary collapse
- #destinations ⇒ Apertur::Resources::Destinations readonly
- #encryption ⇒ Apertur::Resources::Encryption readonly
-
#env ⇒ String
readonly
The environment this client targets (“live” or “test”).
- #keys ⇒ Apertur::Resources::Keys readonly
- #polling ⇒ Apertur::Resources::Polling readonly
- #sessions ⇒ Apertur::Resources::Sessions readonly
- #stats ⇒ Apertur::Resources::Stats readonly
- #upload ⇒ Apertur::Resources::Upload readonly
- #uploads ⇒ Apertur::Resources::Uploads readonly
- #webhooks ⇒ Apertur::Resources::Webhooks readonly
Instance Method Summary collapse
-
#initialize(api_key: nil, oauth_token: nil, base_url: nil) ⇒ Client
constructor
Create a new Apertur API client.
Constructor Details
#initialize(api_key: nil, oauth_token: nil, base_url: nil) ⇒ Client
Create a new Apertur API client.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/apertur/client.rb', line 55 def initialize(api_key: nil, oauth_token: nil, base_url: nil) token = api_key || oauth_token raise ArgumentError, "Either api_key or oauth_token must be provided" if token.nil? || token.empty? @env = token.start_with?("aptr_test_") ? "test" : "live" resolved_url = base_url || (@env == "test" ? SANDBOX_BASE_URL : DEFAULT_BASE_URL) http = HttpClient.new(resolved_url, token) @sessions = Resources::Sessions.new(http) @upload = Resources::Upload.new(http) @uploads = Resources::Uploads.new(http) @polling = Resources::Polling.new(http) @destinations = Resources::Destinations.new(http) @keys = Resources::Keys.new(http) @webhooks = Resources::Webhooks.new(http) @encryption = Resources::Encryption.new(http) @stats = Resources::Stats.new(http) end |
Instance Attribute Details
#destinations ⇒ Apertur::Resources::Destinations (readonly)
34 35 36 |
# File 'lib/apertur/client.rb', line 34 def destinations @destinations end |
#encryption ⇒ Apertur::Resources::Encryption (readonly)
43 44 45 |
# File 'lib/apertur/client.rb', line 43 def encryption @encryption end |
#env ⇒ String (readonly)
Returns the environment this client targets (“live” or “test”).
19 20 21 |
# File 'lib/apertur/client.rb', line 19 def env @env end |
#keys ⇒ Apertur::Resources::Keys (readonly)
37 38 39 |
# File 'lib/apertur/client.rb', line 37 def keys @keys end |
#polling ⇒ Apertur::Resources::Polling (readonly)
31 32 33 |
# File 'lib/apertur/client.rb', line 31 def polling @polling end |
#sessions ⇒ Apertur::Resources::Sessions (readonly)
22 23 24 |
# File 'lib/apertur/client.rb', line 22 def sessions @sessions end |
#stats ⇒ Apertur::Resources::Stats (readonly)
46 47 48 |
# File 'lib/apertur/client.rb', line 46 def stats @stats end |
#upload ⇒ Apertur::Resources::Upload (readonly)
25 26 27 |
# File 'lib/apertur/client.rb', line 25 def upload @upload end |
#uploads ⇒ Apertur::Resources::Uploads (readonly)
28 29 30 |
# File 'lib/apertur/client.rb', line 28 def uploads @uploads end |
#webhooks ⇒ Apertur::Resources::Webhooks (readonly)
40 41 42 |
# File 'lib/apertur/client.rb', line 40 def webhooks @webhooks end |