Sha256: 11d0e88b2f2d80f3b43b6e0cbab420086c93445899bc2047e827bbd65d69940a

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

module VzaarApi
  module Strategy
    module Video
      class Create

        attr_reader :attrs, :video_class

        def initialize(attrs, video_class)
          @attrs = attrs
          @video_class = video_class
        end

        def execute
          case
          when attrs.has_key?(:guid)
            create_from_guid
          when attrs.has_key?(:path)
            create_from_path
          when attrs.has_key?(:url)
            create_from_url
          else
            raise Error.new('Invalid parameters: Expected one of :guid, :path, :url')
          end
        end

        private

        def create_from_guid
          url = Lib::Api.resource_url video_class::ENDPOINT
          video_class.new Lib::Api.new.post(url, attrs).data
        end

        def create_from_path
          signature = Signature::Factory.create(attrs)
          upload_attrs = Upload::S3.new(attrs, signature).execute
          video_class.create upload_attrs
        end

        def create_from_url
          LinkUpload.create(attrs.merge({ uploader: UPLOADER }))
        end

      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vzaar_api-2.0.2 lib/vzaar_api/strategy/video/create.rb
vzaar_api-2.0.1 lib/vzaar_api/strategy/video/create.rb
vzaar_api-2.0.0 lib/vzaar_api/strategy/video/create.rb