checkoff 0.53.0 → 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: 70e5f767656e34b2431a2920a57ade34d64480f53d95855818bd607400ae9e60
4
- data.tar.gz: 42b5dc27c71e1f0bb5772f00d8ae74947286f13e7bb319d9ae8ab2c8dbb06722
3
+ metadata.gz: 2a26bf5e53147ab791087492c23a9a050c6bdeef1d0edadba9a4d3d4741c32bf
4
+ data.tar.gz: 403940c20a3e08c11904192168fbd6d0df95b012cd17e025148a777223b0f30c
5
5
  SHA512:
6
- metadata.gz: 8327942085367d3501b77563121dab0935696550a46036da89f4662d59d5dd7acc9fa49930db08f3901a1468b05c5ab63a2f813ab56415c9f627887b585d8386
7
- data.tar.gz: 6046d32bfd28b7805771be9854843821d0d84c2da3e49eac3df3f44d839169b073117870a38e67659e4f3ca0356151bcbfc4eb2feabbb7a6ffc88efe7917673b
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.0)
15
+ checkoff (0.54.0)
16
16
  activesupport
17
17
  asana (> 0.10.0)
18
18
  cache_method
@@ -22,7 +22,7 @@ PATH
22
22
  GEM
23
23
  remote: https://rubygems.org/
24
24
  specs:
25
- activesupport (7.0.7.2)
25
+ activesupport (7.0.8)
26
26
  concurrent-ruby (~> 1.0, >= 1.0.2)
27
27
  i18n (>= 1.6, < 2)
28
28
  minitest (>= 5.1)
@@ -13,31 +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
- after = Time.at(due_date_after.to_i / 1000).to_date
40
- [{ 'due_on.after' => after.to_s }, []]
93
+ # +1 is because API seems to operate on inclusive ranges
94
+ # @type [Date]
95
+ # @sg-ignore
96
+ after = Time.at(after.to_i / 1000).to_date + 1
97
+ [{ "#{API_PREFIX.fetch(prefix)}.after" => after.to_s }, []]
41
98
  end
42
99
 
43
100
  # @param param_key [String]
@@ -52,37 +109,20 @@ module Checkoff
52
109
  value[0]
53
110
  end
54
111
 
55
- # @return [Array(Hash<String, String>, Array<[Symbol, Array]>)]
56
- def convert
57
- return [{}, []] if date_url_params.empty?
58
-
59
- # example params:
60
- # due_date.operator=through_next
61
- # due_date.value=0
62
- # due_date.unit=day
63
- due_date_operator = get_single_param('due_date.operator')
64
-
65
- return handle_through_next if due_date_operator == 'through_next'
66
-
67
- return handle_between if due_date_operator == 'between'
68
-
69
- raise "Teach me how to handle date mode: #{due_date_operator.inspect}."
70
- end
71
-
72
- private
73
-
112
+ # @param prefix [String]
74
113
  # @return [void]
75
- def validate_unit_not_provided!
76
- 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"
77
116
 
78
- 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}"
79
118
  end
80
119
 
120
+ # @param prefix [String]
81
121
  # @return [void]
82
- def validate_unit_is_day!
83
- 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)
84
124
 
85
- 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'
86
126
  end
87
127
 
88
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.0'
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.0
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-04 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