Class: TaskMapper::Provider::Bcx::API

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/provider/api/auth.rb,
lib/provider/api/todos.rb,
lib/provider/api/comments.rb,
lib/provider/api/projects.rb,
lib/provider/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(account_id, username, password) ⇒ API

Returns a new instance of API.



12
13
14
15
16
17
18
# File 'lib/provider/api.rb', line 12

def initialize(, username, password)
  @username = username
  @password = password
  @account_id = 
  self.class.base_uri "https://basecamp.com/#{account_id}/api/v1"
  self.class.basic_auth username, password
end

Instance Attribute Details

#account_idObject (readonly)

Returns the value of attribute account_id.



8
9
10
# File 'lib/provider/api.rb', line 8

def 
  @account_id
end

#passwordObject (readonly)

Returns the value of attribute password.



8
9
10
# File 'lib/provider/api.rb', line 8

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



8
9
10
# File 'lib/provider/api.rb', line 8

def username
  @username
end

Instance Method Details

#authenticated?Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
# 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) ⇒ Object



4
5
6
7
8
9
10
11
# 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) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# 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) ⇒ Object



8
9
10
# File 'lib/provider/api/projects.rb', line 8

def project(id)
  self.class.get "/projects/#{id}.json"
end

#projectsObject



4
5
6
# File 'lib/provider/api/projects.rb', line 4

def projects
  self.class.get "/projects.json"
end

#todo(project_id, todo_id) ⇒ Object



18
19
20
# 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) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# 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) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# 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