ncore 3.6.2 → 3.7.1

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: 72b21510020d16c3b3867166bd04a2a7f36a10e81e53f3fffafe6ff65dfd58c3
4
- data.tar.gz: 0abc02e39d688fd674fd6eabfc6f57de375b92ee6e037642ec80ab3dbc43345d
3
+ metadata.gz: 6c6562d9f0e6fca58cc5ad061d9461006dc509f92e960a55ed83bd127fd1d503
4
+ data.tar.gz: f61859177171d285d7442dfdee1a66964b318bb14824b7e409da2e3e27b92e0d
5
5
  SHA512:
6
- metadata.gz: 7602eb0f8a31448ea87b96c7d8838e91a1380e45b098fa0a8b7e44241c9bdf6b73330338083b20bbfec1e36c76104180a2681bb89cb7ac8493d1e0d676e2b165
7
- data.tar.gz: e8faccd4fe7495644f6f3c1abeb616f7d57b7cab32bcbf24a2a72eb7334b97de551f7ac690d28cd760b78abe22d37db362a8c47b1a80db24ef1fadffc25a471e
6
+ metadata.gz: 2b702ea0bc616e2aabbd685ac53579759e59176865e562f383aff61682f3cb6defc5aa177ec398a0a9b18229bd8f5a78d5fc5e390f61ce722998e5301bd7dfa1
7
+ data.tar.gz: e2ab8234b5fc0358ba38f2460065dfe029ee92d59d575dbb7f35c9d5b8edb71aff8d15fb0278a50678401a71bea55705eb12bda756e4c99295430d45ae16cbee
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ #### 3.7.1
2
+
3
+ - Don't send both mixed and lowercase headers for accept, user-agent
4
+
5
+ #### 3.7.0
6
+
7
+ - Allow request params to be or contain ActionController::Parameters
8
+ Unless MultiJson is present, this changes json generation to use the
9
+ configured encoder in ActiveSupport::JSON::Encoding.json_encoder instead
10
+ of directly using ::JSON.
11
+ - Change request header names to lowercase
12
+ - Log 404, 409, 422 responses at :debug instead of :error
13
+
14
+ #### 3.6.2
15
+
16
+ - Ensure cache key is stable
17
+
1
18
  #### 3.6.1
2
19
 
3
20
  - Restore usage of Resource.new(some_attr: 'value')
@@ -27,7 +27,7 @@ module MyApi
27
27
 
28
28
  self.status_page = 'http://my.api.status.page'
29
29
 
30
- self.auth_header_prefix = 'X-MyApi'
30
+ self.auth_header_prefix = 'x-myapi'
31
31
 
32
32
  # self.bearer_credential_key = :api_key
33
33
 
data/lib/ncore/builder.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module NCore
2
2
  module Builder
3
3
  extend ActiveSupport::Concern
4
-
4
+
5
5
  included do
6
6
  class_eval <<-INCL, __FILE__, __LINE__+1
7
7
  include NCore::Exceptions
@@ -24,7 +24,7 @@ module NCore
24
24
 
25
25
  class << self
26
26
  def configure(&block)
27
- Api.instance_eval &block
27
+ Api.instance_eval(&block)
28
28
  end
29
29
  end
30
30
  INCL
data/lib/ncore/client.rb CHANGED
@@ -26,15 +26,15 @@ module NCore
26
26
 
27
27
  path = URI.parse(url).path
28
28
  if [:get, :head, :delete].include? method
29
- qs = build_query_string params
29
+ qs = build_query_string params.as_json
30
30
  url += qs
31
31
  path += qs
32
32
  payload = nil
33
33
  else
34
34
  if defined? MultiJson
35
- payload = MultiJson.encode params
35
+ payload = MultiJson.encode params.as_json
36
36
  else
37
- payload = JSON.generate params
37
+ payload = params.to_json
38
38
  end
39
39
  end
40
40
 
@@ -79,7 +79,7 @@ module NCore
79
79
  h = {}
80
80
  [default_headers, auth_headers(req_credentials), headers].each do |set|
81
81
  set.each do |k,v|
82
- k = k.to_s.tr('_','-').gsub(%r{(^|-)\w}){$&.upcase}
82
+ k = k.to_s.tr('_','-').downcase
83
83
  h[k] = v.respond_to?(:call) ? v.call : v
84
84
  end
85
85
  end
@@ -118,7 +118,7 @@ module NCore
118
118
 
119
119
  # create a new excon client if necessary
120
120
  # keeps a pool of the last 10 urls
121
- # in almost all cases this will be more than enough
121
+ # in almost all cases this will be more than enough
122
122
  def excon_client(uri)
123
123
  u = URI.parse uri
124
124
  u.path = ''
@@ -138,6 +138,10 @@ module NCore
138
138
  end
139
139
  ex_opts = {
140
140
  connect_timeout: 10,
141
+ headers: {
142
+ 'accept' => '*/*',
143
+ 'user-agent' => "ncore/ruby v#{VERSION}",
144
+ },
141
145
  persistent: true
142
146
  }
143
147
  if verify_ssl_cert?
@@ -153,6 +157,7 @@ module NCore
153
157
  end
154
158
 
