Move to local toggl-portal to work around bug, also improve error handling and add the two missing sigs
This commit is contained in:
parent
5f6bd01882
commit
28c3fd27be
@ -1,13 +1,19 @@
|
||||
module Toggl
|
||||
def self.current_time_entry
|
||||
JSON.parse(HTTParty.get(
|
||||
response = HTTParty.get(
|
||||
"#{TOGGL_PORTAL_URL}/current",
|
||||
headers: { 'Accept' => 'application/json' }
|
||||
).body)
|
||||
)
|
||||
|
||||
if response.success?
|
||||
return JSON.parse(response.body)
|
||||
else
|
||||
raise "Error fetching current time entry: #{response.body}"
|
||||
end
|
||||
end
|
||||
|
||||
def self.entries_for_project(toggl_project_id, start_time:, end_time:)
|
||||
JSON.parse(HTTParty.post(
|
||||
response = HTTParty.post(
|
||||
"#{TOGGL_PORTAL_URL}/report",
|
||||
body: {
|
||||
"start_date": start_time.to_date.to_fs(),
|
||||
@ -15,11 +21,17 @@ module Toggl
|
||||
"project_ids": [toggl_project_id]
|
||||
}.to_json,
|
||||
headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
|
||||
).body)
|
||||
)
|
||||
|
||||
if response.success?
|
||||
return JSON.parse(response.body)
|
||||
else
|
||||
raise "Error fetching Toggl entries for project: #{response.body}"
|
||||
end
|
||||
end
|
||||
|
||||
def self.start_time_entry(description:, project_id:)
|
||||
HTTParty.post(
|
||||
response = HTTParty.post(
|
||||
"#{TOGGL_PORTAL_URL}/start_time_entry",
|
||||
body: {
|
||||
"created_with": "Attendance Tracker",
|
||||
@ -30,5 +42,7 @@ module Toggl
|
||||
}.to_json,
|
||||
headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
|
||||
)
|
||||
|
||||
raise "Error starting Toggl time entry: #{response.body}" unless response.success?
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
# TODO: Is there a better way to do this?
|
||||
TOGGL_PORTAL_URL = ENV['TOGGL_PORTAL_URL'] || 'http://cosmos:7001'
|
||||
TOGGL_PORTAL_URL = ENV['TOGGL_PORTAL_URL'] || 'http://localhost:3005' ||'http://cosmos:7001'
|
||||
PANOPTO_PORTAL_URL = ENV['PANOPTO_PORTAL_URL'] || 'https://lectures.joshuacoles.me'
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
module Toggl
|
||||
def self.entries_for_project: -> Array[untyped]
|
||||
|
||||
def self.current_time_entry: -> untyped
|
||||
|
||||
def self.start_time_entry: (description: string, project_id: int) -> void
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user