files.com 1.1.647 → 1.1.649

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: 7a9039a7054a6c0d9d48c3079e135a0172e430eb301878cdfebde9dce183c5fc
4
- data.tar.gz: 4b316018052171a078451a0eaa3c9e5608829c8f700269e76ddb40c51d9f48d8
3
+ metadata.gz: f762883ff6e320131d7226422ae25f1800e1fbe172e47364e4af6551a32545a0
4
+ data.tar.gz: 2869f62037e0932d98f81023013b9ed08f180cba307a137f5b6fad728dbd2f65
5
5
  SHA512:
6
- metadata.gz: 4f769a4ae46c896209ff33c9303b47639d28b33145e7d36e863a898f9dcd4d554dad058854d54df357af3c585e3ebaabe531c188f04d637a62326f020c7d4d09
7
- data.tar.gz: 1d33bd48df21b62ae715d54ed611d69ec5bda31534b7a22adc8c178b50a6a62c6b81ed6ef2f6c94d6b2a7f6bb20872037869e09ed3965a84d29de8162a833b96
6
+ metadata.gz: 826dc59eaa2592234e807c00d047e4323efb3a1dc6c511413b349ebe4a78b385a8dbeb6d4733eb8a9000bbf280a7ac94f5cf764c4a5f72bf399f4a7b1a3530b7
7
+ data.tar.gz: db29182d2dee5cf4c7896f84521e9a0b79bb2a6ef42bf0ada476d7d2407bd5d36faa3fa0bed0bf4ed7fd2f9322621c4be49c27da103b25540f431641750c7e8d
data/README.md CHANGED
@@ -405,32 +405,16 @@ A Workspace is a lightweight way to organize related resources inside a single F
405
405
  Customers commonly group resources by project, department, client, or region. Workspaces provide a built-in structure for that grouping, so the UI can operate within a clear "workspace context" and admins can delegate management for a subset of resources without requiring full site-level isolation.
406
406
 
407
407
  Every Site has an implicit Default workspace (ID `0`). Resources that are not explicitly assigned to a named workspace are considered part of the Default workspace.
408
- <div></div>
409
-
410
- ### SDK Support
411
408
 
