Class: NewDemoApiClient::FileClient

Inherits:
Object
  • Object
show all
Defined in:
lib/test_sdk/file/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ NewDemoApiClient::FileClient

Parameters:



21
22
23
# File 'lib/test_sdk/file/client.rb', line 21

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientNewDemoApiClient::RequestClient (readonly)



17
18
19
# File 'lib/test_sdk/file/client.rb', line 17

def request_client
  @request_client
end

Instance Method Details

#create_file_entry(deal_id:, group_id:, name:, type: nil, request_options: nil) ⇒ NewDemoApiClient::CreateFileForSignedURLResponse

Create a new file entry for a specific group and deal. Requires the contents to

be uploaded separately via signed-url.

Examples:

api = NewDemoApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: NewDemoApiClient::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.file.create_file_entry(
  deal_id: 1,
  group_id: 1,
  name: "name"
)

Parameters:

Returns:



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/test_sdk/file/client.rb', line 91

def create_file_entry(deal_id:, group_id:, name:, type: nil, request_options: nil)
  response = @request_client.conn.post do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    req.body = { **(request_options&.additional_body_parameters || {}), name: name, type: type }.compact
    req.url "#{@request_client.get_url(request_options: request_options)}/api/v1/group/#{deal_id}/deal/#{group_id}/file/entry"
  end
  NewDemoApiClient::CreateFileForSignedURLResponse.from_json(json_object: response.body)
end

#delete(file_id:, group_id:, deal_id:, archive: nil, request_options: nil) ⇒ Object

Delete a file by its ID for a specific group and deal.

Examples:

api = NewDemoApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: NewDemoApiClient::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.file.delete(
  file_id: 1,
  group_id: 1,
  deal_id: 1
)

Parameters:

  • file_id (Integer)
  • group_id (Integer)
  • deal_id (Integer)
  • archive (Boolean) (defaults to: nil)
  • request_options (NewDemoApiClient::RequestOptions) (defaults to: nil)

Returns:

  • (Object)


244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/test_sdk/file/client.rb', line 244

def delete(file_id:, group_id:, deal_id:, archive: nil, request_options: nil)
  response = @request_client.conn.delete do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    req.params = { **(request_options&.additional_query_parameters || {}), "archive": archive }.compact
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(request_options: request_options)}/api/v1/group/#{file_id}/deal/#{group_id}/file/#{deal_id}"
  end
  JSON.parse(response.body)
end

#download(deal_id:, file_id:, group_id:, request_options: nil) ⇒ Object

Download a file by its ID for a specific group and deal.

NOTE: Downloads are limited to 10 GB. For larger file downloads use the
signed-url download endpoint.

Examples:

api = NewDemoApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: NewDemoApiClient::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.file.download(
  deal_id: 1,
  file_id: 1,
  group_id: 1
)

Parameters:

Returns:

  • (Object)


282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/test_sdk/file/client.rb', line 282

def download(deal_id:, file_id:, group_id:, request_options: nil)
  response = @request_client.conn.get do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(request_options: request_options)}/api/v1/group/#{deal_id}/deal/#{file_id}/file/#{group_id}/download"
  end
  JSON.parse(response.body)
end

#get(deal_id:, file_id:, group_id:, request_options: nil) ⇒ NewDemoApiClient::FileResponse

Get a file by its ID for a specific group and deal.

Examples:

api = NewDemoApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: NewDemoApiClient::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.file.get(
  deal_id: 1,
  file_id: 1,
  group_id: 1
)

Parameters:

Returns:



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/test_sdk/file/client.rb', line 168

def get(deal_id:, file_id:, group_id:, request_options: nil)
  response = @request_client.conn.get do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(request_options: request_options)}/api/v1/group/#{deal_id}/deal/#{file_id}/file/#{group_id}"
  end
  NewDemoApiClient::FileResponse.from_json(json_object: response.body)
end

#list(deal_id:, group_id:, sort_by: nil, sort_order: nil, page: nil, page_size: nil, request_options: nil) ⇒ NewDemoApiClient::PaginatedResponseFileResponse

Get all files for a specific group and deal.

Examples:

api = NewDemoApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: NewDemoApiClient::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.file.list(deal_id: 1, group_id: 1)

