Class: NewDemoApiClient::FileClient
- Inherits:
-
Object
- Object
- NewDemoApiClient::FileClient
- Defined in:
- lib/test_sdk/file/client.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#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.
-
#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.
-
#download(deal_id:, file_id:, group_id:, request_options: nil) ⇒ Object
Download a file by its ID for a specific group and deal.
-
#get(deal_id:, file_id:, group_id:, request_options: nil) ⇒ NewDemoApiClient::FileResponse
Get a file by its ID for a specific group and deal.
- #initialize(request_client:) ⇒ NewDemoApiClient::FileClient constructor
-
#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.
-
#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.
-
#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.
-
#upload(deal_id:, group_id:, file:, name:, filetype:, request_options: nil) ⇒ NewDemoApiClient::CreateFileResponse
Upload a file for a specific group and deal.
Constructor Details
#initialize(request_client:) ⇒ NewDemoApiClient::FileClient
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_client ⇒ NewDemoApiClient::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.
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..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .token unless &.token.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end req.body = { **(&.additional_body_parameters || {}), name: name, type: type }.compact req.url "#{@request_client.get_url(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.
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..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .token unless &.token.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact req.params = { **(&.additional_query_parameters || {}), "archive": archive }.compact unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(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.
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..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .token unless &.token.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(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.
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..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .token unless &.token.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(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.
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..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .token unless &.token.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact req.params = { **(&.additional_query_parameters || {}), "sort_by": sort_by, "sort_order": sort_order, "page": page, "page_size": page_size }.compact unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(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.
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..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .token unless &.token.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact req.params = { **(&.additional_query_parameters || {}), "content_type": content_type, "download": download }.compact unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(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.
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..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .token unless &.token.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end req.body = { **(&.additional_body_parameters || {}), type: type }.compact req.url "#{@request_client.get_url(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.
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..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .token unless &.token.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end req.body = { **(&.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: )}/api/v1/group/#{deal_id}/deal/#{group_id}/file" end NewDemoApiClient::CreateFileResponse.from_json(json_object: response.body) end |