harvest-ruby-v2 0.4.0 → 0.5.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: 7fd54649aabcba944c8e02a7ea5ae6a972b9b87f2bd7ad455ba2da0ab164ae87
4
- data.tar.gz: 55357327dba37d0e8e50d5b7474d5a5b59f97e083849db987cf5fb38d5596418
3
+ metadata.gz: f341c06dfb732eeb0ab69f8a03d2d3a1d183c3afa1e200c14dba0cfe9e4bc81c
4
+ data.tar.gz: b10cb0684fb74ebb9a8e0dc87875b617a7b3c77af99ca5ed2dd75978c6fa7cf2
5
5
  SHA512:
6
- metadata.gz: 4cb412255cdeed5d49b080c9168bc6f01e8f6ca05c953069428fed942f49a092127c5fc428ca9eac001f34f5b27a9b76d185de414b9daba6c622a4c2977c9d96
7
- data.tar.gz: 5a08ac7e1e6025d43dc1b9e71f56bcf0964199c0c49a10cfb2247346e8a9c78301058b1181e7055b67212c63391d6614334b9431bd4de0517f3fe30c4812ba65
6
+ metadata.gz: bddbbd22c42beb25c7877adc7241b4d2feb61961c0f3ba61c5b774f34c9caf69a87239703a2e3eca0d7906a2b90e648b598492cc149c8d0752804d7f0bc58dd6
7
+ data.tar.gz: 8bdd8d98251fa443f0fbaf0b6665de237f64131aab1cc6d207c1305912f6891831bdd5eb8bf706e6d22696737209e9fccf158e8a9c3ba5625924254d5f8de086
@@ -0,0 +1,8 @@
1
+ ##########################
2
+ Changelog for harvest-ruby
3
+ ##########################
4
+
5
+ 0.5.0
6
+ ^^^^^
7
+
8
+ * Fixed bug with ApiCall which caused query params to not be passed to the underlying call.
data/Gemfile CHANGED
@@ -8,6 +8,7 @@ gemspec
8
8
  gem 'activesupport', '~> 6.0'
9
9
  gem 'configparser', '~> 0.1.7', group: :development
10
10
  gem 'pry', '~> 0.13.1', group: :development
11
+ gem 'pry-stack_explorer', '~> 0.5.1', group: :development
11
12
  gem 'rake', '~> 12.0', group: :development
12
13
  gem 'redcarpet', '~> 3.5', group: :development
13
14
  gem 'reek', '~> 6.0', group: :development
data/Rakefile CHANGED
@@ -9,6 +9,8 @@ RSpec::Core::RakeTask.new(:spec)
9
9
  RuboCop::RakeTask.new(:spec) do |rubocop|
10
10
  rubocop.options << '--auto-correct'
11
11
  rubocop.options << '--display-cop-names'
12
+ rubocop.options << '--extra-details'
13
+ rubocop.options << '--display-style-guide'
12
14
  end
13
15
 
14
16
  YARD::Rake::YardocTask.new do |t|
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'pry'
4
+ require 'pry-stack_explorer'
5
5
  require 'configparser'
6
6
  require 'date'
7
7
  require "bundler/setup"
@@ -39,14 +39,17 @@ module Harvest
39
39
  @client = Harvest::HTTP::Api.new(**@config)
40
40
  @factory = Harvest::ResourceFactory.new
41
41
  @state = state
42
- @active_user = @factory.user(@client.api_call(@client.api_caller('/users/me')))
43
- @admin_api = if @active_user.is_admin
42
+ @admin_api = if active_user.is_admin
44
43
  config.admin_api
45
44
  else
46
45
  false
47
46
  end
48
47
  end
49
48
 
49
+ def active_user
50
+ @state[:active_user] ||= @factory.user(@client.api_call(@client.api_caller('/users/me')))
51
+ end
52
+
50
53
  def allowed?(meth)
51
54
  %i[
52
55
  projects
@@ -93,7 +96,7 @@ module Harvest
93
96
 
94
97
  # Find single instance of resource
95
98
  def change(**kwargs)
96
- @state[@state[:active]].map do |_obj|
99
+ @state[@state[:active]].map do |obj|
97
100
  Harvest::Changers.const_get(to_class_name(@state[:active])).new.change(
98
101
  @factory, @client, active_user, @state, kwargs
99
102
  )
@@ -43,6 +43,9 @@ module Harvest
43
43
  paginator.path = 'time_entries'
44
44
  paginator.data_key = 'time_entries'
45
45
  paginator.param = params
46
+
47
+ # require 'pry'; binding.pry
48
+
46
49
  client.pagination(paginator).map do |time_entry|
47
50
  factory.time_entry(time_entry)
48
51
  end
@@ -71,7 +71,7 @@ module Harvest
71
71
 
72
72
  # Make a api call to an endpoint.
73
73
  # @api public
74
- # @param struct [Struct::ApiCall]
74
+ # @param struct [ApiCall]
75
75
  def api_call(struct)
76
76
  JSON.parse(
77
77
  send(struct.http_method.to_sym, struct).tap do
@@ -85,7 +85,9 @@ module Harvest
85
85
  # @param struct [Struct::Pagination]
86
86
  def pagination(struct)
87
87
  struct.param[:page] = struct.page_count
88
- page = api_call(struct.to_api_call)
88
+ page = api_call(struct.to_api_call).tap do
89
+ # require 'pry'; binding.pry
90
+ end
89
91
  struct.rows.concat(page[struct.data_key])
90
92
 
91
93
  return struct.rows if struct.page_count >= page['total_pages']
@@ -108,11 +110,11 @@ module Harvest
108
110
  end
109
111
 
110
112
  def api_caller(path, http_method: 'get', param: {}, payload: nil, headers: {})
111
- Struct::ApiCall.new(
113
+ ApiCall.new(
112
114
  {
113
115
  path: path,
114
116
  http_method: http_method.to_sym,
115
- param: param,
117
+ params: param,
116
118
  payload: payload,
117
119
  headers: headers
118
120
  }
@@ -138,17 +140,30 @@ module Harvest
138
140
  end
139
141
  end
140
142
 
141
- Struct.new(
142
- 'ApiCall',
143
- :path,
144
- :http_method,
145
- :param,
146
- :payload,
147
- :headers,
148
- keyword_init: true
149
- ) do
150
- def param(params)
151
- headers['params'] = params
143
+ class NoOptionProvided; end
144
+
145
+ class ApiCall
146
+ attr_accessor :path, :http_method, :payload, :headers
147
+
148
+ def initialize(path:, payload: {}, http_method: 'get', headers: {}, params: {})
149
+ @path = path
150
+ @http_method = http_method
151
+ @payload = payload
152
+ @headers = headers
153
+ param(params)
154
+ end
155
+
156
+ def param(params = NoOptionProvided)
157
+ if params == NoOptionProvided
158
+ @headers['params']
159
+ else
160
+ @headers['params'] = params
161
+ end
162
+ end
163
+
164
+ def param=(params)
165
+ param(params)
166
+ self
152
167
  end
153
168
  end
154
169
 
@@ -165,11 +180,11 @@ module Harvest
165
180
  keyword_init: true
166
181
  ) do
167
182
  def to_api_call
168
- Struct::ApiCall.new(
169
- {
183
+ ApiCall.new(
184
+ **{
170
185
  path: path,
171
186
  http_method: http_method,
172
- param: param,
187
+ params: param,
173
188
  payload: payload,
174
189
  headers: headers
175
190
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Harvest
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.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.4.0
4
+ version: 0.5.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-23 00:00:00.000000000 Z
11
+ date: 2020-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport