Skip to content

refs #63197: Update for Toggle API v9. #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: 5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/models/toggl_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ def load_time_entries(
raise ArgumentError, 'Workspace ID must be a valid integer'
end

raw_entries = get('/api/v8/time_entries', { start_date: start_date.iso8601, end_date: end_date.iso8601 })
raw_entries = get('/api/v9/me/time_entries', { start_date: start_date.iso8601, end_date: end_date.iso8601 })

# The workspace filter is only supported on certain versions of the
# Toggl API. Thus, it is easier to filter out such records ourselves.
raw_entries = raw_entries.keep_if { |r| workspace_id == r['wid'] } if workspace_id
raw_entries = raw_entries.keep_if { |r| workspace_id == r['wid'] } if workspace_id > 0
raw_entries.map { |e| TogglTimeEntry.new(e.symbolize_keys) }
end

# Loads workspaces from Toggl.
def load_workspaces
get('/api/v8/workspaces')
get('/api/v9/workspaces')
.map { |w| TogglWorkspace.new(w.symbolize_keys) }
end

Expand Down
30 changes: 16 additions & 14 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@

Rails.configuration.to_prepare do
require_relative 'lib/toggl_2_redmine'
end

Redmine::Plugin.register :toggl2redmine do
# Package info.
name 'Toggl 2 Redmine'
author 'Jigarius'
description 'Imports time entries from Toggl into Redmine.'
version Toggl2Redmine::VERSION
url 'https://github.com/jigarius/toggl2redmine'
author_url 'https://jigarius.com/'
Redmine::Plugin.register :toggl2redmine do
# Package info.
name 'Toggl 2 Redmine'
author 'Jigarius'
description 'Imports time entries from Toggl into Redmine.'
version Toggl2Redmine::VERSION
url 'https://github.com/jigarius/toggl2redmine'
author_url 'https://jigarius.com/'

# Menu items.
menu :application_menu,
:toggl2redmine,
{ controller: 't2r_import', action: 'index' },
caption: 'Toggl'
end
# Menu items.
menu :application_menu,
:toggl2redmine,
{ controller: 't2r_import', action: 'index' },
caption: 'Toggl'
end

Rails.configuration.to_prepare do
# Patches.
require_relative 'lib/patches/time_entry'
end
14 changes: 0 additions & 14 deletions lib/patches/time_entry.rb

This file was deleted.

16 changes: 16 additions & 0 deletions lib/toggl_2_redmine/patches/time_entry_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module Toggl2Redmine
module Patches
# Patch Redmine's TimeEntry model.
module TimeEntryPatch
def self.included(base)
base.class_eval do
has_many :toggl_mappings, dependent: :destroy
end
end
end
end
end

TimeEntry.include Toggl2Redmine::Patches::TimeEntryPatch