155
159
  def pool
160
+ # is actually fiber-local
156
161
  Thread.current[:ncore_pool] ||= {}
157
162
  end
158
163
 
@@ -171,7 +176,6 @@ module NCore
171
176
  response = nil
172
177
  begin
173
178
  ActiveSupport::Notifications.instrument(instrument_key, rest_opts) do
174
-
175
179
  connection = excon_client(rest_opts[:url])
176
180
  begin
177
181
  tries += 1
@@ -286,9 +290,9 @@ module NCore
286
290
  creds.inject({}) do |h,(k,v)|
287
291
  if v.present?
288
292
  if k == bearer_credential_key
289
- h["Authorization"] = "Bearer #{v}"
293
+ h['authorization'] = "Bearer #{v}"
290
294
  else
291
- h["#{auth_header_prefix}-#{k}"] = v
295
+ h["#{auth_header_prefix}-#{k}"] = v
292
296
  end
293
297
  end
294
298
  h
@@ -325,6 +329,7 @@ module NCore
325
329
 
326
330
  def debug_response(response)
327
331
  return unless logger.debug?
332
+ headers = response.headers.transform_keys(&:downcase)
328
333
  if defined? MultiJson
329
334
  json = MultiJson.load(response.body||'', symbolize_keys: false) rescue response.body
330
335
  else
@@ -332,8 +337,8 @@ module NCore
332
337
  end
333
338
  logger << <<~DBG
334
339
  RESPONSE:
335
- #{response.headers['Status']} | #{response.headers['Content-Type']} | #{response.body.size} bytes
336
- #{response.headers.except('Status', 'Connection', 'Content-Type').map{|h,d| "#{h}: #{d}"}.join("\n ")}
340
+ #{response.status} | #{headers['content-type']} | #{response.body.size} bytes
341
+ #{headers.except('status', 'connection', 'content-length', 'content-type').map{|h,d| "#{h}: #{d}"}.join("\n ")}
337
342
  #{json.pretty_inspect.split("\n").join("\n ")}
338
343
  #{'-=- '*18}
339
344
  DBG
@@ -37,7 +37,7 @@ module NCore
37
37
 
38
38
 
39
39
  def request_cache_key(url:, headers:)
40
- hdrs = headers.reject{|k,v| k=='X-Request-Id'}.sort
40
+ hdrs = headers.reject{|k,v| k=='x-request-id'}.sort
41
41
  [ 'ncore',
42
42
  url.gsub(/[^a-zA-Z0-9]+/,'-'),
43
43
  Digest::MD5.hexdigest(hdrs.to_s)
@@ -38,7 +38,7 @@ module NCore
38
38
  self.status_page = 'the status page'
39
39
 
40
40
  mattr_accessor :auth_header_prefix
41
- self.auth_header_prefix = 'X-Api'
41
+ self.auth_header_prefix = 'x-api'
42
42
 
43
43
  mattr_reader :bearer_credential_key
44
44
  class_eval <<-MTH
@@ -7,7 +7,7 @@ module NCore
7
7
  raise(module_parent::RecordNotFound, "ids must not be empty") if ids.blank?
8
8
  params[:ids] = ids
9
9
  params = parse_request_params(params)
10
- parsed, creds = request(:delete, resource_path, params)
10
+ parsed, _creds = request(:delete, resource_path, params)
11
11
  if parsed[:errors].any?
12
12
  raise module_parent::BulkActionError, parsed[:errors]
13
13
  else
@@ -7,7 +7,7 @@ module NCore
7
7
  raise(module_parent::RecordNotFound, "ids must not be empty") if ids.blank?
8
8
  params = parse_request_params(params, json_root: json_root)
9
9
  params[:ids] = ids
10
- parsed, creds = request(:put, resource_path, params)
10
+ parsed, _creds = request(:put, resource_path, params)
11
11
  if parsed[:errors].any?
12
12
  raise module_parent::BulkActionError, parsed[:errors]
13
13
  else
@@ -26,6 +26,8 @@ module NCore
26
26
  end
27
27
  end
28
28
 
29
+ DEBUG_STATUSES = (200..299).to_a + [404, 409, 422]
30
+
29
31
  def log_request(event)
30
32
  self.class.runtime += event.duration
31
33
 
@@ -45,7 +47,7 @@ module NCore
45
47
  res = color(res, :red, bold: true)
46
48
  end
47
49
 
48
- if (200..299).include? http_status
50
+ if DEBUG_STATUSES.include? http_status
49
51
  debug " #{msg}"
50
52
  debug " #{res}"
51
53
  else
data/lib/ncore/util.rb CHANGED
@@ -53,7 +53,7 @@ module NCore
53
53
  klass_name = key.to_s.camelize.singularize
54
54
  begin
55
55
  "#{module_name}::#{klass_name}".constantize
56
- rescue NameError => e
56
+ rescue NameError
57
57
  default_klass
58
58
  end
59
59
  end
data/lib/ncore/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module NCore
2
- VERSION = '3.6.2'
2
+ VERSION = '3.7.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ncore
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.2
4
+ version: 3.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Notioneer Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-09 00:00:00.000000000 Z
11
+ date: 2023-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel