Class: GDocsAPIWrapper::Client::GDocsClient
- Inherits:
-
Object
- Object
- GDocsAPIWrapper::Client::GDocsClient
- Defined in:
- lib/gdocsapi-wrapper/client/client.rb
Instance Attribute Summary collapse
-
#login_handler ⇒ Object
Returns the value of attribute login_handler.
-
#source ⇒ Object
Identifying the application which uses the GDocsAPIWrapper.
Instance Method Summary collapse
- #base_headers ⇒ Object
-
#initialize(options = {}) ⇒ GDocsClient
constructor
A new instance of GDocsClient.
-
#list_documents(options = {}) ⇒ Object
Get a list of documents, possible options: :type => :all, :word, :spreadsheet, :presentation and :filter => :none, :starred, :trashed.
-
#list_folders ⇒ Object
Get a list of folders.
- #loggedin? ⇒ Boolean
-
#login(username, password) ⇒ Object
Performs login on GDocsAPIWrapper:Auth.
Constructor Details
#initialize(options = {}) ⇒ GDocsClient
Returns a new instance of GDocsClient.
32 33 34 35 36 37 38 39 |
# File 'lib/gdocsapi-wrapper/client/client.rb', line 32 def initialize( = {}) .each do |key, value| self.send("#{key}=", value) end @source ||= 'UndefinedApplication' @login_handler = GDocsAPIWrapper::Auth::Login.new end |
Instance Attribute Details
#login_handler ⇒ Object
Returns the value of attribute login_handler.
30 31 32 |
# File 'lib/gdocsapi-wrapper/client/client.rb', line 30 def login_handler @login_handler end |
#source ⇒ Object
Identifying the application which uses the GDocsAPIWrapper
29 30 31 |
# File 'lib/gdocsapi-wrapper/client/client.rb', line 29 def source @source end |
Instance Method Details
#base_headers ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/gdocsapi-wrapper/client/client.rb', line 89 def base_headers headers = Hash.new if loggedin? headers['Authorization'] = 'GoogleLogin auth=' + @login_handler.token end return headers end |
#list_documents(options = {}) ⇒ Object
Get a list of documents, possible options: :type => :all, :word, :spreadsheet, :presentation and :filter => :none, :starred, :trashed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/gdocsapi-wrapper/client/client.rb', line 49 def list_documents( = {}) [:type] ||= :all [:filter] ||= :none # login required to call this function raise LoginRequiredError.new unless loggedin? request = GDocsAPIWrapper::HTTP::Request.new(GDocsAPIWrapper::Client::Service.get(:documents, :type => [:type], :filter => [:filter]), :method => :get, :headers => base_headers) response = request.send_request documents = Array.new doc = REXML::Document.new(response.body) doc.elements.each("/feed/entry") do |entry| documents << GDocsAPIWrapper::Models::Document.parse(entry) end return documents end |
#list_folders ⇒ Object
Get a list of folders
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/gdocsapi-wrapper/client/client.rb', line 69 def list_folders # login required to call this function raise LoginRequiredError.new unless loggedin? request = GDocsAPIWrapper::HTTP::Request.new(GDocsAPIWrapper::Client::Service.get(:folders), :method => :get, :headers => base_headers) response = request.send_request folders = Array.new doc = REXML::Document.new(response.body) doc.elements.each("/feed/entry") do |entry| folders << GDocsAPIWrapper::Models::Folder.parse(entry) end return folders end |
#loggedin? ⇒ Boolean
85 86 87 |
# File 'lib/gdocsapi-wrapper/client/client.rb', line 85 def loggedin? return !(@login_handler.token.nil?) end |
#login(username, password) ⇒ Object
Performs login on GDocsAPIWrapper:Auth
42 43 44 45 46 |
# File 'lib/gdocsapi-wrapper/client/client.rb', line 42 def login(username, password) source = GDocsAPIWrapper::Auth::SOURCE_PREFIX + @source @login_handler.perform_login(username, password, source) end |