Class: TodoableWrapper::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty, Item, List
Defined in:
lib/todoable_wrapper.rb,
lib/todoable_wrapper/item.rb,
lib/todoable_wrapper/list.rb

Defined Under Namespace

Modules: Item, List

Instance Method Summary collapse

Methods included from Item

#add_item, #delete_item, #finish_item

Methods included from List

#create_list, #delete_list, #get_list_by_id, #lists, #update_list

Constructor Details

#initialize(u, p) ⇒ Client

Returns a new instance of Client.



16
17
18
19
# File 'lib/todoable_wrapper.rb', line 16

def initialize(u, p)
  @auth = { username: u, password: p }
  get_token
end

Instance Method Details

#get_tokenObject



21
22
23
24
25
26
27
28
29
30
31
# 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