Class: Todoist::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/todoist/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, object, temp_id = nil, uuid = nil) ⇒ Command

Returns a new instance of Command.



5
6
7
8
9
10
# File 'lib/todoist/command.rb', line 5

def initialize(type, object, temp_id = nil, uuid = nil)
  @type = type
  @object = object
  @temp_id = object.temp_id
  @uuid = uuid || SecureRandom.uuid
end

Instance Attribute Details

#objectObject

Returns the value of attribute object.



3
4
5
# File 'lib/todoist/command.rb', line 3

def object
  @object
end

#temp_idObject

Returns the value of attribute temp_id.



3
4
5
# File 'lib/todoist/command.rb', line 3

def temp_id
  @temp_id
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/todoist/command.rb', line 3

def type
  @type
end

#uuidObject

Returns the value of attribute uuid.



3
4
5
# File 'lib/todoist/command.rb', line 3

def uuid
  @uuid
end

Instance Method Details

#argumentsObject



12
13
14
# File 'lib/todoist/command.rb', line 12

def arguments
  object.to_submittable_hash
end

#to_hashObject



16
17
18
19
20
21
22
# File 'lib/todoist/command.rb', line 16

def to_hash
  {
    type: type,
    uuid: uuid,
    args: object.to_submittable_hash
  }.merge(temp_id ? { temp_id: temp_id} : {})
end