Class: Teamwork::API
- Inherits:
-
Object
- Object
- Teamwork::API
- Defined in:
- lib/teamwork.rb
Instance Method Summary collapse
- #account(request_params) ⇒ Object
- #attach_post_to_project(title, body, project_id) ⇒ Object
- #create_company(name) ⇒ Object
- #create_project(name, client_name) ⇒ Object
- #create_task(task, project_id) ⇒ Object
- #create_task_list(task_list, project_id) ⇒ Object
- #delete_project(id) ⇒ Object
- #get_comment(id) ⇒ Object
- #get_company_id(name) ⇒ Object
- #get_or_create_company(name) ⇒ Object
- #get_tasks(id) ⇒ Object
-
#initialize(project_name: nil, api_key: nil) ⇒ API
constructor
A new instance of API.
- #latestActivity(maxItems: 60, onlyStarred: false) ⇒ Object
- #people(request_params) ⇒ Object
- #update_project(id, name, client_name) ⇒ Object
Constructor Details
#initialize(project_name: nil, api_key: nil) ⇒ API
Returns a new instance of API.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# 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 |
Instance Method Details
#account(request_params) ⇒ Object
27 28 29 30 |
# File 'lib/teamwork.rb', line 27 def account(request_params) response = @api_conn.get "account.json", request_params response.body end |
#attach_post_to_project(title, body, project_id) ⇒ Object
128 129 130 |
# File 'lib/teamwork.rb', line 128 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) ⇒ Object
55 56 57 |
# File 'lib/teamwork.rb', line 55 def create_company(name) @api_conn.post 'companies.json', { company: { name: name } } end |
#create_project(name, client_name) ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/teamwork.rb', line 64 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) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/teamwork.rb', line 94 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) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/teamwork.rb', line 107 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) ⇒ Object
85 86 87 |
# File 'lib/teamwork.rb', line 85 def delete_project(id) @api_conn.delete "projects/#{id}.json" end |
#get_comment(id) ⇒ Object
46 47 48 49 |
# 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) ⇒ Object
51 52 53 |
# 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) ⇒ Object
59 60 61 62 |
# 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) ⇒ Object
89 90 91 92 |
# File 'lib/teamwork.rb', line 89 def get_tasks(id) response = @api_conn.get "projects/#{id}/todo_lists.json" response.body["todo-lists"] end |
#latestActivity(maxItems: 60, onlyStarred: false) ⇒ Object
37 38 39 40 41 42 43 44 |
# 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) ⇒ Object
32 33 34 35 |
# File 'lib/teamwork.rb', line 32 def people(request_params) response = @api_conn.get "people.json", request_params response.body end |
#update_project(id, name, client_name) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/teamwork.rb', line 75 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 |