views:

84

answers:

0

I have a simple rack app that's designed to marshal data from Rackspace CloudFiles, however it doesn't seem to be working.

I'm a complete noob when it comes to rack, so I'm hoping someone can show me the follies of my ways.

require 'rubygems'
require 'cloudfiles'

class StreamingFile
  def initialize(id)
    user = "<CLOUDFILES USERNAME HERE>"
    api = "<API KEY REMOVED>"
    conn = CloudFiles::Connection.new(user, api)
    cn = conn.container("container")
    @file = CloudFiles::StorageObject.new(cn, id, true)
  end

  def length
    @file.bytes.size
  end

  def each
    @file.data_stream do |chunk|
      yield chunk
    end
  end
end

app = lambda { |env| 
  file = StreamingFile.new("6cf72a1855a302f1e65c2cd9ef15bb6e25e1d27c228728597247e9b35e4a75c0")
  [200, {'Content-Type' => "audio/mpeg", "Transfer-Encoding" => "chunked", "Content-Length" => file.length.to_s, "Connection" => "keep-alive"}, file]}

run app