Parameters:

  • deal_id (Integer)
  • group_id (Integer)
  • sort_by (String) (defaults to: nil)
  • sort_order (String) (defaults to: nil)
  • page (Integer) (defaults to: nil)
  • page_size (Integer) (defaults to: nil)
  • request_options (NewDemoApiClient::RequestOptions) (defaults to: nil)

Returns:



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/test_sdk/file/client.rb', line 126

def list(deal_id:, group_id:, sort_by: nil, sort_order: nil, page: nil, page_size: nil, request_options: nil)
  response = @request_client.conn.get do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    req.params = {
      **(request_options&.additional_query_parameters || {}),
      "sort_by": sort_by,
      "sort_order": sort_order,
      "page": page,
      "page_size": page_size
    }.compact
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(request_options: request_options)}/api/v1/group/#{deal_id}/deal/#{group_id}/file/all"
  end
  NewDemoApiClient::PaginatedResponseFileResponse.from_json(json_object: response.body)
end

#read_url(deal_id:, file_id:, group_id:, content_type: nil, download: nil, request_options: nil) ⇒ NewDemoApiClient::GcsSignedURLResponse

Get a signed URL to read a file by its ID for a specific group and deal.

Examples:

api = NewDemoApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: NewDemoApiClient::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.file.read_url(
  deal_id: 1,
  file_id: 1,
  group_id: 1
)

Parameters:

  • deal_id (Integer)
  • file_id (Integer)
  • group_id (Integer)
  • content_type (String) (defaults to: nil)
  • download (Boolean) (defaults to: nil)
  • request_options (NewDemoApiClient::RequestOptions) (defaults to: nil)

Returns:



322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/test_sdk/file/client.rb', line 322

def read_url(deal_id:, file_id:, group_id:, content_type: nil, download: nil, request_options: nil)
  response = @request_client.conn.get do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    req.params = {
      **(request_options&.additional_query_parameters || {}),
      "content_type": content_type,
      "download": download
    }.compact
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(request_options: request_options)}/api/v1/group/#{deal_id}/deal/#{file_id}/file/#{group_id}/signed-url"
  end
  NewDemoApiClient::GcsSignedURLResponse.from_json(json_object: response.body)
end

#update(file_id:, group_id:, deal_id:, type: nil, request_options: nil) ⇒ NewDemoApiClient::FileResponse

Update a file by its ID for a specific group and deal.

Examples:

api = NewDemoApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: NewDemoApiClient::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.file.update(
  file_id: 1,
  group_id: 1,
  deal_id: 1
)

Parameters:

Returns:



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/test_sdk/file/client.rb', line 207

def update(file_id:, group_id:, deal_id:, type: nil, request_options: nil)
  response = @request_client.conn.put do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    req.body = { **(request_options&.additional_body_parameters || {}), type: type }.compact
    req.url "#{@request_client.get_url(request_options: request_options)}/api/v1/group/#{file_id}/deal/#{group_id}/file/#{deal_id}"
  end
  NewDemoApiClient::FileResponse.from_json(json_object: response.body)
end

#upload(deal_id:, group_id:, file:, name:, filetype:, request_options: nil) ⇒ NewDemoApiClient::CreateFileResponse

Upload a file for a specific group and deal. Creates a file entry as well as

uploads its contents.
NOTE: Uploads are limited to 10 GB. For larger file uploads use the signed-url
upload endpoint.

Examples:

api = NewDemoApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: NewDemoApiClient::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.file.upload(
  deal_id: 1,
  group_id: 1,
  file: my_file.txt
)

Parameters:

Returns:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/test_sdk/file/client.rb', line 48

def upload(deal_id:, group_id:, file:, name:, filetype:, request_options: nil)
  response = @request_client.conn.post do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    req.body = {
      **(request_options&.additional_body_parameters || {}),
      file: NewDemoApiClient::FileUtilities.as_faraday_multipart(file_like: file),
      name: name,
      filetype: filetype
    }.compact
    req.url "#{@request_client.get_url(request_options: request_options)}/api/v1/group/#{deal_id}/deal/#{group_id}/file"
  end
  NewDemoApiClient::CreateFileResponse.from_json(json_object: response.body)
end