class AflTeamwork::Client

Public Class Methods

new(teamwork_name, api_key) click to toggle source
# File lib/afl_teamwork/client.rb, line 6
def initialize(teamwork_name, api_key)
  @tw_name = teamwork_name
  @api_key = api_key
end

Public Instance Methods

add_task_to_list(task, list) click to toggle source
# File lib/afl_teamwork/client.rb, line 29
def add_task_to_list(task, list)
  connection.post do |req|
    req.url "/tasklists/#{list}/tasks.json"
    req.headers['Content-Type'] = 'application/json'
    req.body = task.to_json
  end
end
get_list_items(list) click to toggle source
# File lib/afl_teamwork/client.rb, line 19
def get_list_items(list)
  get_tasklists.each do |tasklist|
    if list === tasklist['name']
      tasklist_id = tasklist['id']
      todo_items = connection.get("/tasklists/#{tasklist_id}/tasks.json")
      return JSON.parse(todo_items.body)['todo-items']
    end
  end
end
get_tasklist(list) click to toggle source
# File lib/afl_teamwork/client.rb, line 11
def get_tasklist(list)
  get_tasklists.each do |tasklist|
    if list === tasklist['name']
      return tasklist
    end
  end
end

Protected Instance Methods

connection() click to toggle source
# File lib/afl_teamwork/client.rb, line 45
def connection
  Faraday.new(:url => "https://#{@tw_name}.teamwork.com") do |faraday|
    faraday.request  :basic_auth, @api_key, 'xxx'
    faraday.request  :url_encoded             # form-encode POST params
    faraday.response :logger                  # log requests to STDOUT
    faraday.adapter  Faraday.default_adapter  # make requests with Net::HTTP
  end
end
get_tasklists() click to toggle source
# File lib/afl_teamwork/client.rb, line 39
def get_tasklists
  project_id = AflTeamwork.configuration.project_id
  projects = connection.get("/projects/#{project_id}/tasklists.json")
  tasklists = JSON.parse(projects.body)['tasklists']
end