harvest-ruby-v2 0.3.0 → 0.4.0

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: 35256e578fd37a80e3be93a7faaedf93bff246d771975832815bf81a80df8cb5
4
- data.tar.gz: b25edeb3ebf686a4ce9bc16247a8a24cfdbff88b2fa8c398453421b80f4f7351
3
+ metadata.gz: 7fd54649aabcba944c8e02a7ea5ae6a972b9b87f2bd7ad455ba2da0ab164ae87
4
+ data.tar.gz: 55357327dba37d0e8e50d5b7474d5a5b59f97e083849db987cf5fb38d5596418
5
5
  SHA512:
6
- metadata.gz: 328e1a8105435498c6766aa9f4922d0b167b828934f6ea54536a5b42f5873b46fd170aea2b5202838bb04f1ea22afa3bb43cd8a97c4c752f38b690c394dc1e04
7
- data.tar.gz: 25a1aac8da6040980549606b5afda8dfea1e2b58036f7274110d4597915c106620b5bd403470327ac04dfa55534ba86d4bb29530b54fd20395e1e2537732ee1e
6
+ metadata.gz: 4cb412255cdeed5d49b080c9168bc6f01e8f6ca05c953069428fed942f49a092127c5fc428ca9eac001f34f5b27a9b76d185de414b9daba6c622a4c2977c9d96
7
+ data.tar.gz: 5a08ac7e1e6025d43dc1b9e71f56bcf0964199c0c49a10cfb2247346e8a9c78301058b1181e7055b67212c63391d6614334b9431bd4de0517f3fe30c4812ba65
@@ -11,6 +11,7 @@ require 'harvest/exceptions'
11
11
  require 'harvest/finders'
12
12
  require 'harvest/discovers'
13
13
  require 'harvest/creates'
14
+ require 'harvest/changers'
14
15
 
15
16
  # Conform to naming pattern of Finder, Discover, Creators.
16
17
  # @param key [Symbol] symbol of state
@@ -78,7 +79,7 @@ module Harvest
78
79
  super
79
80
  end
80
81
  rescue NoMethodError
81
- # binding.pry
82
+ # require 'pry'; binding.pry
82
83
  raise Harvest::Exceptions::BadState, "#{meth} is an invalid state change."
83
84
  end
84
85
 
@@ -90,6 +91,16 @@ module Harvest
90
91
  self
91
92
  end
92
93
 
94
+ # Find single instance of resource
95
+ def change(**kwargs)
96
+ @state[@state[:active]].map do |_obj|
97
+ Harvest::Changers.const_get(to_class_name(@state[:active])).new.change(
98
+ @factory, @client, active_user, @state, kwargs
99
+ )
100
+ end
101
+ self
102
+ end
103
+
93
104
  # Discover resources
94
105
  def discover(**params)
95
106
  @state[@state[:active]] = Harvest::Discovers
@@ -101,6 +112,16 @@ module Harvest
101
112
  self
102
113
  end
103
114
 
115
+ # Create an instance of object based on state
116
+ def create(**kwargs)
117
+ @state[@state[:active]] = Harvest::Create.const_get(
118
+ to_class_name(@state[:active])
119
+ ).new.create(
120
+ @factory, @client, active_user, @state, kwargs
121
+ )
122
+ self
123
+ end
124
+
104
125
  # Select a subset of all items depending on state
105
126
  def select(&block)
106
127
  @state[@state[:active]] = @state[@state[:active]].select(&block)
@@ -116,15 +137,5 @@ module Harvest
116
137
  def data
117
138
  @state[@state[:active]]
118
139
  end
119
-
120
- # Create an instance of object based on state
121
- def create(**kwargs)
122
- @state[@state[:active]] = Harvest::Create.const_get(
123
- to_class_name(@state[:active])
124
- ).new.create(
125
- @factory, @client, active_user, @state, kwargs
126
- )
127
- self
128
- end
129
140
  end
