Class: Anakin::Sessions
- Inherits:
-
Object
- Object
- Anakin::Sessions
- Defined in:
- lib/anakin/sessions.rb
Overview
Browser-session management. Saved sessions can be replayed via the /v1/browser-connect CDP endpoint to skip re-login flows.
Instance Method Summary collapse
-
#create(name:, description: nil) ⇒ Object
Create an empty named session that can later be saved into.
-
#delete(session_id) ⇒ Object
Delete a saved session.
-
#initialize(client) ⇒ Sessions
constructor
A new instance of Sessions.
-
#list ⇒ Object
List all saved sessions for the API key.
-
#save(session_id, name: nil, description: nil) ⇒ Object
Save the current state of a CDP session by ID.
-
#update(session_id, name: nil, description: nil) ⇒ Object
Update a saved session’s metadata.
Constructor Details
#initialize(client) ⇒ Sessions
Returns a new instance of Sessions.
5 6 7 |
# File 'lib/anakin/sessions.rb', line 5 def initialize(client) @client = client end |
Instance Method Details
#create(name:, description: nil) ⇒ Object
Create an empty named session that can later be saved into.
16 17 18 19 20 |
# File 'lib/anakin/sessions.rb', line 16 def create(name:, description: nil) body = { name: name } body[:description] = description if description @client.send(:request_json, :post, '/browser-sessions', body: body) end |
#delete(session_id) ⇒ Object
Delete a saved session.
39 40 41 42 |
# File 'lib/anakin/sessions.rb', line 39 def delete(session_id) @client.send(:request_json, :delete, "/browser-sessions/#{session_id}") nil end |
#list ⇒ Object
List all saved sessions for the API key.
10 11 12 13 |
# File 'lib/anakin/sessions.rb', line 10 def list resp = @client.send(:request_json, :get, '/browser-sessions') resp.is_a?(Hash) && resp.key?('sessions') ? resp['sessions'] : resp end |
#save(session_id, name: nil, description: nil) ⇒ Object
Save the current state of a CDP session by ID.
23 24 25 26 27 28 |
# File 'lib/anakin/sessions.rb', line 23 def save(session_id, name: nil, description: nil) body = {} body[:name] = name if name body[:description] = description if description @client.send(:request_json, :post, "/browser-sessions/#{session_id}/save", body: body) end |
#update(session_id, name: nil, description: nil) ⇒ Object
Update a saved session’s metadata.
31 32 33 34 35 36 |
# File 'lib/anakin/sessions.rb', line 31 def update(session_id, name: nil, description: nil) body = {} body[:name] = name if name body[:description] = description if description @client.send(:request_json, :put, "/browser-sessions/#{session_id}", body: body) end |