class Todoable::User

Constants

AUTH_PATH

Attributes

password[RW]
token[RW]
username[RW]

Public Class Methods

authenticate_user(username, password) click to toggle source
# File lib/todoable.rb, line 15
def self.authenticate_user(username, password)
    user = new
    user.username = username
    user.password = password
    user.token = self.get_token!(user)
    user
end
get_token!(client) click to toggle source
# File lib/todoable.rb, line 23
def self.get_token!(client)
    req = RestClient::Request.new(
        method: :post,
        url: BASE_ROUTE+AUTH_PATH,
        user: client.username,
        password: client.password,
        headers: {
            content_type: :json,
            accept: :json
        }
    )
    resp = req.execute {|resp| resp} 
    if resp.code == 401
        return "Unauthorized"
    end 
    resp = JSON.parse(resp)
    
    resp['token']
end

Public Instance Methods

list_items(list_id) click to toggle source
# File lib/todoable.rb, line 68
def list_items(list_id)
    Item.new(self, list_id)
end
list_lists() click to toggle source
# File lib/todoable.rb, line 64
def list_lists
    List.new(self)
end
make_request(path, type, values = nil) click to toggle source
# File lib/todoable.rb, line 43
def make_request(path, type, values = nil)
    data = {
        method: type,
        url: BASE_ROUTE+path,
        headers: {
            content_type: :json,
            accept: :json,
            authorization: "Token token=\"#{token}\""
        }
    }
    if values
        data.merge!(payload: values.to_json)
    end
    req = RestClient::Request.new(data)
    req = req.execute
    if type != :delete and type != :patch
        resp = JSON.parse(req)
        return resp
    end
end