Class: Podio::Task

Inherits:
ActivePodio::Base show all
Includes:
ActivePodio::Updatable
Defined in:
lib/podio/models/task.rb

Instance Attribute Summary

Attributes inherited from ActivePodio::Base

#attributes, #error_code, #error_message, #error_parameters, #error_propagate

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ActivePodio::Base

#==, #[], #[]=, #api_friendly_ref_type, #as_json, collection, delegate_to_hash, handle_api_errors_for, has_many, has_one, #hash, #initialize, list, member, #new_record?, #persisted?, property, #to_param

Constructor Details

This class inherits a constructor from ActivePodio::Base

Class Method Details

.complete(id) ⇒ Object



135
136
137
# File 'lib/podio/models/task.rb', line 135

def complete(id)
  Podio.connection.post("/task/#{id}/complete").body
end

.create(attributes) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/podio/models/task.rb', line 81

def create(attributes)
  response = Podio.connection.post do |req|
    req.url "/task/"
    req.body = attributes
  end

  response.body['task_id']
end

.create_with_ref(ref_type, ref_id, attributes) ⇒ Object



90
91
92
93
94
95
96
97
# File 'lib/podio/models/task.rb', line 90

def create_with_ref(ref_type, ref_id, attributes)
  response = Podio.connection.post do |req|
    req.url "/task/#{ref_type}/#{ref_id}/"
    req.body = attributes
  end

  response.body['task_id']
end

.delete(id) ⇒ Object



131
132
133
# File 'lib/podio/models/task.rb', line 131

def delete(id)
  Podio.connection.delete("/task/#{id}").status
end

.find(id) ⇒ Object



147
148
149
# File 'lib/podio/models/task.rb', line 147

def find(id)
  member Podio.connection.get("/task/#{id}").body
end

.find_all(options = {}) ⇒ Object



155
156
157
158
159
# File 'lib/podio/models/task.rb', line 155

def find_all(options={})
  list Podio.connection.get { |req|
    req.url('/task/', options)
  }.body
end

.find_for_reference(ref_type, ref_id) ⇒ Object



151
152
153
# File 'lib/podio/models/task.rb', line 151

def find_for_reference(ref_type, ref_id)
  list Podio.connection.get("/task/#{ref_type}/#{ref_id}/").body
end

.find_personal_summaryObject



177
178
179
180
181
182
183
# File 'lib/podio/models/task.rb', line 177

def find_personal_summary
  response = Podio.connection.get("/task/personal/summary").body
  response['overdue']['tasks'] = list(response['overdue']['tasks'])
  response['today']['tasks'] = list(response['today']['tasks'])
  response['other']['tasks'] = list(response['other']['tasks'])
  response
end

.find_summaryObject



161
162
163
164
165
166
167
# File 'lib/podio/models/task.rb', line 161

def find_summary
  response = Podio.connection.get("/task/summary").body
  response['overdue']['tasks'] = list(response['overdue']['tasks'])
  response['today']['tasks'] = list(response['today']['tasks'])
  response['other']['tasks'] = list(response['other']['tasks'])
  response
end

.find_summary_for_reference(ref_type, ref_id) ⇒ Object



169
170
171
172
173
174
175
# File 'lib/podio/models/task.rb', line 169

def find_summary_for_reference(ref_type, ref_id)
  response = Podio.connection.get("/task/#{ref_type}/#{ref_id}/summary").body
  response['overdue']['tasks'] = list(response['overdue']['tasks'])
  response['today']['tasks'] = list(response['today']['tasks'])
  response['other']['tasks'] = list(response['other']['tasks'])
  response
end

.incomplete(id) ⇒ Object



139
140
141
# File 'lib/podio/models/task.rb', line 139

def incomplete(id)
  Podio.connection.post("/task/#{id}/incomplete").body
end

.rank(id, before_task_id, after_task_id) ⇒ Object



143
144
145
# File 'lib/podio/models/task.rb', line 143

def rank(id, before_task_id, after_task_id)
  Podio.connection.post("/task/#{id}/rank", {:before => before_task_id, :after => after_task_id}).body
end

.update_assignee(id, user_id) ⇒ Object



119
120
121
# File 'lib/podio/models/task.rb', line 119

def update_assignee(id, user_id)
  Podio.connection.post("/task/#{id}/assign", {:responsible => user_id}).status
end

.update_description(id, description) ⇒ Object



99
100
101
# File 'lib/podio/models/task.rb', line 99

def update_description(id, description)
  Podio.connection.put("/task/#{id}/description", {:description => description}).status
end

.update_due_date(id, due_date) ⇒ Object



111
112
113
# File 'lib/podio/models/task.rb', line 111

def update_due_date(id, due_date)
  Podio.connection.put("/task/#{id}/due_date", {:due_date => due_date}).status
end

.update_due_on(id, due_on) ⇒ Object



115
116
117
# File 'lib/podio/models/task.rb', line 115

def update_due_on(id, due_on)
  Podio.connection.put("/task/#{id}/due_on", {:due_on => due_on}).status
end

.update_labels(id, label_ids) ⇒ Object



127
128
129
# File 'lib/podio/models/task.rb', line 127

def update_labels(id, label_ids)
  Podio.connection.put("/task/#{id}/label/", label_ids).status
end

.update_private(id, private_flag) ⇒ Object



107
108
109
# File 'lib/podio/models/task.rb', line 107

def update_private(id, private_flag)
  Podio.connection.put("/task/#{id}/private", {:private => private_flag}).status
end

.update_reference(id, ref_type, ref_id) ⇒ Object



123
124
125
# File 'lib/podio/models/task.rb', line 123

def update_reference(id, ref_type, ref_id)
  Podio.connection.put("/task/#{id}/ref", {:ref_type => ref_type, :ref_id => ref_id}).status
end

.update_text(id, text) ⇒ Object



103
104
105
# File 'lib/podio/models/task.rb', line 103

def update_text(id, text)
  Podio.connection.put("/task/#{id}/text", {:text => text}).status
end

Instance Method Details

#completeObject



66
67
68
# File 'lib/podio/models/task.rb', line 66

def complete
  self.class.complete(self.id)
end

#createObject



45
46
47
48
49
50
51
52
# File 'lib/podio/models/task.rb', line 45

def create
  compacted_attributes = remove_nil_values(self.attributes)
  if(self.ref_type.present? && self.ref_id.present?)
    self.task_id = self.class.create_with_ref(self.ref_type, self.ref_id, compacted_attributes)
  else
    self.task_id = self.class.create(compacted_attributes)
  end
end

#destroyObject



54
55
56
# File 'lib/podio/models/task.rb', line 54

def destroy
  self.class.delete(self.id)
end

#rank(previous_task, next_task) ⇒ Object



74
75
76
# File 'lib/podio/models/task.rb', line 74

def rank(previous_task, next_task)
  self.class.rank(self.id, previous_task && previous_task.to_i, next_task && next_task.to_i)
end

#uncompleteObject



70
71
72
# File 'lib/podio/models/task.rb', line 70

def uncomplete
  self.class.incomplete(self.id)
end

#update_labels(label_ids) ⇒ Object



62
63
64
# File 'lib/podio/models/task.rb', line 62

def update_labels(label_ids)
  self.class.update_labels(self.id, label_ids)
end

#update_reference(ref_type, ref_id) ⇒ Object



58
59
60
# File 'lib/podio/models/task.rb', line 58

def update_reference(ref_type, ref_id)
  self.class.update_reference(self.id, ref_type, ref_id)
end