class CompanionApi::Base
Attributes
account[RW]
login[RW]
market[RW]
profile[RW]
Public Class Methods
new(profile_name)
click to toggle source
# File lib/companion_api/base.rb, line 8 def initialize(profile_name) @profile = Profile.new(profile_name) @account = CompanionApi::Resources::Account.new(@profile) @login = CompanionApi::Resources::Login.new(@profile) @market = CompanionApi::Resources::Market.new(@profile) end
Public Instance Methods
loggedin?()
click to toggle source
# File lib/companion_api/base.rb, line 31 def loggedin? @login.character.present? end
login!(username, password)
click to toggle source
# File lib/companion_api/base.rb, line 15 def login!(username, password) raise CompanionApi::Error, 'no username or password specified' if username.blank? || password.blank? @account.auto_login!(username, password) end
token_auth!()
click to toggle source
# File lib/companion_api/base.rb, line 21 def token_auth! @account.token_login! url = @account.login_url CompanionApi.config.logger.info("please visit #{url} and hit enter afterwards") gets res = @login.post_auth raise CompanionApi::Error, 'invalid response received' if res['status'] != 200 end
valid_token?()
click to toggle source
# File lib/companion_api/base.rb, line 35 def valid_token? last_login = @profile.get("lastLogin") return false if last_login.blank? diff = Time.now.to_i - last_login # we use 12 hours for now to refresh tokens a bit more often and prevent expiring diff < 12 * 60 * 60 end