Class: SirvRestApi::Client
- Inherits:
-
Object
- Object
- SirvRestApi::Client
- 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
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#access_token ⇒ String?
Get the current access token.
-
#add_file_tags(filename, tags) ⇒ void
Add tags to file.
-
#batch_delete(filenames) ⇒ BatchDeleteResult
Delete multiple files/folders.
-
#batch_zip(filenames:, filename:) ⇒ BatchZipResult
Create ZIP archive from multiple files.
-
#connect(expires_in: nil) ⇒ TokenResponse
Authenticate and obtain a bearer token.
-
#connected? ⇒ Boolean
Check if client is connected with a valid token.
-
#copy_file(from:, to:) ⇒ void
Copy a file.
-
#create_folder(dirname) ⇒ void
Create a new folder.
-
#delete_file(filename) ⇒ void
Delete a file or empty folder.
-
#delete_point_of_interest(filename, name) ⇒ void
Delete point of interest.
-
#download_file(filename) ⇒ String
Download a file.
-
#download_file_to(filename, local_path) ⇒ void
Download a file to local path.
-
#each_folder_item(dirname) {|FileInfo| ... } ⇒ Enumerator
Iterate through all items in a folder (handles pagination automatically).
-
#each_search_result(params = {}) {|FileInfo| ... } ⇒ Enumerator
Iterate through all search results (handles pagination automatically).
-
#export_spin_to_amazon(filename:, asin: nil, product_id: nil) ⇒ void
Export spin to Amazon.
-
#export_spin_to_grainger(filename:, product_id: nil) ⇒ void
Export spin to Grainger.
-
#export_spin_to_home_depot(filename:, product_id: nil) ⇒ void
Export spin to Home Depot.
-
#export_spin_to_lowes(filename:, product_id: nil) ⇒ void
Export spin to Lowe’s.
-
#export_spin_to_walmart(filename:, product_id: nil) ⇒ void
Export spin to Walmart.
-
#fetch_url(url:, filename:, wait: nil) ⇒ void
Fetch file from external URL.
-
#generate_jwt(filename:, expires_in: nil, secure_params: nil) ⇒ JwtResponse
Generate JWT protected URL.
-
#get_account_info ⇒ AccountInfo
Get account information.
-
#get_account_limits ⇒ AccountLimits
Get API rate limits.
-
#get_account_users ⇒ Array<AccountUser>
Get all account users.
-
#get_approval_flag(filename) ⇒ Boolean
Get approval flag.
-
#get_batch_delete_status(job_id) ⇒ BatchDeleteResult
Get batch delete job status.
-
#get_billing_plan ⇒ BillingPlan
Get billing plan details.
-
#get_file_description(filename) ⇒ String
Get file description.
-
#get_file_info(filename) ⇒ FileInfo
Get file information.
-
#get_file_meta(filename) ⇒ FileMeta
Get all file metadata.
-
#get_file_tags(filename) ⇒ Array<String>
Get file tags.
-
#get_file_title(filename) ⇒ String
Get file title.
-
#get_folder_options(dirname) ⇒ Hash
Get folder options.
-
#get_http_stats(from:, to:) ⇒ Array<HttpStats>
Get HTTP transfer statistics.
-
#get_points_of_interest(filename) ⇒ Array<PointOfInterest>
Get points of interest for a file.
-
#get_product_meta(filename) ⇒ ProductMeta
Get product metadata.
-
#get_spin_views_stats(from:, to:) ⇒ Array<SpinViewStats>
Get spin views statistics (max 5-day range).
-
#get_storage_info ⇒ StorageInfo
Get storage usage information.
-
#get_storage_stats(from:, to:) ⇒ Array<StorageStats>
Get storage statistics.
-
#get_user_info(user_id: nil) ⇒ UserInfo
Get user information.
-
#get_zip_status(job_id) ⇒ BatchZipResult
Get ZIP job status.
-
#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
constructor
Initialize a new Sirv API client.
-
#mark_events_seen(event_ids) ⇒ void
Mark events as seen.
-
#read_folder_contents(dirname, continuation: nil) ⇒ FolderContents
Read folder contents.
-
#remove_file_tags(filename, tags) ⇒ void
Remove tags from file.
-
#rename_file(from:, to:) ⇒ void
Rename or move a file/folder.
-
#scroll_search(scroll_id) ⇒ SearchResult
Continue paginated search.
-
#search_events(params = {}) ⇒ Array<AccountEvent>
Search account events.
-
#search_files(params = {}) ⇒ SearchResult
Search files.
-
#set_approval_flag(filename, approved) ⇒ void
Set approval flag.
-
#set_file_description(filename, description) ⇒ void
Set file description.
-
#set_file_meta(filename, meta) ⇒ void
Set file metadata.
-
#set_file_title(filename, title) ⇒ void
Set file title.
-
#set_folder_options(dirname, options) ⇒ void
Set folder options.
-
#set_point_of_interest(filename, poi) ⇒ void
Set point of interest.
-
#set_product_meta(filename, meta) ⇒ void
Set product metadata.
-
#spin_to_video(filename, options: nil) ⇒ String
Convert spin to video.
-
#update_account(options) ⇒ void
Update account settings.
-
#upload_file(target_path, content, content_type: nil) ⇒ void
Upload a file from content.
-
#upload_file_from_path(target_path, local_path, content_type: nil) ⇒ void
Upload a file from local path.
-
#video_to_spin(filename, target_filename: nil, options: nil) ⇒ String
Convert video to spin.
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
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
#config ⇒ Object (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_token ⇒ String?
Get the current access token
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
481 482 483 484 |
# File 'lib/sirv_rest_api/client.rb', line 481 def (filename, ) request(:post, "/v2/files/meta/tags", { filename: filename, tags: }) nil end |
#batch_delete(filenames) ⇒ BatchDeleteResult
Delete multiple files/folders
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
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
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
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
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
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
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
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
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
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)
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)
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
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
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
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
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
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
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
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_info ⇒ AccountInfo
Get account information
99 100 101 102 |
# File 'lib/sirv_rest_api/client.rb', line 99 def get_account_info response = request(:get, "/v2/account") AccountInfo.new(response) end |
#get_account_limits ⇒ AccountLimits
Get API rate limits
116 117 118 119 |
# File 'lib/sirv_rest_api/client.rb', line 116 def get_account_limits response = request(:get, "/v2/account/limits") AccountLimits.new(response) end |
#get_account_users ⇒ Array<AccountUser>
Get all account users
132 133 134 135 |
# File 'lib/sirv_rest_api/client.rb', line 132 def get_account_users response = request(:get, "/v2/account/users") response.map { |user| AccountUser.new(user) } end |
#get_approval_flag(filename) ⇒ Boolean
Get approval flag
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
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_plan ⇒ BillingPlan
Get billing plan details
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
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
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
413 414 415 416 |
# File 'lib/sirv_rest_api/client.rb', line 413 def (filename) response = request(:get, "/v2/files/meta", { filename: filename }) FileMeta.new(response) end |
#get_file_tags(filename) ⇒ Array<String>
Get file tags
471 472 473 474 |
# File 'lib/sirv_rest_api/client.rb', line 471 def (filename) response = request(:get, "/v2/files/meta/tags", { filename: filename }) response["tags"] || [] end |
#get_file_title(filename) ⇒ String
Get 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
223 224 225 |
# File 'lib/sirv_rest_api/client.rb', line 223 def (dirname) request(:get, "/v2/files/options", { dirname: dirname }) end |
#get_http_stats(from:, to:) ⇒ Array<HttpStats>
Get HTTP transfer statistics
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
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
500 501 502 503 |
# File 'lib/sirv_rest_api/client.rb', line 500 def (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)
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_info ⇒ StorageInfo
Get storage usage information
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
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
171 172 173 174 175 |
# File 'lib/sirv_rest_api/client.rb', line 171 def get_user_info(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
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
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
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
491 492 493 494 |
# File 'lib/sirv_rest_api/client.rb', line 491 def (filename, ) request(:delete, "/v2/files/meta/tags", { filename: filename, tags: }) nil end |
#rename_file(from:, to:) ⇒ void
This method returns an undefined value.
Rename or move a file/folder
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
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
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
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
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
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
423 424 425 426 427 |
# File 'lib/sirv_rest_api/client.rb', line 423 def (filename, ) body = .is_a?(FileMeta) ? .to_h : 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
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
232 233 234 235 |
# File 'lib/sirv_rest_api/client.rb', line 232 def (dirname, ) request(:post, "/v2/files/options", { dirname: dirname }.merge()) nil end |
#set_point_of_interest(filename, poi) ⇒ void
This method returns an undefined value.
Set point of interest
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
510 511 512 513 514 |
# File 'lib/sirv_rest_api/client.rb', line 510 def (filename, ) body = .is_a?(ProductMeta) ? .to_h : request(:post, "/v2/files/meta/product", { filename: filename }.merge(body)) nil end |
#spin_to_video(filename, options: nil) ⇒ String
Convert spin to video
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] = if response = request(:post, "/v2/files/spin2video", body) response["filename"] end |
#update_account(options) ⇒ void
This method returns an undefined value.
Update account settings
108 109 110 111 |
# File 'lib/sirv_rest_api/client.rb', line 108 def update_account() request(:post, "/v2/account", ) nil end |
#upload_file(target_path, content, content_type: nil) ⇒ void
This method returns an undefined value.
Upload a file from content
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
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
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] = if response = request(:post, "/v2/files/video2spin", body) response["filename"] end |