class Teamwork::API
Public Class Methods
new(project_name: nil, api_key: nil)
click to toggle source
# File lib/teamwork.rb, line 12 def initialize(project_name: nil, api_key: nil) @project_name = project_name @api_key = api_key @api_conn = Faraday.new(url: "http://#{project_name}.teamworkpm.net/") do |c| c.request :multipart c.request :json c.request :url_encoded c.response :json, content_type: /\bjson$/ c.adapter :net_http end @api_conn.headers[:cache_control] = 'no-cache' @api_conn.basic_auth(api_key, '') end
Public Instance Methods
account(request_params)
click to toggle source
# File lib/teamwork.rb, line 27 def account(request_params) response = @api_conn.get "account.json", request_params response.body end
archive_project(id)
click to toggle source
# File lib/teamwork.rb, line 93 def archive_project(id) @api_conn.put("projects/#{id}.json", { project: { status: 'inactive', } }).status end
attach_post_to_project(title, body, project_id)
click to toggle source
# File lib/teamwork.rb, line 144 def attach_post_to_project(title, body, project_id) @api_conn.post "projects/#{project_id}/messsages.json", { post: { title: title, body: body }.to_json } end
create_company(name)
click to toggle source
# File lib/teamwork.rb, line 55 def create_company(name) @api_conn.post 'companies.json', { company: { name: name } } end
create_project(name, client_name)
click to toggle source
# File lib/teamwork.rb, line 72 def create_project(name, client_name) company_id = get_or_create_company(client_name) @api_conn.post('projects.json', { project: { name: name, companyId: company_id, "category-id" => '0' } }).headers['id'] end
create_task(task,project_id)
click to toggle source
# File lib/teamwork.rb, line 110 def create_task(task,project_id) @api_conn.post "/tasklists/#{project_id}/tasks.json", { "todo-item"=>{ "content"=>task["content"], "notify"=>false, "description"=>task["description"], "private"=>0 } } end
create_task_list(task_list,project_id)
click to toggle source
# File lib/teamwork.rb, line 123 def create_task_list(task_list,project_id) { "todo-list" => task_list.to_json }.to_json @api_conn.post "projects/#{project_id}/todo_lists.json", { "todo-list"=> { "name"=> task_list['name'], "private"=> false, "pinned"=> true, "tracked"=> true, "milestone-id"=> "", } }.to_json end
delete_project(id)
click to toggle source
# File lib/teamwork.rb, line 101 def delete_project(id) @api_conn.delete "projects/#{id}.json" end
get_comment(id)
click to toggle source
# File lib/teamwork.rb, line 46 def get_comment(id) response = @api_conn.get "comments/#{id}.json" response.body["comment"] end
get_company_id(name)
click to toggle source
# File lib/teamwork.rb, line 51 def get_company_id(name) Hash[@api_conn.get('companies.json').body["companies"].map { |c| [c['name'], c['id']] }][name] end
get_or_create_company(name)
click to toggle source
# File lib/teamwork.rb, line 59 def get_or_create_company(name) create_company(name) if !get_company_id(name) get_company_id(name) end
get_tasks(id)
click to toggle source
# File lib/teamwork.rb, line 105 def get_tasks(id) response = @api_conn.get "projects/#{id}/todo_lists.json" response.body["todo-lists"] end
latestActivity(maxItems: 60, onlyStarred: false)
click to toggle source
# File lib/teamwork.rb, line 37 def latestActivity(maxItems: 60, onlyStarred: false) request_params = { maxItems: maxItems, onlyStarred: onlyStarred } response = @api_conn.get "latestActivity.json", request_params response.body end
people(request_params)
click to toggle source
# File lib/teamwork.rb, line 32 def people(request_params) response = @api_conn.get "people.json", request_params response.body end
projects()
click to toggle source
# File lib/teamwork.rb, line 64 def projects() request_params = { status: "ACTIVE" } response = @api_conn.get "projects.json", request_params response.body end
update_project(id, name, client_name)
click to toggle source
# File lib/teamwork.rb, line 83 def update_project(id, name, client_name) company_id = get_or_create_company(client_name) @api_conn.put("projects/#{id}.json", { project: { name: name, companyId: company_id } }).status end