Class: SirvRestApi::Client

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

Overview

Main client for interacting with the Sirv REST API

Constant Summary collapse

DEFAULT_BASE_URL =
"https://api.sirv.com"
DEFAULT_TOKEN_REFRESH_BUFFER =
60
DEFAULT_TIMEOUT =
30
DEFAULT_MAX_RETRIES =
3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id:, client_secret:, base_url: DEFAULT_BASE_URL, auto_refresh_token: true, token_refresh_buffer: DEFAULT_TOKEN_REFRESH_BUFFER, timeout: DEFAULT_TIMEOUT, max_retries: DEFAULT_MAX_RETRIES) ⇒ Client

Initialize a new Sirv API client

Parameters:

  • client_id (String)

    Your Sirv API client ID (required)

  • client_secret (String)

    Your Sirv API client secret (required)

  • base_url (String) (defaults to: DEFAULT_BASE_URL)

    Base URL for API (default: api.sirv.com)

  • auto_refresh_token (Boolean) (defaults to: true)

    Auto-refresh token before expiry (default: true)

  • token_refresh_buffer (Integer) (defaults to: DEFAULT_TOKEN_REFRESH_BUFFER)

    Seconds before token expiry to trigger refresh (default: 60)

  • timeout (Integer) (defaults to: DEFAULT_TIMEOUT)

    Request timeout in seconds (default: 30)

  • max_retries (Integer) (defaults to: DEFAULT_MAX_RETRIES)

    Maximum number of retries for failed requests (default: 3)

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/sirv_rest_api/client.rb', line 26

def initialize(client_id:, client_secret:, base_url: DEFAULT_BASE_URL,
               auto_refresh_token: true, token_refresh_buffer: DEFAULT_TOKEN_REFRESH_BUFFER,
               timeout: DEFAULT_TIMEOUT, max_retries: DEFAULT_MAX_RETRIES)
  raise ArgumentError, "client_id is required" if client_id.nil? || client_id.empty?
  raise ArgumentError, "client_secret is required" if client_secret.nil? || client_secret.empty?

  @config = {
    client_id: client_id,
    client_secret: client_secret,
    base_url: base_url,
    auto_refresh_token: auto_refresh_token,
    token_refresh_buffer: token_refresh_buffer,
    timeout: timeout,
    max_retries: max_retries
  }
  @token = nil
  @token_expiry = nil
  @mutex = Mutex.new
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



15
16
17
# File 'lib/sirv_rest_api/client.rb', line 15

def config
  @config
end

Instance Method Details

#access_tokenString?

Get the current access token

Returns:

  • (String, nil)

    Current token or nil



88
89
90
# File 'lib/sirv_rest_api/client.rb', line 88

def access_token
  @mutex.synchronize { @token }
end

#add_file_tags(filename, tags) ⇒ void

This method returns an undefined value.

Add tags to file

Parameters:

  • filename (String)

    File path

  • tags (Array<String>)

    Tags to add



481
482
483
484
# File 'lib/sirv_rest_api/client.rb', line 481

def add_file_tags(filename, tags)
  request(:post, "/v2/files/meta/tags", { filename: filename, tags: tags })
  nil
end

#batch_delete(filenames) ⇒ BatchDeleteResult

Delete multiple files/folders

Parameters:

  • filenames (Array<String>)

    List of file paths

Returns:



339
340
341
342
# File 'lib/sirv_rest_api/client.rb', line 339

def batch_delete(filenames)
  response = request(:post, "/v2/files/delete", filenames)
  BatchDeleteResult.new(response)
end

#batch_zip(filenames:, filename:) ⇒ BatchZipResult

Create ZIP archive from multiple files

Parameters:

  • filenames (Array<String>)

    Files to include

  • filename (String)

    Output ZIP filename

Returns:



391
392
393
394
# File 'lib/sirv_rest_api/client.rb', line 391

def batch_zip(filenames:, filename:)
  response = request(:post, "/v2/files/zip", { filenames: filenames, filename: filename })
  BatchZipResult.new(response)
end

#connect(expires_in: nil) ⇒ TokenResponse

Authenticate and obtain a bearer token

