From 55b82e91f8ef470458afa67e6bb91af907e87fa7 Mon Sep 17 00:00:00 2001 From: Vittore Date: Fri, 11 Jun 2021 14:02:03 +0200 Subject: [PATCH 1/2] Update Toggl API endpoint --- README.rdoc | 2 +- app/models/toggl_api_service.rb | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.rdoc b/README.rdoc index 3ef22cd..1a45f6d 100644 --- a/README.rdoc +++ b/README.rdoc @@ -23,7 +23,7 @@ Then add the following line to your crontab (schedule may vary, of course): == How to use -First, go to your Redmine profile and set your Toggl API key. You can get one at https://www.toggl.com/user/edit. +First, go to your Redmine profile and set your Toggl API key. You can get one at https://track.toggl.com/profile. If you want to use only some of your Toggl workspaces, you can set them up in Redmine as a comma separated string. To fetch entries from all workspaces, just leave workspace setting empty. After that any entry in Toggl marked with a hash and a number goes to the corresponding task in your projects. For example, an entry "Going out with Sarah #1324" of 2.5 hours will add 2.5h to the issue #1324 with the "Going out with Sarah" comment. diff --git a/app/models/toggl_api_service.rb b/app/models/toggl_api_service.rb index 76cbf95..30d6a70 100644 --- a/app/models/toggl_api_service.rb +++ b/app/models/toggl_api_service.rb @@ -37,7 +37,8 @@ def get_toggl_entries protected def get_latest_toggl_entries_api_response(target) - uri = URI.parse "https://www.toggl.com/api/v8/#{target}" + # https://github.com/toggl/toggl_api_docs/blob/master/toggl_api.md + uri = URI.parse "https://api.track.toggl.com/api/v8/#{target}" uri.query = URI.encode_www_form({ :user_agent => 'Redmine Toggl Client' }) http = Net::HTTP.new(uri.host, uri.port) @@ -48,7 +49,7 @@ def get_latest_toggl_entries_api_response(target) req.basic_auth @toggl_api_key, 'api_token' res = http.request(req) - + if res.code.eql? "200" JSON.parse(res.body) else From fe96f39447e7233d5e96c0738d05e85fcc1e62e4 Mon Sep 17 00:00:00 2001 From: Viktor Sulak Date: Fri, 11 Jun 2021 14:36:17 +0200 Subject: [PATCH 2/2] Fix Rails 5.1 compatibility --- db/migrate/001_create_toggl_time_entries.rb | 2 +- db/migrate/002_create_api_key_field.rb | 6 +++--- db/migrate/003_set_api_key_not_visible.rb | 3 +-- db/migrate/004_create_workspace_field.rb | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/db/migrate/001_create_toggl_time_entries.rb b/db/migrate/001_create_toggl_time_entries.rb index af82890..84e2bc1 100644 --- a/db/migrate/001_create_toggl_time_entries.rb +++ b/db/migrate/001_create_toggl_time_entries.rb @@ -1,4 +1,4 @@ -class CreateTogglTimeEntries < ActiveRecord::Migration +class CreateTogglTimeEntries < Rails.version < '5.1' ? ActiveRecord::Migration : ActiveRecord::Migration[4.2] def change create_table :toggl_time_entries do |t| end diff --git a/db/migrate/002_create_api_key_field.rb b/db/migrate/002_create_api_key_field.rb index ea24b51..f15bb9a 100644 --- a/db/migrate/002_create_api_key_field.rb +++ b/db/migrate/002_create_api_key_field.rb @@ -1,4 +1,4 @@ -class CreateApiKeyField < ActiveRecord::Migration +class CreateApiKeyField < Rails.version < '5.1' ? ActiveRecord::Migration : ActiveRecord::Migration[4.2] def up custom_field = CustomField.new_subclass_instance('UserCustomField', { @@ -15,9 +15,9 @@ def up }) custom_field.save! end - + def down CustomField.find_by_name('Toggl API Key').destroy end -end \ No newline at end of file +end diff --git a/db/migrate/003_set_api_key_not_visible.rb b/db/migrate/003_set_api_key_not_visible.rb index d359ab9..8dd5255 100644 --- a/db/migrate/003_set_api_key_not_visible.rb +++ b/db/migrate/003_set_api_key_not_visible.rb @@ -1,4 +1,4 @@ -class SetApiKeyNotVisible < ActiveRecord::Migration +class SetApiKeyNotVisible < Rails.version < '5.1' ? ActiveRecord::Migration : ActiveRecord::Migration[4.2] def up custom_field = CustomField.find_by_name('Toggl API Key') @@ -13,4 +13,3 @@ def down end end - diff --git a/db/migrate/004_create_workspace_field.rb b/db/migrate/004_create_workspace_field.rb index 6f1b4eb..152006e 100644 --- a/db/migrate/004_create_workspace_field.rb +++ b/db/migrate/004_create_workspace_field.rb @@ -1,4 +1,4 @@ -class CreateWorkspaceField < ActiveRecord::Migration +class CreateWorkspaceField < Rails.version < '5.1' ? ActiveRecord::Migration : ActiveRecord::Migration[4.2] def up custom_field = CustomField.new_subclass_instance('UserCustomField', {