Class: Ghostcrawl::SessionsClient
- Inherits:
-
Object
- Object
- Ghostcrawl::SessionsClient
- Defined in:
- lib/ghostcrawl/client.rb
Overview
Manage browser sessions — /v1/sessions.
Instance Method Summary collapse
-
#create(profile_name:, **opts) ⇒ Object
Create a new browser session.
-
#extend(session_id, duration_seconds: 300) ⇒ Object
Extend a session's TTL.
-
#initialize(v1) ⇒ SessionsClient
constructor
A new instance of SessionsClient.
-
#list ⇒ Object
List all active sessions.
-
#release(session_id) ⇒ Object
Release a session back to the pool.
Constructor Details
#initialize(v1) ⇒ SessionsClient
Returns a new instance of SessionsClient.
509 510 511 |
# File 'lib/ghostcrawl/client.rb', line 509 def initialize(v1) @v1 = v1 end |
Instance Method Details
#create(profile_name:, **opts) ⇒ Object
Create a new browser session. Delegates to POST /v1/sessions/create via the generated builder.
522 523 524 525 |
# File 'lib/ghostcrawl/client.rb', line 522 def create(profile_name:, **opts) data = { "profile" => profile_name }.merge(opts.transform_keys(&:to_s)) ResponseHelper.to_hash(@v1.sessions.create.post(AdditionalDataBody.new(data))) end |
#extend(session_id, duration_seconds: 300) ⇒ Object
Extend a session's TTL. Delegates to POST /v1/sessions/id/extend via the generated builder.
529 530 531 532 533 |
# File 'lib/ghostcrawl/client.rb', line 529 def extend(session_id, duration_seconds: 300) ResponseHelper.to_hash(@v1.sessions.by_profile_id(session_id).extend.post( AdditionalDataBody.new({ "ttl_seconds" => duration_seconds }) )) end |
#list ⇒ Object
List all active sessions. Delegates to GET /v1/sessions via the generated SessionsRequestBuilder.
515 516 517 |
# File 'lib/ghostcrawl/client.rb', line 515 def list ResponseHelper.to_hash(@v1.sessions.get) end |
#release(session_id) ⇒ Object
Release a session back to the pool. Delegates to POST /v1/sessions/id/release via the generated builder.
537 538 539 |
# File 'lib/ghostcrawl/client.rb', line 537 def release(session_id) ResponseHelper.to_hash(@v1.sessions.by_profile_id(session_id).release.post) end |