Parameters:

  • expires_in (Integer, nil) (defaults to: nil)

    Token expiry time in seconds (5-604800). Default is 1200 (20 minutes).

Returns:

  • (TokenResponse)

    Token response with token, expiration, and scopes



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/sirv_rest_api/client.rb', line 54

def connect(expires_in: nil)
  body = {
    clientId: @config[:client_id],
    clientSecret: @config[:client_secret]
  }

  if expires_in
    raise ValidationError.new("expires_in must be between 5 and 604800 seconds") unless expires_in.between?(5, 604800)
    body[:expiresIn] = expires_in
  end

  response = request_without_auth(:post, "/v2/token", body)
  token_response = TokenResponse.new(response)

  @mutex.synchronize do
    @token = token_response.token
    @token_expiry = Time.now + token_response.expires_in
  end

  token_response
end

#connected?Boolean

Check if client is connected with a valid token

Returns:

  • (Boolean)

    true if connected with valid token



79
80
81
82
83
# File 'lib/sirv_rest_api/client.rb', line 79

def connected?
  @mutex.synchronize do
    !@token.nil? && !token_expired?
  end
end

#copy_file(from:, to:) ⇒ void

This method returns an undefined value.

Copy a file

Parameters:

  • from (String)

    Source path

  • to (String)

    Destination path



358
359
360
361
# File 'lib/sirv_rest_api/client.rb', line 358

def copy_file(from:, to:)
  request(:post, "/v2/files/copy", { from: from, to: to })
  nil
end

#create_folder(dirname) ⇒ void

This method returns an undefined value.

Create a new folder

Parameters:

  • dirname (String)

    Directory path



321
322
323
324
# File 'lib/sirv_rest_api/client.rb', line 321

def create_folder(dirname)
  request(:post, "/v2/files/mkdir", { dirname: dirname })
  nil
end

#delete_file(filename) ⇒ void

This method returns an undefined value.

Delete a file or empty folder

Parameters:

  • filename (String)

    File or folder path



330
331
332
333
# File 'lib/sirv_rest_api/client.rb', line 330

def delete_file(filename)
  request(:post, "/v2/files/delete", { filename: filename })
  nil
end

#delete_point_of_interest(filename, name) ⇒ void

This method returns an undefined value.

Delete point of interest

Parameters:

  • filename (String)

    File path

  • name (String)

    POI name



674
675
676
677
# File 'lib/sirv_rest_api/client.rb', line 674

def delete_point_of_interest(filename, name)
  request(:delete, "/v2/files/poi", { filename: filename, name: name })
  nil
end

#download_file(filename) ⇒ String

Download a file

Parameters:

  • filename (String)

    File path on Sirv

Returns:

  • (String)

    File contents as binary string



276
277
278
# File 'lib/sirv_rest_api/client.rb', line 276

def download_file(filename)
  request_raw(:get, "/v2/files/download", { filename: filename })
end

#download_file_to(filename, local_path) ⇒ void

This method returns an undefined value.

Download a file to local path

Parameters:

  • filename (String)

    File path on Sirv

  • local_path (String)

    Local file path to save to



285
286
287
288
289
# File 'lib/sirv_rest_api/client.rb', line 285

def download_file_to(filename, local_path)
  content = download_file(filename)
  File.binwrite(local_path, content)
  nil
end

#each_folder_item(dirname) {|FileInfo| ... } ⇒ Enumerator

Iterate through all items in a folder (handles pagination automatically)

Parameters:

  • dirname (String)

    Directory path

Yields:

  • (FileInfo)

    Each file/folder in the directory

Returns:

  • (Enumerator)

    If no block given



207
208
209
210
211
212
213
214
215
216
217
# File 'lib/sirv_rest_api/client.rb', line 207

def each_folder_item(dirname, &block)
  return enum_for(:each_folder_item, dirname) unless block_given?

  continuation = nil
  loop do
    result = read_folder_contents(dirname, continuation: continuation)
    result.contents.each(&block)
    break if result.continuation.nil? || result.continuation.empty?
    continuation = result.continuation
  end
end

#each_search_result(params = {}) {|FileInfo| ... } ⇒ Enumerator

