Sha256: 20bdcde63d80aa55017846707e8e76ea7adfb92d291ce48da1f6069747dc4bb4

Contents?: true

Size: 827 Bytes

Versions: 1

Compression:

Stored size: 827 Bytes

Contents

module Pige::Client
  class Chunk < Resource

    attr_accessor :begin, :completion_rate, :end, :format, :title
    time_attribute :begin, :end

    def completion_rate
      response = self.class.get("#{Pige::Client.box_url}/sources/1/chunks/#{id}.json")
      if response.code == 200
        response["completion_rate"].to_f
      end
    end

    def extension
      format == "vorbis" ? "ogg" : format
    end

    def download_url
      "#{Pige::Client.box_url}/sources/1/chunks/#{id}.#{extension}"
    end

    def download_file
      "#{title}.#{extension}"
    end

    def download(target)
      target_file = File.join(target, download_file)

      File.open(target_file, "w") do |file|
        open(download_url) do |url|
          IO.copy_stream url, file
        end
      end

      target_file
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tryphon-pige-client-1.0.3 lib/pige/client/chunk.rb