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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 618cfa962f35bcae3a41e437b9aac7d77ae528f535f452355146ccacdb56885d
4
- data.tar.gz: 3f370da2a5aeba7923bdc7cb44531a7c9d5f21eec0ded03bf4312194a0e2c6db
3
+ metadata.gz: a6e17e753d8da98b0e24d093fc9256b751a4030dddca75fc896ebe3177aeb103
4
+ data.tar.gz: d744024765c2181eb5f0e6b8f4e22e0c5b440893bdf73795085d94ff20da88b3
5
5
  SHA512:
6
- metadata.gz: 47597a3f5889d9abbb95699b3f1dffbe9a231c4eb28112b707af2fe0e9e9a06d56cefa88c1d87d00d52ed5d095fb4bc21694ea7f063996b0279fb7d8ff0dffef
7
- data.tar.gz: f23a36519466b76297966bf02f319235113a76d7a3450612f8e4f8c00cd9fd9a40ef41970f4d1198c54cb56b9f109600450e9185a4ca70e1b1c6009db81ddf81
6
+ metadata.gz: 26ca19d4bf4f16dff4b5b3f8ef9c9cec2d5402f899cd9d8112a78b9ada767aee51b9a7a92d865bd6cbcf3d724a3fecc6e240c882638c9e940322fdfabb73f177
7
+ data.tar.gz: 6b2d69c5e712a78c7c2e0475370bb106edff53aa02e98c5df46479d782f07de574bf71dd4be42b952301250e208cd0da78377d33ad6e17a6b8c804e853153e78
@@ -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] 'format' response format ('hash' or 'json')
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
- temp_params = params.merge('format' => 'hash')
19
- all_tasks = [active(temp_params)['tasks'] + archived(temp_params)['tasks']]
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['format'] == 'json'
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] 'page' specific page to fetch (disables auto-pagination)
45
- # @option params [String] 'format' response format ('hash' or 'json')
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
- page = params['page'] || 1
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('page' => page))
54
- tasks = response || []
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?('page')
64
+ break if tasks.empty? || params.key?(:page)
57
65
  page += 1
58
66
  end
59
67
 
60
- result = { 'tasks' => all_tasks.flatten.sort_by { |t| -t['created_on'] } }
61
- return JSON.generate(result) if params['format'] == 'json'
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveCollab
4
- VERSION = '0.3.2'
4
+ VERSION = '0.3.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_collab-ruby-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Lens