Iterate through all search results (handles pagination automatically)

Parameters:

  • params (Hash) (defaults to: {})

    Search parameters

Yields:

  • (FileInfo)

    Each file in search results

Returns:

  • (Enumerator)

    If no block given



260
261
262
263
264
265
266
267
268
269
270
# File 'lib/sirv_rest_api/client.rb', line 260

def each_search_result(params = {}, &block)
  return enum_for(:each_search_result, params) unless block_given?

  result = search_files(params)
  result.hits.each(&block)

  while result.scroll_id && !result.hits.empty?
    result = scroll_search(result.scroll_id)
    result.hits.each(&block)
  end
end

#export_spin_to_amazon(filename:, asin: nil, product_id: nil) ⇒ void

This method returns an undefined value.

Export spin to Amazon

Parameters:

  • filename (String)

    Spin filename

  • asin (String, nil) (defaults to: nil)

    Amazon ASIN

  • product_id (String, nil) (defaults to: nil)

    Product ID



589
590
591
592
593
594
595
# File 'lib/sirv_rest_api/client.rb', line 589

def export_spin_to_amazon(filename:, asin: nil, product_id: nil)
  body = { filename: filename }
  body[:asin] = asin if asin
  body[:productId] = product_id if product_id
  request(:post, "/v2/files/spin/export/amazon", body)
  nil
end

#export_spin_to_grainger(filename:, product_id: nil) ⇒ void

This method returns an undefined value.

Export spin to Grainger

Parameters:

  • filename (String)

    Spin filename

  • product_id (String, nil) (defaults to: nil)

    Product ID



638
639
640
641
642
643
# File 'lib/sirv_rest_api/client.rb', line 638

def export_spin_to_grainger(filename:, product_id: nil)
  body = { filename: filename }
  body[:productId] = product_id if product_id
  request(:post, "/v2/files/spin/export/grainger", body)
  nil
end

#export_spin_to_home_depot(filename:, product_id: nil) ⇒ void

This method returns an undefined value.

Export spin to Home Depot

Parameters:

  • filename (String)

    Spin filename

  • product_id (String, nil) (defaults to: nil)

    Product ID



614
615
616
617
618
619
# File 'lib/sirv_rest_api/client.rb', line 614

def export_spin_to_home_depot(filename:, product_id: nil)
  body = { filename: filename }
  body[:productId] = product_id if product_id
  request(:post, "/v2/files/spin/export/homedepot", body)
  nil
end

#export_spin_to_lowes(filename:, product_id: nil) ⇒ void

This method returns an undefined value.

Export spin to Lowe’s

Parameters:

  • filename (String)

    Spin filename

  • product_id (String, nil) (defaults to: nil)

    Product ID



626
627
628
629
630
631
# File 'lib/sirv_rest_api/client.rb', line 626

def export_spin_to_lowes(filename:, product_id: nil)
  body = { filename: filename }
  body[:productId] = product_id if product_id
  request(:post, "/v2/files/spin/export/lowes", body)
  nil
end

#export_spin_to_walmart(filename:, product_id: nil) ⇒ void

This method returns an undefined value.

Export spin to Walmart

Parameters:

  • filename (String)

    Spin filename

  • product_id (String, nil) (defaults to: nil)

    Product ID



602
603
604
605
606
607
# File 'lib/sirv_rest_api/client.rb', line 602

def export_spin_to_walmart(filename:, product_id: nil)
  body = { filename: filename }
  body[:productId] = product_id if product_id
  request(:post, "/v2/files/spin/export/walmart", body)
  nil
end

#fetch_url(url:, filename:, wait: nil) ⇒ void

This method returns an undefined value.

Fetch file from external URL

Parameters:

  • url (String)

    Source URL

  • filename (String)

    Target filename on Sirv

  • wait (Boolean, nil) (defaults to: nil)

    Wait for completion



379
380
381
382
383
384
# File 'lib/sirv_rest_api/client.rb', line 379

def fetch_url(url:, filename:, wait: nil)
  body = { url: url, filename: filename }
  body[:wait] = wait unless wait.nil?
  request(:post, "/v2/files/fetch", body)
  nil
end

