Class: TimeBuffer::SessionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/time_buffer/session_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(start_time:, end_time:) ⇒ SessionHandler

Returns a new instance of SessionHandler.



7
8
9
10
# File 'lib/time_buffer/session_handler.rb', line 7

def initialize(start_time:, end_time:)
  @start_time = start_time
  @end_time = end_time
end

Instance Method Details

#insert_time_session(app_data) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/time_buffer/session_handler.rb', line 12

def insert_time_session(app_data)
  application_id = TimeBuffer::DatabaseConnector.new.execute(
    "SELECT id FROM applications WHERE bundle_id = ?",
    [app_data.bundle_id]
  ).first&.first

  puts "application ID: #{application_id}"

  TimeBuffer::DatabaseConnector.new.execute(
    "INSERT INTO time_sessions (application_id, start_time, end_time, metadata) VALUES (?, ?, ?, ?);",
    [application_id, start_time.strftime("%Y-%m-%d %H:%M:%S"), end_time.strftime("%Y-%m-%d %H:%M:%S"), app_data..to_json]
  )
end