Module: Insightly2::DSL::Tasks

Included in:
Insightly2::DSL
Defined in:
lib/insightly2/dsl/tasks.rb

Instance Method Summary collapse

Instance Method Details

#create_task(task: nil) ⇒ Insightly2::Resources::Task?

POST /v2.1/Tasks Create a task.

Parameters:

  • task (Hash) (defaults to: nil)

    The task to create.

Returns:

Raises:

  • (ArgumentError)

    If the method arguments are blank.



39
40
41
42
# File 'lib/insightly2/dsl/tasks.rb', line 39

def create_task(task: nil)
  raise ArgumentError, "Task cannot be blank" if task.blank?
  Resources::Task.parse(request(:post, "Tasks", task))
end

#create_task_comment(id: nil, comment: nil) ⇒ Insightly2::Resources::Comment?

POST /v2.1/Tasks/c_id/Comments Create a comment for a task.

Parameters:

  • id (String, Fixnum) (defaults to: nil)

    A task’s ID.

  • comment (Hash) (defaults to: nil)

    The comment to create.

Returns:

Raises:

  • (ArgumentError)

    If the method arguments are blank.



50
51
52
53
54
# File 'lib/insightly2/dsl/tasks.rb', line 50

def create_task_comment(id: nil, comment: nil)
  raise ArgumentError, "ID cannot be blank" if id.blank?
  raise ArgumentError, "Comment cannot be blank" if comment.blank?
  Resources::Comment.parse(request(:post, "Tasks/#{id}/Comments", comment))
end

#delete_task(id: nil) ⇒ Faraday::Response

DELETE /v2.1/Tasks/id Delete a task.

Parameters:

  • id (String, Fixnum) (defaults to: nil)

    A Task’s ID.

Returns:

  • (Faraday::Response)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



71
72
73
74
# File 'lib/insightly2/dsl/tasks.rb', line 71

def delete_task(id: nil)
  raise ArgumentError, "ID cannot be blank" if id.blank?
  request(:delete, "Tasks/#{id}")
end

#get_task(id: nil) ⇒ Insightly2::Resources::Task?

GET /v2.1/Tasks/id Get a task.

Parameters:

  • id (String, Fixnum) (defaults to: nil)

    A Task’s ID.

Returns:

Raises:

  • (ArgumentError)

    If the method arguments are blank.



10
11
12
13
# File 'lib/insightly2/dsl/tasks.rb', line 10

def get_task(id: nil)
  raise ArgumentError, "ID cannot be blank" if id.blank?
  Resources::Task.parse(request(:get, "Tasks/#{id}"))
end

#get_task_comments(id: nil) ⇒ Array?

GET /v2.1/Tasks/c_id/Comments Get a list of comments for a task.

Parameters:

  • id (String, Fixnum) (defaults to: nil)

    A Task’s ID.

Returns:

  • (Array, nil)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



20
21
22
23
# File 'lib/insightly2/dsl/tasks.rb', line 20

def get_task_comments(id: nil)
  raise ArgumentError, "ID cannot be blank" if id.blank?
  Resources::Comment.parse(request(:get, "Tasks/#{id}/Comments"))
end

#get_tasks(ids: []) ⇒ Insightly2::Resources::Task?

GET /v2.1/Tasks?ids=ids Get a list of tasks.

Parameters:

  • Array (ids:)

    of task ids (optional).

Returns:



29
30
31
32
# File 'lib/insightly2/dsl/tasks.rb', line 29

def get_tasks(ids: [])
  url = Utils::UrlHelper.build_url(path: "Tasks", params: {ids: ids.join(',')})
  Resources::Task.parse(request(:get, url))
end

#update_task(task: nil) ⇒ Insightly2::Resources::Comment?

PUT /v2.1/Tasks Update a task.

Parameters:

  • task (Hash) (defaults to: nil)

    The task to update.

Returns:

Raises:

  • (ArgumentError)

    If the method arguments are blank.



61
62
63
64
# File 'lib/insightly2/dsl/tasks.rb', line 61

def update_task(task: nil)
  raise ArgumentError, "Task cannot be blank" if task.blank?
  Resources::Task.parse(request(:put, "Tasks", task))
end