#generate_jwt(filename:, expires_in: nil, secure_params: nil) ⇒ JwtResponse

Generate JWT protected URL

Parameters:

  • filename (String)

    File path

  • expires_in (Integer, nil) (defaults to: nil)

    Expiration time in seconds

  • secure_params (Hash, nil) (defaults to: nil)

    Additional secure parameters

Returns:



545
546
547
548
549
550
551
# File 'lib/sirv_rest_api/client.rb', line 545

def generate_jwt(filename:, expires_in: nil, secure_params: nil)
  body = { filename: filename }
  body[:expiresIn] = expires_in if expires_in
  body[:secureParams] = secure_params if secure_params
  response = request(:post, "/v2/files/jwt", body)
  JwtResponse.new(response)
end

#get_account_infoAccountInfo

Get account information

Returns:



99
100
101
102
# File 'lib/sirv_rest_api/client.rb', line 99

def 
  response = request(:get, "/v2/account")
  AccountInfo.new(response)
end

#get_account_limitsAccountLimits

Get API rate limits

Returns:



116
117
118
119
# File 'lib/sirv_rest_api/client.rb', line 116

def 
  response = request(:get, "/v2/account/limits")
  AccountLimits.new(response)
end

#get_account_usersArray<AccountUser>

Get all account users

Returns:



132
133
134
135
# File 'lib/sirv_rest_api/client.rb', line 132

def 
  response = request(:get, "/v2/account/users")
  response.map { |user| AccountUser.new(user) }
end

#get_approval_flag(filename) ⇒ Boolean

Get approval flag

Parameters:

  • filename (String)

    File path

Returns:

  • (Boolean)

    Approval status



520
521
522
523
# File 'lib/sirv_rest_api/client.rb', line 520

def get_approval_flag(filename)
  response = request(:get, "/v2/files/meta/approval", { filename: filename })
  response["approved"]
end

#get_batch_delete_status(job_id) ⇒ BatchDeleteResult

Get batch delete job status

Parameters:

  • job_id (String)

    Job ID

Returns:



348
349
350
351
# File 'lib/sirv_rest_api/client.rb', line 348

def get_batch_delete_status(job_id)
  response = request(:get, "/v2/files/delete/#{job_id}")
  BatchDeleteResult.new(response)
end

#get_billing_planBillingPlan

Get billing plan details

Returns:



140
141
142
143
# File 'lib/sirv_rest_api/client.rb', line 140

def get_billing_plan
  response = request(:get, "/v2/billing/plan")
  BillingPlan.new(response)
end

#get_file_description(filename) ⇒ String

Get file description

Parameters:

  • filename (String)

    File path

Returns:

  • (String)

    File description



452
453
454
455
# File 'lib/sirv_rest_api/client.rb', line 452

def get_file_description(filename)
  response = request(:get, "/v2/files/meta/description", { filename: filename })
  response["description"]
end

#get_file_info(filename) ⇒ FileInfo

Get file information

Parameters:

  • filename (String)

    File path

Returns:



185
186
187
188
# File 'lib/sirv_rest_api/client.rb', line 185

def get_file_info(filename)
  response = request(:get, "/v2/files/stat", { filename: filename })
  FileInfo.new(response)
end

#get_file_meta(filename) ⇒ FileMeta

Get all file metadata

Parameters:

  • filename (String)

    File path

Returns:



413
414
415
416
# File 'lib/sirv_rest_api/client.rb', line 413

def get_file_meta(filename)
  response = request(:get, "/v2/files/meta", { filename: filename })
  FileMeta.new(response)
end

#get_file_tags(filename) ⇒ Array<String>

Get file tags

Parameters:

  • filename (String)

    File path

Returns:

  • (Array<String>)

    File tags



471
472
473
474
# File 'lib/sirv_rest_api/client.rb', line 471

def get_file_tags(filename)
  response = request(:get, "/v2/files/meta/tags", { filename: filename })
  response["tags"] || []
end

#get_file_title(filename) ⇒ String

Get file title

Parameters:

  • filename (String)

    File path

Returns:

  • (String)

    File title



433
434
435
436
# File 'lib/sirv_rest_api/client.rb', line 433

