Class: ClickUp::Tasks::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/click_up/tasks/service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(list_id:, http_client:) ⇒ Service

Returns a new instance of Service.

Parameters:

  • list_id (Integer)
  • http_client (#get, #delete, #post, #put, #patch)

    any object implementing http requests



12
13
14
15
# File 'lib/click_up/tasks/service.rb', line 12

def initialize(list_id:, http_client:)
  @list_id = list_id
  @http_client = http_client
end

Instance Attribute Details

#list_idObject (readonly)

Returns the value of attribute list_id.



8
9
10
# File 'lib/click_up/tasks/service.rb', line 8

def list_id
  @list_id
end

Instance Method Details

#all(archived: false) ⇒ Array<ClickUp::Tasks::Task>

Parameters:

  • archived (Boolean) (defaults to: false)

    flag telling whether to fetch only achieved tasks or unarchived ones

Returns:



19
20
21
22
23
24
25
26
27
# File 'lib/click_up/tasks/service.rb', line 19

def all(archived: false)
  url = "list/#{@list_id}/task?archived=#{archived}"

  resp = @http_client.get(url)

  body = Oj.load(resp.body)
  tasks = body.fetch("tasks")
  ClickUp::Tasks::Factory.build_collection(tasks)
end

#create(attributes) ⇒ ClickUp::Tasks::Task

Parameters:

  • attributes (Hash)

Returns:



44
45
46
47
48
49
50
51
# File 'lib/click_up/tasks/service.rb', line 44

def create(attributes)
  url = "list/#{@list_id}/task"

  payload = Oj.dump(attributes, mode: :compat)
  resp = @http_client.post(url, payload, { "Content-Type" => "application/json" })

  Oj.load(resp.body).then { |task| Task.new(task) }
end

#delete(task_id) ⇒ Object

Parameters:

  • task_id (String)


38
39
40
# File 'lib/click_up/tasks/service.rb', line 38

def delete(task_id)
  @http_client.delete("task/#{task_id}")
end

#find(task_id) ⇒ ClickUp::Tasks::Task

Parameters:

  • task_id (String)

Returns:



31
32
33
34
35
# File 'lib/click_up/tasks/service.rb', line 31

def find(task_id)
  resp = @http_client.get("task/#{task_id}")

  Oj.load(resp.body).then { |task| Task.new(task) }
end

#update(task_id:, attributes:) ⇒ ClickUp::Tasks::Task

Parameters:

  • task_id (String)
  • attributes (Hash)

Returns:



56
57
58
59
60
61
62
63
# File 'lib/click_up/tasks/service.rb', line 56

def update(task_id:, attributes:)
  url = "task/#{task_id}"

  payload = Oj.dump(attributes, mode: :compat)
  resp = @http_client.put(url, payload, { "Content-Type" => "application/json" })

  Oj.load(resp.body).then { |task| Task.new(task) }
end