active_collab-ruby-sdk 0.3.2 → 0.3.3
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/lib/active_collab/tasks.rb +23 -15
- data/lib/active_collab/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: a6e17e753d8da98b0e24d093fc9256b751a4030dddca75fc896ebe3177aeb103
|
|
4
|
+
data.tar.gz: d744024765c2181eb5f0e6b8f4e22e0c5b440893bdf73795085d94ff20da88b3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 26ca19d4bf4f16dff4b5b3f8ef9c9cec2d5402f899cd9d8112a78b9ada767aee51b9a7a92d865bd6cbcf3d724a3fecc6e240c882638c9e940322fdfabb73f177
|
|
7
|
+
data.tar.gz: 6b2d69c5e712a78c7c2e0475370bb106edff53aa02e98c5df46479d782f07de574bf71dd4be42b952301250e208cd0da78377d33ad6e17a6b8c804e853153e78
|
data/lib/active_collab/tasks.rb
CHANGED
|
@@ -12,18 +12,17 @@ class ActiveCollab::Tasks
|
|
|
12
12
|
# Returns all tasks (active + archived), sorted by created_on descending.
|
|
13
13
|
#
|
|
14
14
|
# @param params [Hash] query parameters
|
|
15
|
-
# @option params [String]
|
|
15
|
+
# @option params [String] :format response format ('hash' or 'json')
|
|
16
16
|
# @return [Hash, String] a hash with a 'tasks' key, or JSON string
|
|
17
17
|
def all(params = {})
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
params = params.transform_keys(&:to_sym)
|
|
19
|
+
temp_params = params.merge(format: 'hash')
|
|
20
|
+
all_tasks = active(temp_params)['tasks'] + archived(temp_params)['tasks']
|
|
20
21
|
result = {
|
|
21
|
-
'tasks' => all_tasks
|
|
22
|
-
.flatten
|
|
23
|
-
.sort_by { |t| -t['created_on'] } || []
|
|
22
|
+
'tasks' => all_tasks.sort_by { |t| -t['created_on'] }
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
return JSON.generate(result) if params[
|
|
25
|
+
return JSON.generate(result) if params[:format] == 'json'
|
|
27
26
|
result
|
|
28
27
|
end
|
|
29
28
|
|
|
@@ -41,24 +40,33 @@ class ActiveCollab::Tasks
|
|
|
41
40
|
# Auto-paginates through all pages unless a specific page is requested.
|
|
42
41
|
#
|
|
43
42
|
# @param params [Hash] query parameters
|
|
44
|
-
# @option params [Integer]
|
|
45
|
-
# @option params [String]
|
|
43
|
+
# @option params [Integer] :page specific page to fetch (disables auto-pagination)
|
|
44
|
+
# @option params [String] :format response format ('hash' or 'json')
|
|
46
45
|
# @return [Hash, String] a hash with a 'tasks' key, or JSON string
|
|
47
46
|
def archived(params = {})
|
|
48
|
-
|
|
47
|
+
params = params.transform_keys(&:to_sym)
|
|
48
|
+
page = params[:page] || 1
|
|
49
49
|
all_tasks = []
|
|
50
50
|
|
|
51
51
|
loop do
|
|
52
52
|
response = @client
|
|
53
|
-
.get("/projects/#{@project_id}/tasks/archive", params.merge(
|
|
54
|
-
|
|
53
|
+
.get("/projects/#{@project_id}/tasks/archive", params.merge(page: page))
|
|
54
|
+
|
|
55
|
+
tasks = if response.is_a?(Hash)
|
|
56
|
+
Array(response['tasks'])
|
|
57
|
+
elsif response.is_a?(Array)
|
|
58
|
+
response
|
|
59
|
+
else
|
|
60
|
+
[]
|
|
61
|
+
end
|
|
62
|
+
|
|
55
63
|
all_tasks += tasks
|
|
56
|
-
break if tasks.empty? || params.key?(
|
|
64
|
+
break if tasks.empty? || params.key?(:page)
|
|
57
65
|
page += 1
|
|
58
66
|
end
|
|
59
67
|
|
|
60
|
-
result = { 'tasks' => all_tasks.
|
|
61
|
-
return JSON.generate(result) if params[
|
|
68
|
+
result = { 'tasks' => all_tasks.sort_by { |t| -t['created_on'] } }
|
|
69
|
+
return JSON.generate(result) if params[:format] == 'json'
|
|
62
70
|
result
|
|
63
71
|
end
|
|
64
72
|
|