Module: Fog::Google::Storage::Utils

Included in:
Mock, Real
Defined in:
lib/fog/storage/google.rb

Instance Method Summary collapse

Instance Method Details

#parse_data(data) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fog/storage/google.rb', line 34

def parse_data(data)
   = {
    :body => nil,
    :headers => {}
  }

  if data.is_a?(String)
    [:body] = data
    [:headers]['Content-Length'] = [:body].size
  else
    filename = ::File.basename(data.path)
    unless (mime_types = MIME::Types.of(filename)).empty?
      [:headers]['Content-Type'] = mime_types.first.content_type
    end
    [:body] = data
    [:headers]['Content-Length'] = ::File.size(data.path)
  end
  # metadata[:headers]['Content-MD5'] = Base64.encode64(Digest::MD5.digest(metadata[:body])).strip
  
end

#url(params, expires) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/fog/storage/google.rb', line 55

def url(params, expires)
  params[:headers]['Date'] = expires.to_i
  params[:path] = CGI.escape(params[:path]).gsub('%2F', '/')
  query = [params[:query]].compact
  query << "GoogleAccessKeyId=#{@google_storage_access_key_id}"
  query << "Signature=#{CGI.escape(signature(params))}"
  query << "Expires=#{params[:headers]['Date']}"
  "http://#{params[:host]}/#{params[:path]}?#{query.join('&')}"
end