class Whats::Actions::Login

Constants

PATH

Attributes

client[R]

Public Class Methods

new() click to toggle source
# File lib/whats/actions/login.rb, line 10
def initialize
  @user = Whats.configuration.user
  @password = Whats.configuration.password
  @client = Whats::Client.new(encoded_auth, :basic)
end

Public Instance Methods

call() click to toggle source
# File lib/whats/actions/login.rb, line 16
def call
  client.request(PATH)
end
token() click to toggle source
# File lib/whats/actions/login.rb, line 20
def token
  return @token if valid?

  extract_atributes call

  @token
end

Private Instance Methods

encoded_auth() click to toggle source
# File lib/whats/actions/login.rb, line 37
def encoded_auth
  Base64.encode64("#{@user}:#{@password}").chomp
end
extract_atributes(response) click to toggle source
# File lib/whats/actions/login.rb, line 32
def extract_atributes(response)
  @token = response["users"].first["token"]
  @expires_after = response["users"].first["expires_after"]
end
valid?() click to toggle source
# File lib/whats/actions/login.rb, line 41
def valid?
  return false if @expires_after.nil?

  @expires_after > Time.now
end