chdorner-gdocsapi-wrapper 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,10 +3,16 @@ History.txt
3
3
  lib/gdocsapi-wrapper/auth/login.rb
4
4
  lib/gdocsapi-wrapper/auth.rb
5
5
  lib/gdocsapi-wrapper/base.rb
6
+ lib/gdocsapi-wrapper/client/client.rb
7
+ lib/gdocsapi-wrapper/client/service.rb
6
8
  lib/gdocsapi-wrapper/client.rb
7
9
  lib/gdocsapi-wrapper/http/request.rb
8
10
  lib/gdocsapi-wrapper/http/response.rb
9
11
  lib/gdocsapi-wrapper/http.rb
12
+ lib/gdocsapi-wrapper/models/author.rb
13
+ lib/gdocsapi-wrapper/models/document.rb
14
+ lib/gdocsapi-wrapper/models/folder.rb
15
+ lib/gdocsapi-wrapper/models.rb
10
16
  lib/gdocsapi-wrapper.rb
11
17
  Manifest.txt
12
18
  PostInstall.txt
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{gdocsapi-wrapper}
5
- s.version = "0.0.3"
5
+ s.version = "0.0.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Christof Dorner"]
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.description = %q{A Ruby wrapper around the Google Documents List Data API}
11
11
  s.email = ["christof@chdorner.com"]