130
141
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Harvest
4
+ module Changers
5
+ class TimeEntry
6
+ def change(factory, client, _active_user, state, kwargs)
7
+ # binding.pry
8
+ state[state[:active]].map do |te|
9
+ send(kwargs[:action].to_sym, factory, client, te)
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def restart(factory, client, te)
16
+ # PATCH /v2/time_entries/{TIME_ENTRY_ID}/restart
17
+ # binding.pry
18
+ [factory.time_entry(client.api_call(client.api_caller("time_entries/#{te.id}/restart", http_method: 'patch')))]
19
+ end
20
+
21
+ def stop(factory, client, te)
22
+ # PATCH /v2/time_entries/{TIME_ENTRY_ID}/stop
23
+ [factory.time_entry(client.api_call(client.api_caller("time_entries/#{te.id}/stop", http_method: 'patch')))]
24
+ end
25
+ end
26
+ end
27
+ end
@@ -34,8 +34,8 @@ module Harvest
34
34
 
35
35
  # @api private
36
36
  def time_entry_payload(kwargs)
37
- possible_keys = %i[spent_date notes external_reference user_id]
38
- payload = kwargs.map { |k, v| [k, v] if possible_keys.include?(k) }.to_h
37
+ possible_keys = %i[spent_date notes external_reference user_id project_id task_id]
38
+ payload = kwargs.each { |k, v| [k, v] if possible_keys.include?(k) }.to_h
39
39
  payload[:user_id] ||= @active_user.id
40
40
  payload[:task_id] = @state[:project_tasks][0].task.id
41
41
  payload[:project_id] = true_project(@state[:projects][0]).id
@@ -10,7 +10,7 @@ module Harvest
10
10
 
11
11
  class TimeEntry
12
12
  def find(factory, client, id)
13
- [factory.time_entry(client.api_call(client.api_caller("time_entry/#{id}")))]
13
+ [factory.time_entry(client.api_call(client.api_caller("time_entries/#{id}")))]
14
14
  end
15
15
  end
16
16
  end
@@ -75,8 +75,7 @@ module Harvest
75
75
  def api_call(struct)
76
76
  JSON.parse(
77
77
  send(struct.http_method.to_sym, struct).tap do
78
- require 'pry'
79
- # binding.pry
78
+ # require 'pry'; binding.pry
80
79
  end
81
80
  )
82
81
  end
@@ -126,9 +125,17 @@ module Harvest
126
125
  client[struct.path].get(struct.headers)
127
126
  end
128
127
 
128
+ def delete(struct)
129
+ client[struct.path].delete(struct.headers)
130
+ end
131
+
129
132
  def post(struct)
130
133
  client[struct.path].post(struct.payload, struct.headers)
131
134
  end
135
+
136
+ def patch(struct)
137
+ client[struct.path].patch(struct.payload, struct.headers)
138
+ end
132
139
  end
133
140
 
134
141
  Struct.new(
@@ -213,6 +213,11 @@ module Harvest
213
213
  data.method("#{key}=").call(DateTime.strptime(data.method(key).call))
214
214
  end
215
215
  end
216
+ %i[spent_date].each do |key|
217
+ if data.members.include?(key) && !data.method(key).call.nil?
218
+ data.method("#{key}=").call(Date.strptime(data.method(key).call))
219
+ end
220
+ end
216
221
  data
217
222
  end
218
223
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Harvest
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: harvest-ruby-v2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig Davis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-20 00:00:00.000000000 Z
11
+ date: 2020-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -61,6 +61,7 @@ files:
61
61
  - bin/setup
62
62
  - harvest-ruby-v2.gemspec
63
63
  - lib/harvest.rb
64
+ - lib/harvest/changers.rb
64
65
  - lib/harvest/client.rb
65
66
  - lib/harvest/config.rb
66
67
  - lib/harvest/creates.rb