files.com 1.1.784 → 1.1.785

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: cd5e31f4e4c09fa7272e5c337ddc01c434546c93f177fe8fecd887839326f060
4
- data.tar.gz: 143a0c464a2530296c1e67243d5f8d2e3640cff840c897ae2067517147af45b7
3
+ metadata.gz: 826a8d11a190abdb6361a77d984ee6fa10edd1a00ae53d6899e1d4caa82f9c95
4
+ data.tar.gz: 8b3e481cee2fff8e991e19af4fb18490e2a177f96cca16aabefdcc1b74a76efd
5
5
  SHA512:
6
- metadata.gz: 0d5eca777f0554ded3ad22b322bd8dcf959885c986c461a1d478c8097ffb00e2ee6d6741fd426cd36d0031796890f7d6ec7d0400f8c37072ae9079484a856fc7
7
- data.tar.gz: f377e72e2cdb7e3f49391059d4c4c6115e506053cf7c371e6a0c2957018e701e8f3fd09ef8daeb099c498de22d8ce490826ea66cf596511bc43f8dd3f1fbaa89
6
+ metadata.gz: 400c4fce89d964bf7b2ee6fba2059474fc5d54b5858ab07c8e5e7c7a5c21c62ed2998921d2b479dbbe4e22c89a58340d360b54156c8fab01be150a04c085308c
7
+ data.tar.gz: 7ec1d135b18a5f02b7c5b68d9dd02249608617e7bc4dc14a36093c602aa862bc4054f7ea7bdbbc8f7331d0a4bba39b626b691731f56cd6ca7f44a2f1fd6e7b9e
data/_VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.784
1
+ 1.1.785
@@ -8,7 +8,7 @@ module Files
8
8
  QUERY_METHODS = %i[get head delete].freeze
9
9
  private_constant :QUERY_METHODS
10
10
 
11
- # The default for a logging option this client does not set itself.
11
+ # The default for an option this client does not set itself.
12
12
  USE_GLOBAL = Object.new.freeze
13
13
  private_constant :USE_GLOBAL
14
14
 
@@ -27,10 +27,16 @@ module Files
27
27
  # Files.log_level is set.
28
28
  #
29
29
  # A client created with logger: nil, log_level: nil logs no ordinary API messages.
30
- def initialize(conn = nil, logger: USE_GLOBAL, log_level: USE_GLOBAL)
30
+ #
31
+ # Its API requests likewise name the library-wide Files.workspace_id, read for each request, unless
32
+ # +workspace_id+ gives this client its own workspace; 0 is sent as "0". A request's own workspace_id option still
33
+ # takes precedence, and a request whose workspace_id is nil uses this client's. Pass workspace_id: nil to name no
34
+ # workspace for this client's requests even when Files.workspace_id is set.
35
+ def initialize(conn = nil, logger: USE_GLOBAL, log_level: USE_GLOBAL, workspace_id: USE_GLOBAL)
31
36
  self.conn = conn || self.class.default_conn
32
37
  @logger = logger
33
38
  @log_level = log_level.equal?(USE_GLOBAL) ? log_level : Util.normalize_log_level(log_level)
39
+ @workspace_id = workspace_id
34
40
  @system_profiler = SystemProfiler.new
35
41
  @last_request_metrics = nil
36
42
  end
@@ -125,7 +131,7 @@ module Files
125
131
  else
126
132
  session_id = nil
127
133
  end
128
- workspace_id = Files.workspace_id if workspace_id.nil?
134
+ workspace_id = default_workspace_id if workspace_id.nil?
129
135
 
130
136
  if session_id and session_id != ""
131
137
  check_session_id!(session_id)
@@ -550,6 +556,11 @@ module Files
550
556
  )
551
557
  end
552
558
 
559
+ # This client's own workspace where it set one, and the library-wide one otherwise.
560
+ private def default_workspace_id
561
+ @workspace_id.equal?(USE_GLOBAL) ? Files.workspace_id : @workspace_id
562
+ end
563
+
553
564
  class RequestLogContext
554
565
  attr_accessor :body, :api_key, :method, :path, :query_params, :session_id
555
566
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Files
4
- VERSION = "1.1.784"
4
+ VERSION = "1.1.785"
5
5
  end
@@ -402,6 +402,45 @@ RSpec.describe Files::ApiClient do
402
402
  end
403
403
  end
404
404
 
405
+ describe "client workspaces" do
406
+ around do |example|
407
+ original = Files.workspace_id
408
+ example.run
409
+ ensure
410
+ Files.workspace_id = original
411
+ end
412
+
413
+ it "sends each client's own workspace, and the library-wide one for clients without their own" do
414
+ workspace_headers = []
415
+ connection = Faraday.new do |builder|
416
+ builder.response :raise_error
417
+ builder.adapter :test do |stub|
418
+ stub.get("/api/rest/v1/workspaces/1") do |env|
419
+ workspace_headers << env.request_headers["X-Files-Workspace-Id"]
420
+ [ 200, { "Content-Type" => "application/json" }, { id: 1 }.to_json ]
421
+ end
422
+ end
423
+ end
424
+ find_workspace = ->(client, **options) { Files::Workspace.find(1, {}, api_key: "key", client: client, **options) }
425
+ Files.workspace_id = 5
426
+ client_a = described_class.new(connection, workspace_id: 0)
427
+ client_b = described_class.new(connection, workspace_id: 7)
428
+
429
+ find_workspace.call(client_a)
430
+ find_workspace.call(client_b)
431
+ Files.workspace_id = 6
432
+ find_workspace.call(client_a)
433
+ find_workspace.call(described_class.new(connection))
434
+ find_workspace.call(described_class.new(connection, workspace_id: nil))
435
+ find_workspace.call(client_b, workspace_id: 0)
436
+ find_workspace.call(client_b, workspace_id: "")
437
+ find_workspace.call(client_b, workspace_id: nil)
438
+
439
+ expect(workspace_headers).to eq([ "0", "7", "0", "6", nil, "0", nil, "7" ])
440
+ expect(Files.workspace_id).to eq(6)
441
+ end
442
+ end
443
+
405
444
  describe "network timeouts" do
406
445
  around do |example|
407
446
  original = [ Files.open_timeout, Files.read_timeout ]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: files.com
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.784
4
+ version: 1.1.785
5
5
  platform: ruby
6
6
  authors:
7
7
  - files.com