Class: NewDemoApiClient::AsyncFileClient

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::AsyncFileClient

Parameters:



351
352
353
# File 'lib/test_sdk/file/client.rb', line 351

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientNewDemoApiClient::AsyncRequestClient (readonly)



347
348
349
# File 'lib/test_sdk/file/client.rb', line 347

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:



423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
# File 'lib/test_sdk/file/client.rb', line 423

def create_file_entry(deal_id:, group_id:, name:, type: nil, request_options: nil)
  Async do
    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
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)


584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
# File 'lib/test_sdk/file/client.rb', line 584

def delete(file_id:, group_id:, deal_id:, archive: nil, request_options: nil)
  Async do
    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
    parsed_json = JSON.parse(response.body)
    parsed_json
  end
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)


625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
# File 'lib/test_sdk/file/client.rb', line 625

def download(deal_id:, file_id:, group_id:, request_options: nil)
  Async do
    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
    parsed_json = JSON.parse(response.body)
    parsed_json
  end
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:



504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
# File 'lib/test_sdk/file/client.rb', line 504

def get(deal_id:, file_id:, group_id:, request_options: nil)
  Async do
    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
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:



460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
# File 'lib/test_sdk/file/client.rb', line 460

def list(deal_id:, group_id:, sort_by: nil, sort_order: nil, page: nil, page_size: nil, request_options: nil)
  Async do
    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
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:



668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
# File 'lib/test_sdk/file/client.rb', line 668

def read_url(deal_id:, file_id:, group_id:, content_type: nil, download: nil, request_options: nil)
  Async do
    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
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:



545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
# File 'lib/test_sdk/file/client.rb', line 545

def update(file_id:, group_id:, deal_id:, type: nil, request_options: nil)
  Async do
    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
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:



378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# File 'lib/test_sdk/file/client.rb', line 378

def upload(deal_id:, group_id:, file:, name:, filetype:, request_options: nil)
  Async do
    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
end