class TodoableWrapper::Client

Public Class Methods

new(u, p) click to toggle source
# File lib/todoable_wrapper.rb, line 16
def initialize(u, p)
  @auth = { username: u, password: p }
  get_token
end

Public Instance Methods

get_token() click to toggle source
# File lib/todoable_wrapper.rb, line 21
def get_token
  begin
    options = { basic_auth: @auth }
    response = self.class.post('/authenticate', options)
    @token = JSON.parse(response.body)["token"]
    @expires_at = JSON.parse(response.body)["expires_at"].to_datetime
  rescue => exception
    puts exception
    puts "Invalid credentials"
  end
end

Private Instance Methods

validate_token() click to toggle source
# File lib/todoable_wrapper.rb, line 34
def validate_token
  if @expires_at && @expires_at < DateTime.now
    get_token
  end
end