toggl_cache 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/HISTORY.md +4 -0
- data/VERSION +1 -1
- data/lib/toggl_cache.rb +15 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e83c9bbbb499c8115a5f60c5606c6ad9589af93
|
4
|
+
data.tar.gz: e09117cc40b710b0096fd83ad602b946e11dcb7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b721bf3650aaf6081615573f114838d07bc6cebbf6efd440afb4b8f2ddfffa78327600d6e002194fd1d0ad09c21dd3e5d6f24a6af8f05263e65c50b01419f02
|
7
|
+
data.tar.gz: cc31f8dad8f31396c37fc6758004df251703cc6653bcc8785b36be17b4f5c6979d67dc1b161e4bb91b214b345576876fb57fb2f8c686502a13a507ee8a1e6a4c
|
data/HISTORY.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/lib/toggl_cache.rb
CHANGED
@@ -33,7 +33,8 @@ module TogglCache
|
|
33
33
|
logger.info "Syncing reports from #{date_since} to #{date_until}."
|
34
34
|
clear_cache(
|
35
35
|
time_since: Time.parse("#{date_since} 00:00:00Z"),
|
36
|
-
time_until: Time.parse("#{date_until} 23:59:59Z")
|
36
|
+
time_until: Time.parse("#{date_until} 23:59:59Z"),
|
37
|
+
logger: logger
|
37
38
|
)
|
38
39
|
fetch_reports(
|
39
40
|
client: client,
|
@@ -48,7 +49,7 @@ module TogglCache
|
|
48
49
|
# report in the cache to now. Proceeds by comparing reports total
|
49
50
|
# duration from Toggl (using the Reports API) and the total contained
|
50
51
|
# in the cache. If a difference is detected, proceeds monthly and
|
51
|
-
# clear and reconstructs the cache for the
|
52
|
+
# clear and reconstructs the cache for the concerned month.
|
52
53
|
#
|
53
54
|
# TODO: enable detecting a change in project/task level aggregates.
|
54
55
|
def self.sync_check_and_fix(logger: default_logger)
|
@@ -77,8 +78,8 @@ module TogglCache
|
|
77
78
|
logger.info "Checked total for #{year}/#{month}: ✅ (#{month_toggl})"
|
78
79
|
else
|
79
80
|
logger.info "Checked total for #{year}/#{month}: ❌ (Toggl: #{month_toggl}, cache: #{month_cache})"
|
80
|
-
TogglCache.
|
81
|
-
TogglCache.sync_reports_for_month(year: year, month: month)
|
81
|
+
TogglCache.clear_cache_for_month(year: year, month: month, logger: logger)
|
82
|
+
TogglCache.sync_reports_for_month(year: year, month: month, logger: logger)
|
82
83
|
end
|
83
84
|
end
|
84
85
|
end
|
@@ -87,20 +88,22 @@ module TogglCache
|
|
87
88
|
# An easy-to-use method to sync reports for a given month. Simply
|
88
89
|
# performs a call to `sync_reports`.
|
89
90
|
#
|
90
|
-
# @param year [Integer]
|
91
|
-
# @param month [Integer
|
92
|
-
|
91
|
+
# @param year: [Integer]
|
92
|
+
# @param month: [Integer
|
93
|
+
# @param logger: [Logger] (optional)
|
94
|
+
def self.sync_reports_for_month(year:, month:, logger: default_logger)
|
93
95
|
date_since = Date.civil(year, month, 1)
|
94
96
|
date_until = Date.civil(year, month, -1)
|
95
97
|
sync_reports(
|
96
98
|
date_since: date_since,
|
97
|
-
date_until: date_until
|
99
|
+
date_until: date_until,
|
100
|
+
logger: logger
|
98
101
|
)
|
99
102
|
end
|
100
103
|
|
101
104
|
# Remove TogglCache's reports between the specified dates.
|
102
|
-
def self.clear_cache(time_since:, time_until:)
|
103
|
-
logger.info "Clearing cache from #{
|
105
|
+
def self.clear_cache(time_since:, time_until:, logger: default_logger)
|
106
|
+
logger.info "Clearing cache from #{time_since} to #{time_until}."
|
104
107
|
reports = Data::ReportRepository.new
|
105
108
|
reports.delete_starting(
|
106
109
|
time_since: time_since,
|
@@ -114,7 +117,8 @@ module TogglCache
|
|
114
117
|
date_until = Date.civil(year, month, -1)
|
115
118
|
clear_cache(
|
116
119
|
time_since: Time.parse("#{date_since} 00:00:00Z"),
|
117
|
-
time_until: Time.parse("#{date_until} 23:59:59Z")
|
120
|
+
time_until: Time.parse("#{date_until} 23:59:59Z"),
|
121
|
+
logger: logger
|
118
122
|
)
|
119
123
|
end
|
120
124
|
|