Class: StudyLine::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/study_line.rb

Defined Under Namespace

Classes: Sender

Instance Method Summary collapse

Instance Method Details

#configure(token, base_url = nil) ⇒ Object



13
14
15
16
17
18
# File 'lib/study_line.rb', line 13

def configure(token, base_url = nil)
  config = { 'CUSTOM_TOKEN' => token }
  config['BASE_URL'] = base_url unless base_url.nil? || base_url.empty?
  File.write(CONFIG_FILE, config.to_json)
  puts "トークン#{'とベースURL' if base_url}が設定されました。"
end

#finishObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/study_line.rb', line 51

def finish
  finish_time = Time.now
  response = Sender.post(
    "#{Sender.base_uri}/update",
    body: { finish_time: finish_time }.to_json,
    headers: headers
  )
  # Handle the response...
  if response.success?
    puts "学習の終了時間を記録します。"
  else
    error_message = response.parsed_response['message'] || 'Unknown error'
    puts "Error: #{error_message}"
  end

end

#showObject



69
70
71
72
73
74
75
76
# File 'lib/study_line.rb', line 69

def show
  if File.exist?(CONFIG_FILE)
    config = JSON.parse(File.read(CONFIG_FILE))
    puts "現在のCUSTOM_TOKEN: #{config['CUSTOM_TOKEN'] || '未設定'}"
  else
    puts "トークンは未設定です。"
  end
end

#startObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/study_line.rb', line 33

def start
  start_time = Time.now
  tags = options[:tag] ? options[:tag].split(',') : []
  response = Sender.post(
    "#{Sender.base_uri}/create",
    body: { start_time: start_time, tags: tags  }.to_json,
    headers: headers
  )
  # Handle the response...
  if response.success?
    puts "学習セッションの開始に成功しました。"
  else
    error_message = response.parsed_response['error'] || response.parsed_response['message'] || 'Unknown error'
    puts "Error: #{response['error']}"
  end
end