Class: Afterlife::Clickup::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/afterlife/clickup/api.rb

Constant Summary collapse

BASE_URL =
'https://api.clickup.com'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token:) ⇒ Api

Returns a new instance of Api.



11
12
13
14
15
16
17
18
19
20
# File 'lib/afterlife/clickup/api.rb', line 11

def initialize(token:)
  @connection = Faraday.new(
    url: BASE_URL,
    headers: { 'Content-Type' => 'application/json', 'Authorization' => token },
  ) do |faraday|
    faraday.request :json # encode request bodies as JSON
    faraday.response :json # decode response bodies as JSON
    faraday.response :raise_error # raise an error if the response is not successful
  end
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



9
10
11
# File 'lib/afterlife/clickup/api.rb', line 9

def connection
  @connection
end

Instance Method Details

#get_task(task_id) ⇒ Object



22
23
24
25
26
# File 'lib/afterlife/clickup/api.rb', line 22

def get_task(task_id)
  connection.get("/api/v2/task/#{task_id}").body
rescue Faraday::Error
  nil
end

#update_task(task_id, params) ⇒ Object



28
29
30
31
32
33
# File 'lib/afterlife/clickup/api.rb', line 28

def update_task(task_id, params)
  connection.put("/api/v2/task/#{task_id}", params).body
rescue Faraday::Error => e
  puts "Error updating task #{task_id}: #{e.message}"
  nil
end