Class: Apertur::Resources::Sessions
- Inherits:
-
Object
- Object
- Apertur::Resources::Sessions
- Defined in:
- lib/apertur/resources/sessions.rb
Overview
Manage upload sessions.
Upload sessions represent a time-limited context in which one or more images can be uploaded. Each session has a unique UUID, optional password protection, and configurable constraints.
Instance Method Summary collapse
-
#create(**options) ⇒ Hash
Create a new upload session.
-
#delivery_status(uuid, poll_from: nil) ⇒ Hash
Get the delivery status for a session.
-
#get(uuid) ⇒ Hash
Retrieve an existing upload session by UUID.
-
#initialize(http) ⇒ Sessions
constructor
A new instance of Sessions.
-
#list(**params) ⇒ Hash
List upload sessions with pagination.
-
#qr(uuid, **options) ⇒ String
Get the QR code image for an upload session.
-
#recent(**params) ⇒ Array<Hash>
List recent upload sessions.
-
#update(uuid, **options) ⇒ Hash
Update an existing upload session.
-
#verify_password(uuid, password) ⇒ Hash
Verify a session password.
Constructor Details
#initialize(http) ⇒ Sessions
Returns a new instance of Sessions.
12 13 14 |
# File 'lib/apertur/resources/sessions.rb', line 12 def initialize(http) @http = http end |
Instance Method Details
#create(**options) ⇒ Hash
Create a new upload session.
28 29 30 |
# File 'lib/apertur/resources/sessions.rb', line 28 def create(**) @http.request(:post, "/api/v1/upload-sessions", body: ) end |
#delivery_status(uuid, poll_from: nil) ⇒ Hash
Get the delivery status for a session.
Returns a hash with the following shape:
{
"status" => "pending" | "active" | "completed" | "expired",
"files" => [ { "record_id" => ..., "filename" => ..., "size_bytes" => ...,
"destinations" => [ { "destination_id" => ..., "status" => ..., ... } ] } ],
"lastChanged" => "<ISO 8601>"
}
When poll_from (ISO 8601 timestamp) is provided, the server long-polls for up to 5 minutes waiting for something to change before responding. This call automatically widens the read timeout to 360 s (6 min) in that case so the server releases first under the happy path.
122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/apertur/resources/sessions.rb', line 122 def delivery_status(uuid, poll_from: nil) query = {} query["pollFrom"] = poll_from if poll_from read_timeout = poll_from ? 360 : nil @http.request( :get, "/api/v1/upload-sessions/#{uuid}/delivery-status", query: query, read_timeout: read_timeout, ) end |
#get(uuid) ⇒ Hash
Retrieve an existing upload session by UUID.
36 37 38 |
# File 'lib/apertur/resources/sessions.rb', line 36 def get(uuid) @http.request(:get, "/api/v1/upload/#{uuid}/session") end |
#list(**params) ⇒ Hash
List upload sessions with pagination.
54 55 56 57 58 59 |
# File 'lib/apertur/resources/sessions.rb', line 54 def list(**params) query = {} query["page"] = params[:page].to_s if params[:page] query["pageSize"] = params[:page_size].to_s if params[:page_size] @http.request(:get, "/api/v1/sessions", query: query) end |
#qr(uuid, **options) ⇒ String
Get the QR code image for an upload session.
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/apertur/resources/sessions.rb', line 82 def qr(uuid, **) query = {} query["format"] = [:format] if [:format] query["size"] = [:size].to_s if [:size] query["style"] = [:style] if [:style] query["fg"] = [:fg] if [:fg] query["bg"] = [:bg] if [:bg] query["borderSize"] = [:border_size].to_s if [:border_size] query["borderColor"] = [:border_color] if [:border_color] @http.request_raw(:get, "/api/v1/upload-sessions/#{uuid}/qr", query: query) end |
#recent(**params) ⇒ Array<Hash>
List recent upload sessions.
65 66 67 68 69 |
# File 'lib/apertur/resources/sessions.rb', line 65 def recent(**params) query = {} query["limit"] = params[:limit].to_s if params[:limit] @http.request(:get, "/api/v1/sessions/recent", query: query) end |
#update(uuid, **options) ⇒ Hash
Update an existing upload session.
45 46 47 |
# File 'lib/apertur/resources/sessions.rb', line 45 def update(uuid, **) @http.request(:patch, "/api/v1/upload-sessions/#{uuid}", body: ) end |
#verify_password(uuid, password) ⇒ Hash
Verify a session password.
99 100 101 |
# File 'lib/apertur/resources/sessions.rb', line 99 def verify_password(uuid, password) @http.request(:post, "/api/v1/upload/#{uuid}/verify-password", body: { password: password }) end |