class TaskMapper::Provider::Bcx::API
Attributes
account_id[R]
password[R]
username[R]
Public Class Methods
new(account_id, username, password)
click to toggle source
# File lib/provider/api.rb, line 12 def initialize(account_id, username, password) @username = username @password = password @account_id = account_id self.class.base_uri "https://basecamp.com/#{account_id}/api/v1" self.class.basic_auth username, password end
Public Instance Methods
authenticated?()
click to toggle source
# File lib/provider/api/auth.rb, line 4 def authenticated? @auth ||= begin me = self.class.get "/people/me.json" me.is_a?(Hash) && !me['id'].nil? end end
create_comment(attributes)
click to toggle source
# File lib/provider/api/comments.rb, line 4 def create_comment(attributes) project = attributes.delete(:project_id) todo = attributes.delete(:ticket_id) body = { "content" => attributes[:body] } url = "/projects#{project}/todos/#{todo}/comments.json" self.class.post url, :body => body.to_json end
create_todo(attributes)
click to toggle source
# File lib/provider/api/todos.rb, line 22 def create_todo(attributes) project = attributes.delete(:project_id) todolist = attributes.delete(:todolist_id) due_at = attributes.delete(:due_at) body = { "content" => attributes[:description] } body.merge({ "due_at" => due_at.utc.iso8601 }) if due_at url = "/projects/#{project}/todolists/#{todolist}/todos.json" self.class.post url, :body => body.to_json end
project(id)
click to toggle source
# File lib/provider/api/projects.rb, line 8 def project(id) self.class.get "/projects/#{id}.json" end
projects()
click to toggle source
# File lib/provider/api/projects.rb, line 4 def projects self.class.get "/projects.json" end
todo(project_id, todo_id)
click to toggle source
# File lib/provider/api/todos.rb, line 18 def todo(project_id, todo_id) self.class.get "/projects/#{project_id}/todos/#{todo_id}.json" end
todos(project_id)
click to toggle source
# File lib/provider/api/todos.rb, line 4 def todos(project_id) ids = get_todolist_ids project_id todo_ids = ids.collect do |id| get_todo_ids_from_list project_id, id end.flatten todos = [] todo_ids.each do |id| todo = self.class.get "/projects/#{project_id}/todos/#{id}.json" todos << Hash[todo] end todos.flatten end
update_todo(todo)
click to toggle source
# File lib/provider/api/todos.rb, line 34 def update_todo(todo) body = { :content => todo['content'], :due_at => todo['due_at'], :completed => todo['completed'] } url = "/projects/#{todo['project_id']}/todos/#{todo['id']}.json" self.class.put url, :body => body.to_json end
Private Instance Methods
get_todo_ids_from_list(project_id, list)
click to toggle source
# File lib/provider/api/todos.rb, line 51 def get_todo_ids_from_list(project_id, list) list = self.class.get "/projects/#{project_id}/todolists/#{list}.json" return [] if !list.is_a?(Hash) || list["todos"].nil? ids = [] ids << list["todos"]["remaining"].map { |t| t['id'] } ids << list["todos"]["completed"].map { |t| t['id'] } ids.flatten end
get_todolist_ids(project_id)
click to toggle source
# File lib/provider/api/todos.rb, line 46 def get_todolist_ids(project_id) lists = self.class.get "/projects/#{project_id}/todolists.json" lists.collect { |t| t['id'] } end