12
12
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt"]
13
- s.files = ["gdocsapi-wrapper.gemspec", "History.txt", "lib/gdocsapi-wrapper/auth/login.rb", "lib/gdocsapi-wrapper/auth.rb", "lib/gdocsapi-wrapper/base.rb", "lib/gdocsapi-wrapper/client.rb", "lib/gdocsapi-wrapper/http/request.rb", "lib/gdocsapi-wrapper/http/response.rb", "lib/gdocsapi-wrapper/http.rb", "lib/gdocsapi-wrapper.rb", "Manifest.txt", "PostInstall.txt", "Rakefile", "README.rdoc", "test/test_gdocsapi-wrapper.rb", "test/test_helper.rb"]
13
+ s.files = ["gdocsapi-wrapper.gemspec", "History.txt", "lib/gdocsapi-wrapper/auth/login.rb", "lib/gdocsapi-wrapper/auth.rb", "lib/gdocsapi-wrapper/base.rb", "lib/gdocsapi-wrapper/client/client.rb", "lib/gdocsapi-wrapper/client/service.rb", "lib/gdocsapi-wrapper/client.rb", "lib/gdocsapi-wrapper/http/request.rb", "lib/gdocsapi-wrapper/http/response.rb", "lib/gdocsapi-wrapper/http.rb", "lib/gdocsapi-wrapper/models/author.rb", "lib/gdocsapi-wrapper/models/document.rb", "lib/gdocsapi-wrapper/models/folder.rb", "lib/gdocsapi-wrapper/models.rb", "lib/gdocsapi-wrapper.rb", "Manifest.txt", "PostInstall.txt", "Rakefile", "README.rdoc", "test/test_gdocsapi-wrapper.rb", "test/test_helper.rb"]
14
14
  s.homepage = %q{http://github.com/chdorner/gdocs-wrapper}
15
15
  s.post_install_message = %q{PostInstall.txt}
16
16
  s.rdoc_options = ["--main", "README.rdoc"]
@@ -29,5 +29,5 @@ require 'gdocsapi-wrapper/client'
29
29
  require 'gdocsapi-wrapper/models'
30
30
 
31
31
  module GDocsAPIWrapper
32
- VERSION = '0.0.3'
32
+ VERSION = '0.0.4'
33
33
  end
@@ -41,4 +41,7 @@ module GDocsAPIWrapper
41
41
  class LoginRequiredError < Error
42
42
  end
43
43
 
44
+ class ServiceNotFoundError < Error
45
+ end
46
+
44
47
  end
@@ -0,0 +1,98 @@
1
+ # Copyright (c) 2009 Christof Dorner
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # 'Software'), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'rexml/document'
23
+
24
+ module GDocsAPIWrapper
25
+ module Client
26
+ class GDocsClient
27
+
28
+ # Identifying the application which uses the GDocsAPIWrapper
29
+ attr_accessor :source
30
+ attr_accessor :login_handler
31
+
32
+ def initialize(options = {})
33
+ options.each do |key, value|
34
+ self.send("#{key}=", value)
35
+ end
36
+
37
+ @source ||= 'UndefinedApplication'
38
+ @login_handler = GDocsAPIWrapper::Auth::Login.new
39
+ end
40
+
41
+ # Performs login on GDocsAPIWrapper:Auth
42
+ def login(username, password)
43
+ source = GDocsAPIWrapper::Auth::SOURCE_PREFIX + @source
44
+
45
+ @login_handler.perform_login(username, password, source)
46
+ end
47
+
48
+ # Get a list of documents, possible options: :type => :all, :word, :spreadsheet, :presentation and :filter => :none, :starred, :trashed
49
+ def list_documents(options = {})
50
+ options[:type] ||= :all
51
+ options[:filter] ||= :none
52
+
53
+ # login required to call this function
54
+ raise LoginRequiredError.new unless loggedin?
55
+
56
+ request = GDocsAPIWrapper::HTTP::Request.new(GDocsAPIWrapper::Client::Service.get(:documents, :type => options[:type], :filter => options[:filter]), :method => :get, :headers => base_headers)
57
+ response = request.send_request
58
+
59
+ documents = Array.new
60
+ doc = REXML::Document.new(response.body)
61
+ doc.elements.each("/feed/entry") do |entry|
62
+ documents << GDocsAPIWrapper::Models::Document.parse(entry)
63
+ end
64
+
65
+ return documents
66
+ end
67
+
68
+ # Get a list of folders
69
+ def list_folders
70
+ # login required to call this function
71
+ raise LoginRequiredError.new unless loggedin?
72
+
73
+ request = GDocsAPIWrapper::HTTP::Request.new(GDocsAPIWrapper::Client::Service.get(:folders), :method => :get, :headers => base_headers)
74
+ response = request.send_request
75
+
76
+ folders = Array.new
77
+ doc = REXML::Document.new(response.body)
78
+ doc.elements.each("/feed/entry") do |entry|
79
+ folders << GDocsAPIWrapper::Models::Folder.parse(entry)
80
+ end
81
+
82
+ return folders
83
+ end
84
+
85
+ def loggedin?
86
+ return !(@login_handler.token.nil?)
87
+ end
88
+
89
+ def base_headers
90
+ headers = Hash.new
91
+ if loggedin?
92
+ headers['Authorization'] = 'GoogleLogin auth=' + @login_handler.token
93
+ end
94
+ return headers
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,68 @@
1
+ # Copyright (c) 2009 Christof Dorner
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # 'Software'), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ module GDocsAPIWrapper
23
+ module Client
24
+ class Service
25
+
26
+ @@base_uri = 'https://docs.google.com'
27
+ @@documents = '/feeds/documents/private/full'
28
+ @@folders = '/feeds/documents/private/full/-/folder?showfolders=true'
29
+
30
+ def self.get(object, options = {})
31
+ case object
32
+ when :documents
33
+ uri = @@base_uri + @@documents
34
+
35
+ # process types
36
+ case options[:type]
37
+ when :word
38
+ uri += '/-/document'
39
+ when :spreadsheet
40
+ uri += '/-/spreadsheet'
41
+ when :presentation
42
+ uri += '/-/presentation'
43
+ end
44
+
45
+ #process filters
46
+ case options[:filter]
47
+ when :starred
48
+ if options[:type] == :all
49
+ uri += '/-'
50
+ end
51
+ uri += '/starred'
52
+ when :trashed
53
+ if options[:type] == :all
54
+ uri += '/-'
55
+ end
56
+ uri += '/trashed'
57
+ end
58
+ return uri
59
+
60
+ when :folders
61
+ return @@base_uri + '/feeds/documents/private/full/-/folder?showfolders=true'
62
+ else
63
+ raise ServiceNotFoundError.new
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,24 @@
1
+ # Copyright (c) 2009 Christof Dorner
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # 'Software'), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'gdocsapi-wrapper/models/document'
23
+ require 'gdocsapi-wrapper/models/author'
24
+ require 'gdocsapi-wrapper/models/folder'
@@ -0,0 +1,38 @@
1
+ # Copyright (c) 2009 Christof Dorner
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # 'Software'), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ module GDocsAPIWrapper
23
+ module Models
24
+ class Author
25
+ attr_accessor :name
26
+ attr_accessor :email
27
+
28
+ def self.parse(element)
29
+ author = GDocsAPIWrapper::Models::Author.new
30
+
31
+ author.name = element.elements['name'].text
32
+ author.email = element.elements['email'].text
33
+
34
+ return author
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,46 @@
1
+ # Copyright (c) 2009 Christof Dorner
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # 'Software'), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'date'
23
+
24
+ module GDocsAPIWrapper
25
+ module Models
26
+ class Document
27
+ attr_accessor :title
28
+ attr_accessor :published
29
+ attr_accessor :updated
30
+ attr_accessor :link
31
+ attr_accessor :author
32
+
33
+ def self.parse(element)
34
+ document = GDocsAPIWrapper::Models::Document.new
35
+
36
+ document.title = element.elements['title'].text
37
+ document.published = DateTime.parse(element.elements['published'].text)
38
+ document.updated = DateTime.parse(element.elements['updated'].text)
39
+ document.link = element.elements['link[@rel="alternate"]'].attributes['href']
40
+ document.author = GDocsAPIWrapper::Models::Author.parse(element.elements['author'])
41
+
42
+ return document
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,46 @@
1
+ # Copyright (c) 2009 Christof Dorner
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # 'Software'), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'date'
23
+
24
+ module GDocsAPIWrapper
25
+ module Models
26
+ class Folder
27
+ attr_accessor :title
28
+ attr_accessor :published
29
+ attr_accessor :updated
30
+ attr_accessor :link
31
+ attr_accessor :author
32
+
33
+ def self.parse(element)
34
+ document = GDocsAPIWrapper::Models::Document.new
35
+
36
+ document.title = element.elements['title'].text
37
+ document.published = DateTime.parse(element.elements['published'].text)
38
+ document.updated = DateTime.parse(element.elements['updated'].text)
39
+ document.link = element.elements['link[@rel="alternate"]'].attributes['href']
40
+ document.author = GDocsAPIWrapper::Models::Author.parse(element.elements['author'])
41
+
42
+ return document
43
+ end
44
+ end
45
+ end
46
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chdorner-gdocsapi-wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christof Dorner
@@ -39,10 +39,16 @@ files:
39
39
  - lib/gdocsapi-wrapper/auth/login.rb
40
40
  - lib/gdocsapi-wrapper/auth.rb
41
41
  - lib/gdocsapi-wrapper/base.rb
42
+ - lib/gdocsapi-wrapper/client/client.rb
43
+ - lib/gdocsapi-wrapper/client/service.rb
42
44
  - lib/gdocsapi-wrapper/client.rb
43
45
  - lib/gdocsapi-wrapper/http/request.rb
44
46
  - lib/gdocsapi-wrapper/http/response.rb
45
47
  - lib/gdocsapi-wrapper/http.rb
48
+ - lib/gdocsapi-wrapper/models/author.rb
49
+ - lib/gdocsapi-wrapper/models/document.rb
50
+ - lib/gdocsapi-wrapper/models/folder.rb
51
+ - lib/gdocsapi-wrapper/models.rb
46
52
  - lib/gdocsapi-wrapper.rb
47
53
  - Manifest.txt
48
54
  - PostInstall.txt