Class: Vimeo::VideosResource

Inherits:
Resource show all
Defined in:
lib/vimeo/resources/videos.rb

Instance Attribute Summary

Attributes inherited from Resource

#client

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Vimeo::Resource

Instance Method Details

#delete(id:) ⇒ Object



14
15
16
17
# File 'lib/vimeo/resources/videos.rb', line 14

def delete(id:)
  response = delete_request("videos/#{id}")
  return true if response.success
end

#edit(id:, **params) ⇒ Object



9
10
11
12
# File 'lib/vimeo/resources/videos.rb', line 9

def edit(id:, **params)
  response = patch_request("videos/#{id}", body: params)
  Video.new(response.body)
end

#retrieve(id:) ⇒ Object



4
5
6
7
# File 'lib/vimeo/resources/videos.rb', line 4

def retrieve(id:)
  response = get_request("videos/#{id}")
  Video.new(response.body)
end

#upload(file:, debug: false) ⇒ Object

Upload a new Video Uses the Resumable Upload feature - developer.vimeo.com/api/upload/videos#resumable-approach It splits the file up into 128MB chunks and uploads them until complete



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/vimeo/resources/videos.rb', line 22

def upload(file:, debug: false)
  tus = post_request("me/videos", body: {upload: {approach: 'tus', size: file.size.to_s}})

  headers = {'Content-Type' => 'application/offset+octet-stream'}
  headers['Tus-Resumable'] = '1.0.0'
  headers['Upload-Offset'] = '0'
  file.rewind

  # 128MB
  split = 128000000

  begin
    video_content = file.read(split)
    @response = patch_request(tus.body["upload"]["upload_link"], body: video_content, headers: headers)
    
    offset = @response.headers['upload-offset']
    headers['Upload-Offset'] = offset 
    
    if debug
      puts "* #{offset}/#{file.size}"
    end
  end while offset.to_i != file.size

  Video.new(tus.body)
end