ncore 3.6.2 → 3.7.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: 72b21510020d16c3b3867166bd04a2a7f36a10e81e53f3fffafe6ff65dfd58c3
4
- data.tar.gz: 0abc02e39d688fd674fd6eabfc6f57de375b92ee6e037642ec80ab3dbc43345d
3
+ metadata.gz: d88aebda2989bb9112e2e0a6a90a0eb4fb6224db0563560df03fa70f602dc03d
4
+ data.tar.gz: e1933d625a8771f26a6697ad3d4d1bd34cc63c67ae69b07516b935d25389c55b
5
5
  SHA512:
6
- metadata.gz: 7602eb0f8a31448ea87b96c7d8838e91a1380e45b098fa0a8b7e44241c9bdf6b73330338083b20bbfec1e36c76104180a2681bb89cb7ac8493d1e0d676e2b165
7
- data.tar.gz: e8faccd4fe7495644f6f3c1abeb616f7d57b7cab32bcbf24a2a72eb7334b97de551f7ac690d28cd760b78abe22d37db362a8c47b1a80db24ef1fadffc25a471e
6
+ metadata.gz: 29288f675a0ba7efe0a79ece9235bb793258c216a48f3874a0129aa089e4fe59eb82572aaf04a9a4810f6bd57d9bcc98b3abab00d516f3c3511ecd0edf73de07
7
+ data.tar.gz: 610ae4cdf2d632b06a4938f22c2f95dd7c2904ae9a98a12b721f6113fa99b0e67125c85fd973a346e3d128121e3f7a4324a204acf987e38a2873ede293462286
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ #### 3.7.0
2
+
3
+ - Allow request params to be or contain ActionController::Parameters
4
+ Unless MultiJson is present, this changes json generation to use the
5
+ configured encoder in ActiveSupport::JSON::Encoding.json_encoder instead
6
+ of directly using ::JSON.
7
+ - Change request header names to lowercase
8
+ - Log 404, 409, 422 responses at :debug instead of :error
9
+
10
+ #### 3.6.2
11
+
12
+ - Ensure cache key is stable
13
+
1
14
  #### 3.6.1
2
15
 
3
16
  - 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 = ''
@@ -153,6 +153,7 @@ module NCore
153
153
  end
154
154
 
155
155
  def pool
156
+ # is actually fiber-local
156
157
  Thread.current[:ncore_pool] ||= {}
157
158
  end
158
159
 
@@ -171,7 +172,6 @@ module NCore
171
172
  response = nil
172
173
  begin
173
174
  ActiveSupport::Notifications.instrument(instrument_key, rest_opts) do
174
-
175
175
  connection = excon_client(rest_opts[:url])
176
176
  begin
177
177
  tries += 1
@@ -286,9 +286,9 @@ module NCore
286
286
  creds.inject({}) do |h,(k,v)|
287
287
  if v.present?
288
288
  if k == bearer_credential_key
289
- h["Authorization"] = "Bearer #{v}"
289
+ h['authorization'] = "Bearer #{v}"
290
290
  else
291
- h["#{auth_header_prefix}-#{k}"] = v
291
+ h["#{auth_header_prefix}-#{k}"] = v
292
292
  end
293
293
  end
294
294
  h
@@ -325,6 +325,7 @@ module NCore
325
325
 
326
326
  def debug_response(response)
327
327
  return unless logger.debug?
328
+ headers = response.headers.transform_keys(&:downcase)
328
329
  if defined? MultiJson
329
330
  json = MultiJson.load(response.body||'', symbolize_keys: false) rescue response.body
330
331
  else
@@ -332,8 +333,8 @@ module NCore
332
333
  end
333
334
  logger << <<~DBG
334
335
  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 ")}
336
+ #{response.status} | #{headers['content-type']} | #{response.body.size} bytes
337
+ #{headers.except('status', 'connection', 'content-length', 'content-type').map{|h,d| "#{h}: #{d}"}.join("\n ")}
337
338
  #{json.pretty_inspect.split("\n").join("\n ")}
338
339
  #{'-=- '*18}
339
340
  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.0'
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.0
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-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel