checkoff 0.157.0 → 0.159.0
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/Gemfile.lock +1 -1
- data/lib/checkoff/task_searches.rb +88 -16
- data/lib/checkoff/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ea1c2f4c9b1727b1f1ea960da4305dbcc170570726b7d072d672173e765a617
|
4
|
+
data.tar.gz: f6e47950aad4370f48548afda8f97ec4688c0c8b1f588cabad415ae8d92bcd43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c045f4a4fba06f9844082e269b902d738dbdadba318480a833e9e930b8092ae7b1178dbca94b8e10c8b39fbb9c3dbab4e8cf5d635bc324958db5d98f700f605e
|
7
|
+
data.tar.gz: 196b0fadb3f8c36ac722af7e2ce89bc498e0a6107da920b6370b2f1b19dd2a9e5556b3e34a0e238e79fb1bad404031753cf3e75ecfb14e4f1c9c92821e6b7f22
|
data/Gemfile.lock
CHANGED
@@ -84,30 +84,29 @@ module Checkoff
|
|
84
84
|
#
|
85
85
|
# @param [Hash<Symbol, Object>] api_params
|
86
86
|
# @param [String] workspace_gid
|
87
|
-
# @param [String] url
|
88
87
|
# @param [Array<String>] extra_fields
|
89
88
|
# @param [Array] task_selector
|
89
|
+
# @param [Boolean] fetch_all Ensure all results are provided by manually paginating
|
90
90
|
#
|
91
91
|
# @return [Enumerable<Asana::Resources::Task>]
|
92
|
-
def raw_task_search(api_params,
|
92
|
+
def raw_task_search(api_params,
|
93
|
+
workspace_gid:, extra_fields: [], task_selector: [],
|
94
|
+
fetch_all: true)
|
93
95
|
# @sg-ignore
|
94
|
-
|
95
|
-
|
96
|
-
tasks
|
97
|
-
|
98
|
-
|
99
|
-
type: Asana::Resources::Task,
|
100
|
-
client: client)
|
101
|
-
|
102
|
-
if tasks.length == 100
|
103
|
-
raise 'Too many results returned. ' \
|
104
|
-
'Please narrow your search in ways expressible through task search API: ' \
|
105
|
-
'https://developers.asana.com/reference/searchtasksforworkspace'
|
96
|
+
tasks = api_task_search_request(api_params, workspace_gid: workspace_gid, extra_fields: extra_fields)
|
97
|
+
|
98
|
+
if fetch_all && tasks.count == 100
|
99
|
+
# @sg-ignore
|
100
|
+
tasks = iterated_raw_task_search(api_params, workspace_gid: workspace_gid, extra_fields: extra_fields)
|
106
101
|
end
|
107
102
|
|
108
|
-
debug { "#{tasks.
|
103
|
+
debug { "#{tasks.count} raw tasks returned" }
|
104
|
+
|
105
|
+
return tasks if task_selector.empty?
|
109
106
|
|
110
|
-
tasks.select
|
107
|
+
tasks.select do |task|
|
108
|
+
task_selectors.filter_via_task_selector(task, task_selector)
|
109
|
+
end
|
111
110
|
end
|
112
111
|
|
113
112
|
# @return [Hash]
|
@@ -117,6 +116,79 @@ module Checkoff
|
|
117
116
|
|
118
117
|
private
|
119
118
|
|
119
|
+
# Perform a search using the Asana Task Search API:
|
120
|
+
#
|
121
|
+
# https://developers.asana.com/reference/searchtasksforworkspace
|
122
|
+
#
|
123
|
+
# @param [Hash<Symbol, Object>] api_params
|
124
|
+
# @param [String] workspace_gid
|
125
|
+
# @param [Array<String>] extra_fields
|
126
|
+
#
|
127
|
+
# @return [Enumerable<Asana::Resources::Task>]
|
128
|
+
def api_task_search_request(api_params, workspace_gid:, extra_fields:)
|
129
|
+
path = "/workspaces/#{workspace_gid}/tasks/search"
|
130
|
+
options = calculate_api_options(extra_fields)
|
131
|
+
@asana_resources_collection_class.new(parse(client.get(path,
|
132
|
+
params: api_params,
|
133
|
+
options: options)),
|
134
|
+
type: Asana::Resources::Task,
|
135
|
+
client: client)
|
136
|
+
end
|
137
|
+
|
138
|
+
# Perform a search using the Asana Task Search API and use manual pagination to
|
139
|
+
# ensure all results are returned:
|
140
|
+
#
|
141
|
+
# https://developers.asana.com/reference/searchtasksforworkspace
|
142
|
+
#
|
143
|
+
# "However, you can paginate manually by sorting the search
|
144
|
+
# results by their creation time and then modifying each
|
145
|
+
# subsequent query to exclude data you have already seen." -
|
146
|
+
# see sort_by field at
|
147
|
+
# https://developers.asana.com/reference/searchtasksforworkspace
|
148
|
+
#
|
149
|
+
# @param [Hash<Symbol, Object>] api_params
|
150
|
+
# @param [String] workspace_gid
|
151
|
+
# @param [String] url
|
152
|
+
# @param [Array<String>] extra_fields
|
153
|
+
# @param [Boolean] fetch_all Ensure all results are provided by manually paginating
|
154
|
+
#
|
155
|
+
# @return [Enumerable<Asana::Resources::Task>]
|
156
|
+
def iterated_raw_task_search(api_params, workspace_gid:, extra_fields:)
|
157
|
+
# https://developers.asana.com/reference/searchtasksforworkspace
|
158
|
+
tasks = []
|
159
|
+
new_api_params = api_params.dup
|
160
|
+
original_sort_by = new_api_params.delete('sort_by')
|
161
|
+
# defaults to false
|
162
|
+
original_sort_ascending = new_api_params.delete('sort_ascending')
|
163
|
+
original_created_at_before = new_api_params.delete('created_at.before')
|
164
|
+
raise 'Teach me how to handle original_created_at_before' unless original_created_at_before.nil?
|
165
|
+
|
166
|
+
new_api_params['sort_by'] = 'created_at'
|
167
|
+
|
168
|
+
Kernel.loop do
|
169
|
+
# Get the most recently created results, then iterate on until we're out of results
|
170
|
+
|
171
|
+
# @type [Array<Asana::Resources::Task>]
|
172
|
+
task_batch = raw_task_search(new_api_params,
|
173
|
+
workspace_gid: workspace_gid, extra_fields: extra_fields + ['created_at'],
|
174
|
+
fetch_all: false).to_a
|
175
|
+
oldest = task_batch.to_a.last
|
176
|
+
|
177
|
+
break if oldest.nil?
|
178
|
+
|
179
|
+
new_api_params['created_at.before'] = oldest.created_at
|
180
|
+
|
181
|
+
tasks.concat(task_batch.to_a)
|
182
|
+
end
|
183
|
+
unless original_sort_by.nil? || original_sort_by == 'created_at'
|
184
|
+
raise "Teach me how to handle original_sort_by: #{original_sort_by.inspect}"
|
185
|
+
end
|
186
|
+
|
187
|
+
raise 'Teach me how to handle original_sort_ascending' unless original_sort_ascending.nil?
|
188
|
+
|
189
|
+
tasks
|
190
|
+
end
|
191
|
+
|
120
192
|
# @param [Array<String>] extra_fields
|
121
193
|
# @return [Hash<Symbol, Object>]
|
122
194
|
def calculate_api_options(extra_fields)
|
data/lib/checkoff/version.rb
CHANGED