def get_file_title(filename)
  response = request(:get, "/v2/files/meta/title", { filename: filename })
  response["title"]
end

#get_folder_options(dirname) ⇒ Hash

Get folder options

Parameters:

  • dirname (String)

    Directory path

Returns:

  • (Hash)

    Folder options



223
224
225
# File 'lib/sirv_rest_api/client.rb', line 223

def get_folder_options(dirname)
  request(:get, "/v2/files/options", { dirname: dirname })
end

#get_http_stats(from:, to:) ⇒ Array<HttpStats>

Get HTTP transfer statistics

Parameters:

  • from (String)

    Start date (ISO format)

  • to (String)

    End date (ISO format)

Returns:



688
689
690
691
# File 'lib/sirv_rest_api/client.rb', line 688

def get_http_stats(from:, to:)
  response = request(:get, "/v2/stats/http", { from: from, to: to })
  response.map { |stat| HttpStats.new(stat) }
end

#get_points_of_interest(filename) ⇒ Array<PointOfInterest>

Get points of interest for a file

Parameters:

  • filename (String)

    File path

Returns:



653
654
655
656
# File 'lib/sirv_rest_api/client.rb', line 653

def get_points_of_interest(filename)
  response = request(:get, "/v2/files/poi", { filename: filename })
  response.map { |poi| PointOfInterest.new(poi) }
end

#get_product_meta(filename) ⇒ ProductMeta

Get product metadata

Parameters:

  • filename (String)

    File path

Returns:



500
501
502
503
# File 'lib/sirv_rest_api/client.rb', line 500

def get_product_meta(filename)
  response = request(:get, "/v2/files/meta/product", { filename: filename })
  ProductMeta.new(response)
end

#get_spin_views_stats(from:, to:) ⇒ Array<SpinViewStats>

Get spin views statistics (max 5-day range)

Parameters:

  • from (String)

    Start date (ISO format)

  • to (String)

    End date (ISO format)

Returns:



698
699
700
701
# File 'lib/sirv_rest_api/client.rb', line 698

def get_spin_views_stats(from:, to:)
  response = request(:get, "/v2/stats/spins/views", { from: from, to: to })
  response.map { |stat| SpinViewStats.new(stat) }
end

#get_storage_infoStorageInfo

Get storage usage information

Returns:



124
125
126
127
# File 'lib/sirv_rest_api/client.rb', line 124

def get_storage_info
  response = request(:get, "/v2/account/storage")
  StorageInfo.new(response)
end

#get_storage_stats(from:, to:) ⇒ Array<StorageStats>

Get storage statistics

Parameters:

  • from (String)

    Start date (ISO format)

  • to (String)

    End date (ISO format)

Returns:



708
709
710
711
# File 'lib/sirv_rest_api/client.rb', line 708

def get_storage_stats(from:, to:)
  response = request(:get, "/v2/stats/storage", { from: from, to: to })
  response.map { |stat| StorageStats.new(stat) }
end

#get_user_info(user_id: nil) ⇒ UserInfo

Get user information

Parameters:

  • user_id (String, nil) (defaults to: nil)

    User ID (optional, defaults to current user)

Returns:



171
172
173
174
175
# File 'lib/sirv_rest_api/client.rb', line 171

def (user_id: nil)
  params = user_id ? { userId: user_id } : {}
  response = request(:get, "/v2/user", params)
  UserInfo.new(response)
end

#get_zip_status(job_id) ⇒ BatchZipResult

Get ZIP job status

Parameters:

  • job_id (String)

    Job ID

Returns:



400
401
402
403
# File 'lib/sirv_rest_api/client.rb', line 400

def get_zip_status(job_id)
  response = request(:get, "/v2/files/zip/#{job_id}")
  BatchZipResult.new(response)
end

#mark_events_seen(event_ids) ⇒ void

This method returns an undefined value.

Mark events as seen

Parameters:

  • event_ids (Array<String>)

    Event IDs to mark as seen



158
159
160
161
# File 'lib/sirv_rest_api/client.rb', line 158

def mark_events_seen(event_ids)
  request(:post, "/v2/account/events/seen", event_ids)
  nil
