checkoff 0.53.1 → 0.54.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: 234864e30843bb30b598e38ef8e2571a6b5f6bbf37f07db7af5d4249ffe8ada2
4
- data.tar.gz: 4e2eef390cc3fca5a3022a816811acadfc710983ec96f288567d6892f7d08e22
3
+ metadata.gz: 2a26bf5e53147ab791087492c23a9a050c6bdeef1d0edadba9a4d3d4741c32bf
4
+ data.tar.gz: 403940c20a3e08c11904192168fbd6d0df95b012cd17e025148a777223b0f30c
5
5
  SHA512:
6
- metadata.gz: b035b186ac2b3fd74507020d165aa4b50c1c95d1a5848cbae0f579013dbf4fd6c6b0a3f648b00901544c525924ea7596009446777bb91db3ca5412fad6448136
7
- data.tar.gz: c35c867d9aaac72f54355fb371ea298afb55ccf9502d6baca0f2bc928ca4a0896a3bd5c784c052a6f566852933fbac88dd51a2d0764e4940edd132b5d21f5c8d
6
+ metadata.gz: a5421aa9a82b335176e2cd98e0bba600acbaa61cc5e8c45fd876c13eeb5d2d1d750740f56a92cf8f556d79faf7b8ac162452d7ff6d30dff9719df5ffeba4930f
7
+ data.tar.gz: 8dd35cf8d9009cb1bf76fd0b662a0d5bbde874a25c7cad914424131dc8d5e508ce0e39f0c2ba690b2ff3936bda3076ea9b6ec1eff6416ea032cd24bb0b10da59
data/Gemfile.lock CHANGED
@@ -12,7 +12,7 @@ GIT
12
12
  PATH
13
13
  remote: .
14
14
  specs:
15
- checkoff (0.53.1)
15
+ checkoff (0.54.0)
16
16
  activesupport
17
17
  asana (> 0.10.0)
18
18
  cache_method
@@ -13,34 +13,88 @@ module Checkoff
13
13
  @date_url_params = date_url_params
14
14
  end
15
15
 
16
+ # @sg-ignore
17
+ # @return [Array(Hash<String, String>, Array<[Symbol, Array]>)]
18
+ def convert
19
+ return [{}, []] if date_url_params.empty?
20
+
21
+ out = nil
22
+
23
+ %w[due_date start_date].each do |prefix|
24
+ next unless date_url_params.key? "#{prefix}.operator"
25
+ raise 'Teach me how to handle simultaneous date parameters' unless out.nil?
26
+
27
+ out = convert_for_prefix(prefix)
28
+ end
29
+
30
+ raise "Teach me to handle these parameters: #{date_url_params.inspect}" unless date_url_params.empty?
31
+
32
+ out
33
+ end
34
+
35
+ private
36
+
37
+ # @sg-ignore
38
+ # @param prefix [String]
39
+ # @return [Array(Hash<String, String>, Array<[Symbol, Array]>)]
40
+ def convert_for_prefix(prefix)
41
+ # example params:
42
+ # due_date.operator=through_next
43
+ # due_date.value=0
44
+ # due_date.unit=day
45
+ operator = get_single_param("#{prefix}.operator")
46
+
47
+ out = if operator == 'through_next'
48
+ handle_through_next(prefix)
49
+ elsif operator == 'between'
50
+ handle_between(prefix)
51
+ else
52
+ raise "Teach me how to handle date mode: #{operator.inspect}."
53
+ end
54
+
55
+ # mark these as done by deleting from the hash
56
+ date_url_params.delete_if { |k, _| k.start_with? prefix }
57
+
58
+ out
59
+ end
60
+
61
+ # https://developers.asana.com/docs/search-tasks-in-a-workspace
62
+ API_PREFIX = {
63
+ 'due_date' => 'due_on',
64
+ 'start_date' => 'start_on',
65
+ }.freeze
66
+
67
+ # @param prefix [String]
16
68
  # @return [Array(Hash<String, String>, Array<[Symbol, Array]>)] See https://developers.asana.com/docs/search-tasks-in-a-workspace
