checkoff 0.157.0 → 0.158.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87c0b892ddeb1ba74e3d3903131b8c07178a53ab6f202eeaeb628e064b6b3b69
4
- data.tar.gz: 9d66bf594da9b4e50f177ad9d2ee86e29fd22daff64eaad423bb349148c58c91
3
+ metadata.gz: 3411417f4aa2d4585bbffe2abbe5d035e6c87df952f7db9c13b1c0233800f65a
4
+ data.tar.gz: 84a4da9aa7cb6d34d5e3af3677372f16b7377aa373486ddc5db34fc7b29bb7c6
5
5
  SHA512:
6
- metadata.gz: 191ea179fc32fc8b21a8d11db72659f5b365ea4346d8f529386c53aac0142f0a5cb8bf7a71d7e0f53b04ae61eda9d9515173fbf4e6e724c87c835084585fb1fe
7
- data.tar.gz: 215b4747ea847ed2522fbb849caa8b0a283c6069b345126dea90b0d04931640532fc0ac4dccc3b0ec9c3258e5c986abd5b60427237801837e325459537194173
6
+ metadata.gz: d58a2d975ea40a4de969af0149a84b118efdf36f24d0c9bae40203bb535d032fc8b4d2a912185392d4bd7280d1e356df19f521ad14b6f089cdcc8de281548658
7
+ data.tar.gz: 8d6f4e1c7a7d0d09fcc84e1eb1c0a72f4ab4ed9ba30bdddff89c9239e8e60e882a5377de31846bec7d7a7938a951b27e8a23817c84e518a04abb20041e1096bf
data/Gemfile.lock CHANGED
@@ -12,7 +12,7 @@ GIT
12
12
  PATH
13
13
  remote: .
14
14
  specs:
15
- checkoff (0.157.0)
15
+ checkoff (0.158.0)
16
16
  activesupport
17
17
  asana (> 0.10.0)
18
18
  cache_method
@@ -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, workspace_gid:, extra_fields: [], task_selector: [])
92
+ def raw_task_search(api_params,
93
+ workspace_gid:, extra_fields: [], task_selector: [],
94
+ fetch_all: true)
93
95
  # @sg-ignore
94
- path = "/workspaces/#{workspace_gid}/tasks/search"
95
- options = calculate_api_options(extra_fields)
96
- tasks = @asana_resources_collection_class.new(parse(client.get(path,
97
- params: api_params,
98
- options: options)),
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.length} raw tasks returned" }
103
+ debug { "#{tasks.count} raw tasks returned" }
104
+
105
+ return tasks if task_selector.empty?
109
106
 
110
- tasks.select { |task| task_selectors.filter_via_task_selector(task, task_selector) }
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_appt'],
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)
@@ -3,5 +3,5 @@
3
3
  # Command-line and gem client for Asana (unofficial)
4
4
  module Checkoff
5
5
  # Version of library
6
- VERSION = '0.157.0'
6
+ VERSION = '0.158.0'
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: checkoff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.157.0
4
+ version: 0.158.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vince Broz