Class: ClickUp::Tasks::Service
- Inherits:
-
Object
- Object
- ClickUp::Tasks::Service
- Defined in:
- lib/click_up/tasks/service.rb
Instance Attribute Summary collapse
-
#list_id ⇒ Object
readonly
Returns the value of attribute list_id.
Instance Method Summary collapse
- #all(archived: false) ⇒ Array<ClickUp::Tasks::Task>
- #create(attributes) ⇒ ClickUp::Tasks::Task
- #delete(task_id) ⇒ Object
- #find(task_id) ⇒ ClickUp::Tasks::Task
-
#initialize(list_id:, http_client:) ⇒ Service
constructor
A new instance of Service.
- #update(task_id:, attributes:) ⇒ ClickUp::Tasks::Task
Constructor Details
#initialize(list_id:, http_client:) ⇒ Service
Returns a new instance of Service.
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_id ⇒ Object (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>
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
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
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
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
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 |