Class: StudyLine::CLI
- Inherits:
-
Thor
- Object
- Thor
- StudyLine::CLI
- 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 |
#finish ⇒ Object
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 = response.parsed_response['message'] || 'Unknown error' puts "Error: #{}" end end |
#show ⇒ Object
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 |
#start ⇒ Object
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 = [:tag] ? [:tag].split(',') : [] response = Sender.post( "#{Sender.base_uri}/create", body: { start_time: start_time, tags: }.to_json, headers: headers ) # Handle the response... if response.success? puts "学習セッションの開始に成功しました。" else = response.parsed_response['error'] || response.parsed_response['message'] || 'Unknown error' puts "Error: #{response['error']}" end end |