Sha256: 6f97b3906bd3a0c9be0e60509cf4eaa86a2e13094b41173d9aab738844817038

Contents?: true

Size: 1.81 KB

Versions: 2

Compression:

Stored size: 1.81 KB

Contents

require 'httpclient'
require 'json'

module Vimeo
  module Advanced

    class Upload < Vimeo::Advanced::Base

      # TODO: Make this work with either a JSON or an XML manifest.
      # Confirms the upload process.
      create_api_method :confirm,
                        "vimeo.videos.upload.confirm",
                        :required => [:ticket_id]
      
      # "{\"files\":[{\"md5\":\"731f09145a1ea9ec9dad689de6fa0358\"}]}"

      # Returns the space and HD uploads left for a user.
      create_api_method :get_quota,
                        "vimeo.videos.upload.getQuota"
                        
      # Returns an upload ticket.
      create_api_method :get_ticket,
                        "vimeo.videos.upload.getTicket"

      # Upload +file+ to vimeo with +ticket_id+ and +auth_token+
      # Returns the json manifest necessary to confirm the upload.
      def upload(auth_token, file_path, ticket_id, end_point)
        params = {
          :auth_token => auth_token,
          :ticket_id  => ticket_id
        }
        params[:api_sig] = generate_api_sig params
        
        params.merge!({ :file_data => File.open(file_path) })
        
        client = HTTPClient.new
        response = client.post(end_point, params)
        md5 = response.content

        self.class.create_json_manifest(md5)
      end

      # TODO: Make this work with either json or xml manifest.
      # FIXME: Ticket id is required?
      # Verifies a file manifest.
      create_api_method :verify_manifest,
                        "vimeo.videos.upload.verifyManifest",
                        :required => [:auth_token, :ticket_id]

      # TODO: Make this more flexible for split uploads?
      def self.create_json_manifest(md5s)
        { :files => md5s.map { |md5| { :md5 => md5 } } }.to_json
      end

    end # Upload
  end # Advanced
end # Vimeo

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vimeo-1.2.0 lib/vimeo/advanced/upload.rb
vimeo-1.1.0 lib/vimeo/advanced/upload.rb