412
- We are still in the process of adding Workspaces support to each SDK. If you require Workspaces support right now, you need to use the REST API or the CLI.
413
- <div></div>
414
-
415
- ### Using Workspaces with the REST API
409
+ The Files.com Ruby SDK supports workspace scoping by using the `Files.workspace_id` configuration attribute. Scope a single request by passing `workspace_id` in the request options.
410
+ ```ruby title="Example Request"
411
+ require "files.com"
416
412
 
417
- To use Workspaces with the REST API, send the following request header:
413
+ Files.workspace_id = 123
418
414
 
419
- ```http
420
- X-Files-Workspace-Id: <workspace_id>
415
+ Files::Folder.list_for("", {}, workspace_id: 456)
421
416
  ```
422
417
 
423
- This changes path mapping and "what you're looking at."
424
-
425
- When the `X-Files-Workspace-Id` header is provided:
426
-
427
- - List, show, update, and delete operations are constrained to that workspace for workspace-scoped models.
428
- - Create operations default `workspace_id` to the scoped workspace when not explicitly provided.
429
- - Attempts to provide a mismatching `workspace_id` are rejected with `not-authorized/insufficient-permission-for-params`.
430
-
431
- This header only works for sitewide keys, or keys related to users with permissions to more than one workspace.
432
- <div></div>
433
-
434
418
  ## Foreign Language Support
435
419
 
436
420
  The Files.com Ruby SDK supports localized responses by using the `Files.language` configuration attribute.
data/_VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.647
1
+ 1.1.649
data/lib/files.com/api.rb CHANGED
@@ -11,13 +11,14 @@ module Files
11
11
  api_key = headers.delete(:api_key)
12
12
  client = headers.delete(:client)
13
13
  session_id = headers.delete(:session_id)
14
+ workspace_id = headers.delete(:workspace_id)
14
15
  if session = headers.delete(:session)
15
16
  session.save unless session.id
16
17
  session_id = session.id
17
18
  end
18
19
 
19
20
  resp, options[:api_key], options[:session_id] = client.execute_request(
20
- verb, path, api_key: api_key, headers: headers, params: params, session_id: session_id
21
+ verb, path, api_key: api_key, headers: headers, params: params, session_id: session_id, workspace_id: workspace_id
21
22
  )
22
23
 
23
24
  # Hash#select returns an array before 1.9
@@ -93,9 +93,10 @@ module Files
93
93
  end
94
94
  end
95
95
 
96
- def execute_request(method, path, base_url: nil, api_key: nil, session_id: nil, headers: {}, params: {})
96
+ def execute_request(method, path, base_url: nil, api_key: nil, session_id: nil, workspace_id: nil, headers: {}, params: {})
97
97
  base_url ||= Files.base_url
98
98
  session_id ||= Files.session_id
99
+ workspace_id = Files.workspace_id if workspace_id.nil?
99
100
 
100
101
  if session_id and session_id != ""
101
102
  check_session_id!(session_id)
@@ -113,7 +114,7 @@ module Files
113
114
  body = params
114
115
  end
115
116
 
116
- headers = request_headers(api_key, session_id, method).update(headers)
117
+ headers = request_headers(api_key, session_id, method, workspace_id).update(headers)
117
118
  url = api_url(path, base_url)
118
119
 
119
120
  context = RequestLogContext.new
@@ -315,7 +316,7 @@ module Files
315
316
  raise APIConnectionError, message
316
317
  end
317
318
 
318
- private def request_headers(api_key, session_id, _method)
319
+ private def request_headers(api_key, session_id, _method, workspace_id)
319
320
  user_agent = "Files.com Ruby SDK v#{Files::VERSION}"
320
321
  user_agent += " #{format_app_info(Files.app_info)}" unless Files.app_info.nil?
321
322
 
@@ -334,6 +335,8 @@ module Files
334
335
  headers["X-FilesAPI-Key"] = api_key if api_key
335
336
  headers["X-FilesAPI-Auth"] = session_id if session_id
336
337
  headers["Accept-Language"] = Files.language if Files.language
338
+ workspace_id = workspace_id.to_s
339
+ headers["X-Files-Workspace-Id"] = workspace_id unless workspace_id.empty?
337
340
 
338
341
  user_agent = @system_profiler.user_agent
339
342
  begin
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Files
4
4
  module Util
5
- OPTS = Set[:api_key, :client, :session_id].freeze
5
+ OPTS = Set[:api_key, :client, :session_id, :workspace_id].freeze
6
6
  COLOR_CODES = {
7
7
  black: 0, light_black: 60,
8
8
  red: 1, light_red: 61,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Files
4
- VERSION = "1.1.647"
4
+ VERSION = "1.1.649"
5
5
  end
data/lib/files.com.rb CHANGED
@@ -176,6 +176,7 @@ module Files
176
176
  @logger = nil
177
177
  @proxy = nil
178
178
  @session_id = nil
179
+ @workspace_id = nil
179
180
  @default_headers = nil
180
181
 
181
182
  @max_network_retries = 3
@@ -186,7 +187,7 @@ module Files
186
187
  @read_timeout = 60
187
188
 
188
189
  class << self
189
- attr_accessor :api_key, :base_url, :default_headers, :initial_network_retry_delay, :language, :max_network_retry_delay, :open_timeout, :read_timeout, :proxy, :session_id
190
+ attr_accessor :api_key, :base_url, :default_headers, :initial_network_retry_delay, :language, :max_network_retry_delay, :open_timeout, :read_timeout, :proxy, :session_id, :workspace_id
190
191
  end
191
192
 
192
193
  # map to the same values as the standard library's logger
@@ -0,0 +1,79 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "Workspace scoping" do
4
+ around do |example|
5
+ old_workspace_id = Files.workspace_id
6
+ Files.workspace_id = nil
7
+ example.run
8
+ ensure
9
+ Files.workspace_id = old_workspace_id
10
+ end
11
+
12
+ describe Files::ApiClient do
13
+ let(:client) { described_class.new }
14
+
15
+ it "includes the configured workspace ID header" do
16
+ headers = client.send(:request_headers, "api-key", nil, :get, 123)
17
+
18
+ expect(headers["X-Files-Workspace-Id"]).to eq("123")
19
+ end
20
+
21
+ it "omits the workspace ID header when unset" do
22
+ headers = client.send(:request_headers, "api-key", nil, :get, nil)
23
+
24
+ expect(headers).not_to have_key("X-Files-Workspace-Id")
25
+ end
26
+
27
+ it "falls back to the configured workspace ID" do
28
+ Files.workspace_id = 123
29
+ response = double(status: 204, body: "", headers: {})
30
+ conn = double
31
+ client = described_class.new(conn)
32
+
33
+ expect(client).to receive(:request_headers).with("api-key", nil, :get, 123).and_return({})
34
+ expect(conn).to receive(:run_request).and_return(response)
35
+
36
+ client.execute_request(:get, "/folders", api_key: "api-key")
37
+ end
38
+
39
+ it "lets a per-request workspace ID override the configured workspace ID" do
40
+ Files.workspace_id = 123
41
+ response = double(status: 204, body: "", headers: {})
42
+ conn = double
43
+ client = described_class.new(conn)
44
+
45
+ expect(client).to receive(:request_headers).with("api-key", nil, :get, 456).and_return({})
46
+ expect(conn).to receive(:run_request).and_return(response)
47
+
48
+ client.execute_request(:get, "/folders", api_key: "api-key", workspace_id: 456)
49
+ end
50
+ end
51
+
52
+ describe Files::Api do
53
+ it "passes per-request workspace ID options to the API client" do
54
+ client = instance_double(Files::ApiClient)
55
+ response = instance_double(Files::Response)
56
+
57
+ expect(client).to receive(:execute_request).with(
58
+ :get,
59
+ "/folders",
60
+ api_key: nil,
61
+ headers: {},
62
+ params: {},
63
+ session_id: nil,
64
+ workspace_id: 456
65
+ ).and_return([ response, nil, nil ])
66
+
67
+ actual_response, options = described_class.send_request(
68
+ "/folders",
69
+ :get,
70
+ {},
71
+ client: client,
72
+ workspace_id: 456
73
+ )
74
+
75
+ expect(actual_response).to eq(response)
76
+ expect(options[:workspace_id]).to eq(456)
77
+ end
78
+ end
79
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: files.com
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.647
4
+ version: 1.1.649
5
5
  platform: ruby
6
6
  authors:
7
7
  - files.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-06-15 00:00:00.000000000 Z
11
+ date: 2026-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -461,6 +461,7 @@ files:
461
461
  - spec/path_util_spec.rb
462
462
  - spec/spec_helper.rb
463
463
  - spec/uri_spec.rb
464
+ - spec/workspace_id_spec.rb
464
465
  - test.sh
465
466
  - test/test.rb
466
467
  homepage: https://www.files.com