end

#read_folder_contents(dirname, continuation: nil) ⇒ FolderContents

Read folder contents

Parameters:

  • dirname (String)

    Directory path

  • continuation (String, nil) (defaults to: nil)

    Continuation token for pagination

Returns:

  • (FolderContents)

    Folder contents with files and continuation token



195
196
197
198
199
200
# File 'lib/sirv_rest_api/client.rb', line 195

def read_folder_contents(dirname, continuation: nil)
  params = { dirname: dirname }
  params[:continuation] = continuation if continuation
  response = request(:get, "/v2/files/readdir", params)
  FolderContents.new(response)
end

#remove_file_tags(filename, tags) ⇒ void

This method returns an undefined value.

Remove tags from file

Parameters:

  • filename (String)

    File path

  • tags (Array<String>)

    Tags to remove



491
492
493
494
# File 'lib/sirv_rest_api/client.rb', line 491

def remove_file_tags(filename, tags)
  request(:delete, "/v2/files/meta/tags", { filename: filename, tags: tags })
  nil
end

#rename_file(from:, to:) ⇒ void

This method returns an undefined value.

Rename or move a file/folder

Parameters:

  • from (String)

    Current path

  • to (String)

    New path



368
369
370
371
# File 'lib/sirv_rest_api/client.rb', line 368

def rename_file(from:, to:)
  request(:post, "/v2/files/rename", { from: from, to: to })
  nil
end

#scroll_search(scroll_id) ⇒ SearchResult

Continue paginated search

Parameters:

  • scroll_id (String)

    Scroll ID from previous search

Returns:



250
251
252
253
# File 'lib/sirv_rest_api/client.rb', line 250

def scroll_search(scroll_id)
  response = request(:post, "/v2/files/search/scroll", { scrollId: scroll_id })
  SearchResult.new(response)
end

#search_events(params = {}) ⇒ Array<AccountEvent>

Search account events

Parameters:

  • params (Hash) (defaults to: {})

    Search parameters (module, type, level, filename, from, to)

Returns:



149
150
151
152
# File 'lib/sirv_rest_api/client.rb', line 149

def search_events(params = {})
  response = request(:post, "/v2/account/events/search", params)
  response.map { |event| AccountEvent.new(event) }
end

#search_files(params = {}) ⇒ SearchResult

Search files

Parameters:

  • params (Hash) (defaults to: {})

    Search parameters (query, from, size, sort, filters)

Returns:



241
242
243
244
# File 'lib/sirv_rest_api/client.rb', line 241

def search_files(params = {})
  response = request(:post, "/v2/files/search", params)
  SearchResult.new(response)
end

#set_approval_flag(filename, approved) ⇒ void

This method returns an undefined value.

Set approval flag

Parameters:

  • filename (String)

    File path

  • approved (Boolean)

    Approval status



530
531
532
533
# File 'lib/sirv_rest_api/client.rb', line 530

def set_approval_flag(filename, approved)
  request(:post, "/v2/files/meta/approval", { filename: filename, approved: approved })
  nil
end

#set_file_description(filename, description) ⇒ void

This method returns an undefined value.

Set file description

Parameters:

  • filename (String)

    File path

  • description (String)

    New description



462
463
464
465
# File 'lib/sirv_rest_api/client.rb', line 462

def set_file_description(filename, description)
  request(:post, "/v2/files/meta/description", { filename: filename, description: description })
  nil
end

#set_file_meta(filename, meta) ⇒ void

This method returns an undefined value.

Set file metadata

Parameters:

  • filename (String)

    File path

  • meta (Hash, FileMeta)

    Metadata to set



423
424
425
426
427
# File 'lib/sirv_rest_api/client.rb', line 423

def set_file_meta(filename, meta)
  body = meta.is_a?(FileMeta) ? meta.to_h : meta
  request(:post, "/v2/files/meta", { filename: filename }.merge(body))
  nil
end

#set_file_title(filename, title) ⇒ void

This method returns an undefined value.

Set file title

Parameters:

  • filename (String)

    File path

  • title (String)

    New title



443
444
445
446
# File 'lib/sirv_rest_api/client.rb', line 443

