Module: GoogleDrive::Util

Included in:
Acl, AclEntry, Collection, File, Record, Session, Session, Spreadsheet, Table, Worksheet
Defined in:
lib/google_drive/util.rb

Overview

:nodoc:

Constant Summary collapse

DOCS_BASE_URL =

The beginning of Doc List API URL that is used in all requests (version 3).

"https://docs.google.com/feeds/default/private/full"
EXT_TO_CONTENT_TYPE =
{
    ".csv" =>"text/csv",
    ".tsv" =>"text/tab-separated-values",
    ".tab" =>"text/tab-separated-values",
    ".doc" =>"application/msword",
    ".docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
    ".ods" =>"application/x-vnd.oasis.opendocument.spreadsheet",
    ".odt" =>"application/vnd.oasis.opendocument.text",
    ".rtf" =>"application/rtf",
    ".sxw" =>"application/vnd.sun.xml.writer",
    ".txt" =>"text/plain",
    ".xls" =>"application/vnd.ms-excel",
    ".xlsx" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    ".pdf" =>"application/pdf",
    ".png" =>"image/png",
    ".ppt" =>"application/vnd.ms-powerpoint",
    ".pps" =>"application/vnd.ms-powerpoint",
    ".htm" =>"text/html",
    ".html" =>"text/html",
    ".zip" =>"application/zip",
    ".swf" =>"application/x-shockwave-flash",
}

Class Method Summary collapse

Class Method Details

.concat_url(url, piece) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/google_drive/util.rb', line 43

def concat_url(url, piece)
  (url_base, url_query) = url.split(/\?/, 2)
  (piece_base, piece_query) = piece.split(/\?/, 2)
  result_query = [url_query, piece_query].select(){ |s| s && !s.empty? }.join("&")
  return (url_base || "") +
      (piece_base || "") +
      (result_query.empty? ? "" : "?#{result_query}")
end

.encode_query(params) ⇒ Object



39
40
41
# File 'lib/google_drive/util.rb', line 39

def encode_query(params)
  return params.map(){ |k, v| CGI.escape(k.to_s()) + "=" + CGI.escape(v.to_s()) }.join("&")
end

.h(str) ⇒ Object



61
62
63
64
# File 'lib/google_drive/util.rb', line 61

def h(str)
  # Should also escape "\n" to keep it in cell contents.
  return CGI.escapeHTML(str.to_s()).gsub(/\n/, '
')
end

.to_v3_url(url) ⇒ Object

Returns a URL with added version parameter (“?v=3”) if needed.



53
54
55
56
57
58
59
# File 'lib/google_drive/util.rb', line 53

def to_v3_url(url)
  if url =~ %r{docs.google.com/feeds/default/private/} && !(url =~ /[?&]v=3/)
    return concat_url(url, "?v=3")
  else
    return url
  end
end