class Freee::Pigmon::CLI

Public Instance Methods

authorize(authorize_code) click to toggle source
# File lib/freee/pigmon/cli.rb, line 18
def authorize(authorize_code)
  token_hash = pigmon.fetch_token_hash(authorize_code)
  Freee::Pigmon.configure(
    access_token: token_hash[:access_token],
    refresh_token: token_hash[:refresh_token],
    expires_at: token_hash[:expires_at]
  )
  user_info_hash = pigmon.fetch_freee_user_info_hash(access_token)
  Freee::Pigmon.configure(
    employee_id: user_info_hash[:employee_id],
    company_id: user_info_hash[:company_id]
  )
end
break_begin() click to toggle source
# File lib/freee/pigmon/cli.rb, line 44
def break_begin
  token_refresh if token_expired?
  puts pigmon.break_begin(access_token, employee_id, company_id).body
end
break_end() click to toggle source
# File lib/freee/pigmon/cli.rb, line 50
def break_end
  token_refresh if token_expired?
  puts pigmon.break_end(access_token, employee_id, company_id).body
end
clock_in() click to toggle source
# File lib/freee/pigmon/cli.rb, line 38
def clock_in
  token_refresh if token_expired?
  puts pigmon.clock_in(access_token, employee_id, company_id).body
end
clock_out() click to toggle source
# File lib/freee/pigmon/cli.rb, line 56
def clock_out
  token_refresh if token_expired?
  puts pigmon.clock_out(access_token, employee_id, company_id).body
end
generate_code() click to toggle source
# File lib/freee/pigmon/cli.rb, line 33
def generate_code
  puts Freee::Pigmon.url_to_generate_code(client_id)
end
set_client(client_id, client_secret) click to toggle source
# File lib/freee/pigmon/cli.rb, line 10
def set_client(client_id, client_secret)
  Freee::Pigmon.configure(
    freee_client_id: client_id,
    freee_client_secret: client_secret
  )
end

Private Instance Methods

access_token() click to toggle source
# File lib/freee/pigmon/cli.rb, line 75
def access_token
  Freee::Pigmon.config[:access_token]
end
client_id() click to toggle source
# File lib/freee/pigmon/cli.rb, line 67
def client_id
  Freee::Pigmon.config[:freee_client_id]
end
client_secret() click to toggle source
# File lib/freee/pigmon/cli.rb, line 71
def client_secret
  Freee::Pigmon.config[:freee_client_secret]
end
company_id() click to toggle source
# File lib/freee/pigmon/cli.rb, line 91
def company_id
  Freee::Pigmon.config[:company_id]
end
employee_id() click to toggle source
# File lib/freee/pigmon/cli.rb, line 87
def employee_id
  Freee::Pigmon.config[:employee_id]
end
expires_at() click to toggle source
# File lib/freee/pigmon/cli.rb, line 83
def expires_at
  Freee::Pigmon.config[:expires_at]
end
pigmon() click to toggle source
# File lib/freee/pigmon/cli.rb, line 63
def pigmon
  Freee::Pigmon::Client.new(client_id, client_secret)
end
refresh_token() click to toggle source
# File lib/freee/pigmon/cli.rb, line 79
def refresh_token
  Freee::Pigmon.config[:refresh_token]
end
token_expired?() click to toggle source
# File lib/freee/pigmon/cli.rb, line 95
def token_expired?
  return false if expires_at.nil?

  Time.parse(expires_at) <= Time.now
end
token_is_ok_message() click to toggle source
# File lib/freee/pigmon/cli.rb, line 122
def token_is_ok_message
  puts 'You already prepared token. No problem.'
  true
end
token_refresh() click to toggle source
# File lib/freee/pigmon/cli.rb, line 101
def token_refresh
  token_hash = Freee::Pigmon.token_refresh(
    client_id,
    client_secret,
    access_token,
    refresh_token,
    expires_at
  )

  Freee::Pigmon.configure(
    access_token: token_hash[:access_token],
    refresh_token: token_hash[:refresh_token],
    expires_at: token_hash[:expires_at]
  )
end
warn_to_get_code() click to toggle source
# File lib/freee/pigmon/cli.rb, line 117
def warn_to_get_code
  puts "Get code from here: #{url_to_generate_code}\n"
  true
end