Module: Todoist::Resource

Included in:
Filter, Item, Label, Note, Project, Reminder, User
Defined in:
lib/todoist/resource.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#temp_idObject

Returns the value of attribute temp_id.



16
17
18
# File 'lib/todoist/resource.rb', line 16

def temp_id
  @temp_id
end

Instance Method Details

#attributesObject



22
23
24
25
26
27
28
29
# File 'lib/todoist/resource.rb', line 22

def attributes
  self.class.attributes.inject({}) do |attributes, attribute|
    value = send(attribute)
    if !value.nil?
      attributes[attribute] = value
    end; attributes
  end
end

#attributes=(attributes) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/todoist/resource.rb', line 31

def attributes=(attributes)
  attributes.each do |attribute, value|
    if respond_to?(writer = attribute.to_s + '=')
      send(writer, value)
    else
      logger.warn "#{self.class} does not have an `#{attribute}' attribute"
    end
  end
end

#command_classObject



53
54
55
# File 'lib/todoist/resource.rb', line 53

def command_class
  @command_class ||= Command
end

#create_command(name, arguments, tmp_id = nil) ⇒ Object



49
50
51
# File 'lib/todoist/resource.rb', line 49

def create_command(name, arguments, tmp_id = nil)
  command_class.new(name, arguments, tmp_id)
end

#initialize(attributes = {}) ⇒ Object



18
19
20
# File 'lib/todoist/resource.rb', line 18

def initialize(attributes={})
  self.attributes = attributes || {}
end

#loggerObject



45
46
47
# File 'lib/todoist/resource.rb', line 45

def logger
  @logger ||=  Logger.new
end

#persisted?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/todoist/resource.rb', line 69

def persisted?
  !id.nil?
end

#resource_typeObject



65
66
67
# File 'lib/todoist/resource.rb', line 65

def resource_type
  self.class.name.split('::').last.downcase
end

#to_hashObject



41
42
43
# File 'lib/todoist/resource.rb', line 41

def to_hash
  attributes
end

#to_submittable_hashObject



57
58
59
60
61
62
63
# File 'lib/todoist/resource.rb', line 57

def to_submittable_hash
  if self.class.read_only_attributes
    attributes.delete_if { |key, value| self.class.read_only_attributes.include?(key)}
  else
    attributes
  end
end