Class: Apertur::Client

Inherits:
Object
  • Object
show all
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.

Examples:

client = Apertur::Client.new(api_key: "aptr_test_abc123")
session = client.sessions.create(max_images: 5)
puts session["uuid"]

Constant Summary collapse

DEFAULT_BASE_URL =
"https://api.aptr.ca"
SANDBOX_BASE_URL =
"https://sandbox.api.aptr.ca"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, oauth_token: nil, base_url: nil) ⇒ Client

Create a new Apertur API client.

Parameters:

  • api_key (String, nil) (defaults to: nil)

    an API key (prefixed aptr_ or aptr_test_)

  • oauth_token (String, nil) (defaults to: nil)

    an OAuth bearer token (alternative to api_key)

  • base_url (String, nil) (defaults to: nil)

    override the base URL; auto-detected from the key prefix when nil

Raises:

  • (ArgumentError)

    if neither api_key nor oauth_token is provided



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

#destinationsApertur::Resources::Destinations (readonly)



34
35
36
# File 'lib/apertur/client.rb', line 34

def destinations
  @destinations
end

#encryptionApertur::Resources::Encryption (readonly)



43
44
45
# File 'lib/apertur/client.rb', line 43

def encryption
  @encryption
end

#envString (readonly)

Returns the environment this client targets (“live” or “test”).

Returns:

  • (String)

    the environment this client targets (“live” or “test”)



19
20
21
# File 'lib/apertur/client.rb', line 19

def env
  @env
end

#keysApertur::Resources::Keys (readonly)



37
38
39
# File 'lib/apertur/client.rb', line 37

def keys
  @keys
end

#pollingApertur::Resources::Polling (readonly)



31
32
33
# File 'lib/apertur/client.rb', line 31

def polling
  @polling
end

#sessionsApertur::Resources::Sessions (readonly)



22
23
24
# File 'lib/apertur/client.rb', line 22

def sessions
  @sessions
end

#statsApertur::Resources::Stats (readonly)



46
47
48
# File 'lib/apertur/client.rb', line 46

def stats
  @stats
end

#uploadApertur::Resources::Upload (readonly)



25
26
27
# File 'lib/apertur/client.rb', line 25

def upload
  @upload
end

#uploadsApertur::Resources::Uploads (readonly)



28
29
30
# File 'lib/apertur/client.rb', line 28

def uploads
  @uploads
end

#webhooksApertur::Resources::Webhooks (readonly)



40
41
42
# File 'lib/apertur/client.rb', line 40

def webhooks
  @webhooks
end