harvest-ruby-v2 0.3.4 → 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: '0481299c43502e489ab013be74fe6ae6fa563f1997662b1df2cf1f091d197709'
4
- data.tar.gz: f99eda5308acbba9efd5c574ce60518dc3681edb2ab223253de0f3eca8592dec
3
+ metadata.gz: 7fd54649aabcba944c8e02a7ea5ae6a972b9b87f2bd7ad455ba2da0ab164ae87
4
+ data.tar.gz: 55357327dba37d0e8e50d5b7474d5a5b59f97e083849db987cf5fb38d5596418
5
5
  SHA512:
6
- metadata.gz: c1ad1076b5315860c0995f359099b9aedb8e720709584f0ed825ac2fedb325aa6ae08d17783da7660c08adc901becea8b64a9ea13c65bad380010f2e7dae77e0
7
- data.tar.gz: de22f15ab703b41ff0a5188562fe19f04a84cc6982170c4a641565a54e3c81bea67b0dc28e993552097518898c9e81451480b4ad26bd813cdab57c6f62237e5d
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
@@ -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
@@ -125,9 +125,17 @@ module Harvest
125
125
  client[struct.path].get(struct.headers)
126
126
  end
127
127
 
128
+ def delete(struct)
129
+ client[struct.path].delete(struct.headers)
130
+ end
131
+
128
132
  def post(struct)
129
133
  client[struct.path].post(struct.payload, struct.headers)
130
134
  end
135
+
136
+ def patch(struct)
137
+ client[struct.path].patch(struct.payload, struct.headers)
138
+ end
131
139
  end
132
140
 
133
141
  Struct.new(
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Harvest
4
- VERSION = '0.3.4'
4
+ VERSION = '0.4.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: harvest-ruby-v2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig Davis
@@ -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