17
- def handle_through_next
18
- due_date_value = get_single_param('due_date.value').to_i
69
+ def handle_through_next(prefix)
70
+ value = get_single_param("#{prefix}.value").to_i
19
71
 
20
- validate_unit_is_day!
72
+ validate_unit_is_day!(prefix)
21
73
 
22
74
  # @sg-ignore
23
75
  # @type [Date]
24
- before = Date.today + due_date_value
76
+ before = Date.today + value
77
+
25
78
  # 'due_on.before' => '2023-01-01',
26
79
  # 'due_on.after' => '2023-01-01',
27
80
  # [{ 'due_on.before' => '2023-09-01' }, []]
28
- [{ 'due_on.before' => before.to_s }, []]
81
+ [{ "#{API_PREFIX.fetch(prefix)}.before" => before.to_s }, []]
29
82
  end
30
83
 
84
+ # @param prefix [String]
31
85
  # @return [Array(Hash<String, String>, Array<[Symbol, Array]>)] See https://developers.asana.com/docs/search-tasks-in-a-workspace
32
- def handle_between
33
- due_date_after = get_single_param('due_date.after')
34
- raise 'Teach me how to handle due_date_before' if date_url_params.key? 'due_date.before'
86
+ def handle_between(prefix)
87
+ after = get_single_param("#{prefix}.after")
88
+ raise "Teach me how to handle #{prefix}.before" if date_url_params.key? "#{prefix}.before"
35
89
 
36
- validate_unit_not_provided!
90
+ validate_unit_not_provided!(prefix)
37
91
 
38
92
  # Example value: 1702857600000
39
93
  # +1 is because API seems to operate on inclusive ranges
40
94
  # @type [Date]
41
95
  # @sg-ignore
42
- after = Time.at(due_date_after.to_i / 1000).to_date + 1
43
- [{ 'due_on.after' => after.to_s }, []]
96
+ after = Time.at(after.to_i / 1000).to_date + 1
97
+ [{ "#{API_PREFIX.fetch(prefix)}.after" => after.to_s }, []]
44
98
  end
45
99
 
46
100
  # @param param_key [String]
@@ -55,37 +109,20 @@ module Checkoff
55
109
  value[0]
56
110
  end
57
111
 
58
- # @return [Array(Hash<String, String>, Array<[Symbol, Array]>)]
59
- def convert
60
- return [{}, []] if date_url_params.empty?
61
-
62
- # example params:
63
- # due_date.operator=through_next
64
- # due_date.value=0
65
- # due_date.unit=day
66
- due_date_operator = get_single_param('due_date.operator')
67
-
68
- return handle_through_next if due_date_operator == 'through_next'
69
-
70
- return handle_between if due_date_operator == 'between'
71
-
72
- raise "Teach me how to handle date mode: #{due_date_operator.inspect}."
73
- end
74
-
75
- private
76
-
112
+ # @param prefix [String]
77
113
  # @return [void]
78
- def validate_unit_not_provided!
79
- return unless date_url_params.key? 'due_date.unit'
114
+ def validate_unit_not_provided!(prefix)
115
+ return unless date_url_params.key? "#{prefix}.unit"
80
116
 
81
- raise "Teach me how to handle other due_date.unit for these params: #{date_url_params.inspect}"
117
+ raise "Teach me how to handle other #{prefix}.unit for these params: #{date_url_params.inspect}"
82
118
  end
83
119
 
120
+ # @param prefix [String]
84
121
  # @return [void]
85
- def validate_unit_is_day!
86
- unit = date_url_params.fetch('due_date.unit').fetch(0)
122
+ def validate_unit_is_day!(prefix)
123
+ unit = date_url_params.fetch("#{prefix}.unit").fetch(0)
87
124
 
88
- raise 'Teach me how to handle other time units' unless unit == 'day'
125
+ raise "Teach me how to handle other time units: #{unit}" unless unit == 'day'
89
126
  end
90
127
 
91
128
  # @return [Hash<String, Array<String>>]
@@ -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.53.1'
6
+ VERSION = '0.54.0'
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: checkoff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.53.1
4
+ version: 0.54.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vince Broz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-12 00:00:00.000000000 Z
11
+ date: 2023-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport