Module: GoogleDriveV0::Util

Included in:
Acl, AclEntry, Collection, File, Record, Session, Session, Spreadsheet, Table, Worksheet
Defined in:
lib/google_drive_v0/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



48
49
50
51
52
53
54
55
# File 'lib/google_drive_v0/util.rb', line 48

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
42
43
44
45
46
# File 'lib/google_drive_v0/util.rb', line 39

def encode_query(params)
  for k, v in params
    if ["ocr", "targetLanguage", "sourceLanguage"].include?(k.to_s())
      warn("WARNING: Parameter '%s' is deprecated, and will not work in the next version." % k)
    end
  end
  return params.map(){ |k, v| CGI.escape(k.to_s()) + "=" + CGI.escape(v.to_s()) }.join("&")
end

.h(str) ⇒ Object



66
67
68
69
# File 'lib/google_drive_v0/util.rb', line 66

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.



58
59
60
61
62
63
64
# File 'lib/google_drive_v0/util.rb', line 58

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