def set_file_title(filename, title)
  request(:post, "/v2/files/meta/title", { filename: filename, title: title })
  nil
end

#set_folder_options(dirname, options) ⇒ void

This method returns an undefined value.

Set folder options

Parameters:

  • dirname (String)

    Directory path

  • options (Hash)

    Folder options (scanSpins, allowListing)



232
233
234
235
# File 'lib/sirv_rest_api/client.rb', line 232

def set_folder_options(dirname, options)
  request(:post, "/v2/files/options", { dirname: dirname }.merge(options))
  nil
end

#set_point_of_interest(filename, poi) ⇒ void

This method returns an undefined value.

Set point of interest

Parameters:

  • filename (String)

    File path

  • poi (Hash, PointOfInterest)

    Point of interest data



663
664
665
666
667
# File 'lib/sirv_rest_api/client.rb', line 663

def set_point_of_interest(filename, poi)
  body = poi.is_a?(PointOfInterest) ? poi.to_h : poi
  request(:post, "/v2/files/poi", { filename: filename }.merge(body))
  nil
end

#set_product_meta(filename, meta) ⇒ void

This method returns an undefined value.

Set product metadata

Parameters:

  • filename (String)

    File path

  • meta (Hash, ProductMeta)

    Product metadata



510
511
512
513
514
# File 'lib/sirv_rest_api/client.rb', line 510

def set_product_meta(filename, meta)
  body = meta.is_a?(ProductMeta) ? meta.to_h : meta
  request(:post, "/v2/files/meta/product", { filename: filename }.merge(body))
  nil
end

#spin_to_video(filename, options: nil) ⇒ String

Convert spin to video

Parameters:

  • filename (String)

    Spin filename

  • options (Hash, nil) (defaults to: nil)

    Conversion options (width, height, loops, format)

Returns:

  • (String)

    Output video filename



562
563
564
565
566
567
# File 'lib/sirv_rest_api/client.rb', line 562

def spin_to_video(filename, options: nil)
  body = { filename: filename }
  body[:options] = options if options
  response = request(:post, "/v2/files/spin2video", body)
  response["filename"]
end

#update_account(options) ⇒ void

This method returns an undefined value.

Update account settings

Parameters:

  • options (Hash)

    Account update options



108
109
110
111
# File 'lib/sirv_rest_api/client.rb', line 108

def (options)
  request(:post, "/v2/account", options)
  nil
end

#upload_file(target_path, content, content_type: nil) ⇒ void

This method returns an undefined value.

Upload a file from content

Parameters:

  • target_path (String)

    Target path on Sirv

  • content (String)

    File content

  • content_type (String, nil) (defaults to: nil)

    Content type (optional)



301
302
303
304
# File 'lib/sirv_rest_api/client.rb', line 301

def upload_file(target_path, content, content_type: nil)
  upload_raw(target_path, content, content_type: content_type)
  nil
end

#upload_file_from_path(target_path, local_path, content_type: nil) ⇒ void

This method returns an undefined value.

Upload a file from local path

Parameters:

  • target_path (String)

    Target path on Sirv

  • local_path (String)

    Local file path

  • content_type (String, nil) (defaults to: nil)

    Content type (optional)



312
313
314
315
# File 'lib/sirv_rest_api/client.rb', line 312

def upload_file_from_path(target_path, local_path, content_type: nil)
  content = File.binread(local_path)
  upload_file(target_path, content, content_type: content_type)
end

#video_to_spin(filename, target_filename: nil, options: nil) ⇒ String

Convert video to spin

Parameters:

  • filename (String)

    Video filename

  • target_filename (String, nil) (defaults to: nil)

    Target spin filename

  • options (Hash, nil) (defaults to: nil)

    Conversion options (frames, start, duration)

Returns:

  • (String)

    Output spin filename



575
576
577
578
579
580
581
# File 'lib/sirv_rest_api/client.rb', line 575

def video_to_spin(filename, target_filename: nil, options: nil)
  body = { filename: filename }
  body[:targetFilename] = target_filename if target_filename
  body[:options] = options if options
  response = request(:post, "/v2/files/video2spin", body)
  response["filename"]
end