Class: Podio::TaskLabel

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

Constant Summary collapse

DEFAULT_COLOR_FOR_NEW_LABELS =
'E9E9E9'

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 included from ActivePodio::Updatable

#remove_nil_values, #update_attributes

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, #initialize_attributes, list, member, #new_record?, output_attribute_as_json, #persisted?, property, #to_param

Constructor Details

This class inherits a constructor from ActivePodio::Base

Class Method Details

.create(attributes) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/podio/models/task_label.rb', line 33

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

  response.body['label_id']
end

.delete(label_id) ⇒ Object



42
43
44
# File 'lib/podio/models/task_label.rb', line 42

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

.find_all_labelsObject



27
28
29
30
31
# File 'lib/podio/models/task_label.rb', line 27

def find_all_labels
  list Podio.connection.get { |req|
    req.url("/task/label/")
  }.body
end

.update(label_id, attributes) ⇒ Object



46
47
48
# File 'lib/podio/models/task_label.rb', line 46

def update(label_id, attributes)
  Podio.connection.put("/task/label/#{label_id}", attributes).status
end

Instance Method Details

#createObject



10
11
12
13
14
15
16
# File 'lib/podio/models/task_label.rb', line 10

def create
  if self.color.nil? || self.color.empty?
    self.color = DEFAULT_COLOR_FOR_NEW_LABELS
  end
  
  self.label_id = self.class.create(self.attributes)
end

#destroyObject



18
19
20
# File 'lib/podio/models/task_label.rb', line 18

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

#updateObject



22
23
24
# File 'lib/podio/models/task_label.rb', line 22

def update
  self.class.update(self.label_id, self.attributes)
end