Sha256: d0aadb13d4e1b5bf3e5dc49eac8a20c45b805b0e3ac1daa9f0e08adda03f6c05

Contents?: true

Size: 887 Bytes

Versions: 2

Compression:

Stored size: 887 Bytes

Contents

module VzaarApi
  module Strategy
    module Subtitle
      class Create
        attr_reader :video_id, :attrs, :klass

        def initialize(video_id, attrs, klass)
          @attrs = attrs
          @video_id = video_id
          @klass = klass
        end

        def execute
          res = attrs[:file] ? create_from_file : Lib::Api.new.post(url, attrs)
          klass.new res.data.merge(scope_id: video_id)
        end

        private

        def create_from_file
          File.open(attrs[:file], "r") do |file|
            Lib::Api.new.post(url, attrs.merge(file: file)) do |body, headers|
              headers.delete('Content-Type')
              [body, headers]
            end
          end
        end

        def url
          path = VzaarApi::Video::Subtitle::ENDPOINT.call(video_id, nil)
          Lib::Api.resource_url path
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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