gdocs4ruby 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gdocs4ruby/base_object.rb +13 -37
- data/lib/gdocs4ruby/service.rb +1 -1
- data/test/unit.rb +114 -3
- metadata +21 -10
@@ -95,18 +95,6 @@ module GDocs4Ruby
|
|
95
95
|
|
96
96
|
TYPES = ["document", "folder", "spreadsheet", "presentation", "any"]
|
97
97
|
|
98
|
-
#The raw date the document was published
|
99
|
-
attr_reader :published
|
100
|
-
|
101
|
-
#The raw date the document was last updated
|
102
|
-
attr_reader :updated
|
103
|
-
|
104
|
-
#The author/owner name
|
105
|
-
attr_reader :author_name
|
106
|
-
|
107
|
-
#The author/owner email
|
108
|
-
attr_reader :author_email
|
109
|
-
|
110
98
|
#An array of folders this object belongs to
|
111
99
|
attr_reader :folders
|
112
100
|
|
@@ -119,9 +107,6 @@ module GDocs4Ruby
|
|
119
107
|
#The uri for the html editor of the object (the web editor for documents)
|
120
108
|
attr_reader :html_uri
|
121
109
|
|
122
|
-
#The content uri for exporting the object content
|
123
|
-
attr_reader :content_uri
|
124
|
-
|
125
110
|
#Flag indicating whether the document has the 'viewed' category link.
|
126
111
|
attr_reader :viewed
|
127
112
|
|
@@ -133,7 +118,6 @@ module GDocs4Ruby
|
|
133
118
|
super(service, attributes)
|
134
119
|
@xml = ENTRY_XML
|
135
120
|
@folders = []
|
136
|
-
@content_uri = nil
|
137
121
|
@edit_content_uri = nil
|
138
122
|
@viewed = false
|
139
123
|
@content = @content_type = nil
|
@@ -148,12 +132,6 @@ module GDocs4Ruby
|
|
148
132
|
xml.root.elements.each(){}.map do |ele|
|
149
133
|
@etag = xml.root.attributes['etag'] if xml.root.attributes['etag']
|
150
134
|
case ele.name
|
151
|
-
when 'published'
|
152
|
-
@published = ele.text
|
153
|
-
when 'updated'
|
154
|
-
@updated = ele.text
|
155
|
-
when 'content'
|
156
|
-
@content_uri = ele.attributes['src']
|
157
135
|
when 'link'
|
158
136
|
case ele.attributes['rel']
|
159
137
|
when 'edit-media'
|
@@ -161,9 +139,6 @@ module GDocs4Ruby
|
|
161
139
|
when 'alternate'
|
162
140
|
@html_uri = ele.attributes['href']
|
163
141
|
end
|
164
|
-
when 'author'
|
165
|
-
ele.elements.each('name'){}.map {|e| @author_name = e.text}
|
166
|
-
ele.elements.each('email'){}.map {|e| @author_email = e.text}
|
167
142
|
when 'quotaBytesUsed'
|
168
143
|
@bytes_used = ele.text
|
169
144
|
end
|
@@ -199,13 +174,13 @@ module GDocs4Ruby
|
|
199
174
|
else
|
200
175
|
ret = service.send_request(GData4Ruby::Request.new(:put, @edit_uri, to_xml()))
|
201
176
|
end
|
202
|
-
if not load(ret.read_body)
|
203
|
-
raise SaveFailed
|
204
|
-
end
|
205
|
-
return true
|
206
177
|
else
|
207
|
-
|
178
|
+
ret = create
|
179
|
+
end
|
180
|
+
if not load(ret.read_body)
|
181
|
+
raise SaveFailed
|
208
182
|
end
|
183
|
+
return true
|
209
184
|
end
|
210
185
|
|
211
186
|
#Retrieves an array of GData4Ruby::AccessRules representing the access rules for the object, as contained in the Google ACL.
|
@@ -291,9 +266,6 @@ module GDocs4Ruby
|
|
291
266
|
else
|
292
267
|
service.send_request(GData4Ruby::Request.new(:post, DOCUMENT_LIST_FEED, to_xml()))
|
293
268
|
end
|
294
|
-
if not load(ret.read_body)
|
295
|
-
raise SaveFailed
|
296
|
-
end
|
297
269
|
return ret
|
298
270
|
end
|
299
271
|
|
@@ -319,7 +291,7 @@ module GDocs4Ruby
|
|
319
291
|
|
320
292
|
#Finds a BaseObject based on a text query or by an id. Parameters are:
|
321
293
|
#*service*:: A valid Service object to search.
|
322
|
-
#*query*:: either a string containing a text query to search by, or a hash containing an +id+ key with an associated id to find, or a +query+ key containint a text query to search for.
|
294
|
+
#*query*:: either a string containing a text query to search by, or a hash containing an +id+ key with an associated id to find, or a +query+ key containint a text query to search for, or a +title+ key containing a title to search.
|
323
295
|
#*type*:: used to limit results to a specific document type, as list in TYPES.
|
324
296
|
#*args*:: a hash containing optional additional query paramters to use. See http://code.google.com/apis/gdata/docs/2.0/reference.html#Queries for a full list of possible values. Example:
|
325
297
|
# {'max-results' => '100'}
|
@@ -331,7 +303,7 @@ module GDocs4Ruby
|
|
331
303
|
raise ArgumentError, "type must be one of #{TYPES.join(" ")}" if not TYPES.include? type
|
332
304
|
if query.is_a? Hash and query[:id]
|
333
305
|
id = query[:id]
|
334
|
-
puts "id passed, finding
|
306
|
+
puts "id passed, finding document by id" if service.debug
|
335
307
|
puts "id = "+id if service.debug
|
336
308
|
d = service.send_request(GData4Ruby::Request.new(:get, FEEDS[type.to_sym]+id, {"If-Not-Match" => "*"}))
|
337
309
|
puts d.inspect if service.debug
|
@@ -340,8 +312,12 @@ module GDocs4Ruby
|
|
340
312
|
end
|
341
313
|
else
|
342
314
|
results = []
|
343
|
-
|
344
|
-
|
315
|
+
if query.is_a?(Hash)
|
316
|
+
args["q"] = query[:query] if query[:query]
|
317
|
+
args['title'] = query[:title] if query[:title]
|
318
|
+
else
|
319
|
+
args["q"] = CGI::escape(query) if query != ''
|
320
|
+
end
|
345
321
|
ret = service.send_request(GData4Ruby::Request.new(:get, QUERY_FEEDS[type.to_sym], nil, nil, args))
|
346
322
|
xml = REXML::Document.new(ret.body).root
|
347
323
|
xml.elements.each("entry") do |e|
|
data/lib/gdocs4ruby/service.rb
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
# Feel free to use and update, but be sure to contribute your
|
16
16
|
# code back to the project and attribute as required by the license.
|
17
17
|
#++
|
18
|
-
require 'gdocs4ruby
|
18
|
+
require 'gdocs4ruby'
|
19
19
|
require 'gdocs4ruby/base_object'
|
20
20
|
require 'gdocs4ruby/folder'
|
21
21
|
require 'gdocs4ruby/document'
|
data/test/unit.rb
CHANGED
@@ -1,3 +1,114 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'gdocs4ruby'
|
5
|
+
include GDocs4Ruby
|
6
|
+
|
7
|
+
@service = Service.new
|
8
|
+
@username = nil
|
9
|
+
@password = nil
|
10
|
+
|
11
|
+
def tester
|
12
|
+
if ARGV.include?("-d")
|
13
|
+
@service.debug = true
|
14
|
+
end
|
15
|
+
ARGV.each do |ar|
|
16
|
+
if ar.match("username=")
|
17
|
+
@username = ar.gsub("username=", "")
|
18
|
+
end
|
19
|
+
if ar.match("password=")
|
20
|
+
@password = ar.gsub("password=", "")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
service_test
|
24
|
+
document_crud
|
25
|
+
find_document
|
26
|
+
end
|
27
|
+
|
28
|
+
def service_test
|
29
|
+
puts "---Starting Service Test---"
|
30
|
+
puts "1. Authenticate"
|
31
|
+
if @service.authenticate(@username, @password)
|
32
|
+
successful
|
33
|
+
else
|
34
|
+
failed
|
35
|
+
end
|
36
|
+
|
37
|
+
puts "2. Authenticate with GData version 3.0"
|
38
|
+
@service = Service.new({:gdata_version => '3.0'})
|
39
|
+
if @service.authenticate(@username, @password) and @service.gdata_version == '3.0'
|
40
|
+
successful
|
41
|
+
else
|
42
|
+
failed
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def document_crud
|
47
|
+
puts "---Starting Document Test---"
|
48
|
+
@service = Service.new()
|
49
|
+
@service.authenticate(@username, @password)
|
50
|
+
|
51
|
+
content = '<h1>test content</h1>'
|
52
|
+
content1 = '<b>new content</b>'
|
53
|
+
content_type = 'html'
|
54
|
+
title = 'Test title'
|
55
|
+
title1 = 'new title'
|
56
|
+
|
57
|
+
puts "1. Create Document"
|
58
|
+
doc = Document.new(@service)
|
59
|
+
doc.title = title
|
60
|
+
doc.content = content
|
61
|
+
doc.content_type = content_type
|
62
|
+
if doc.save and doc.title == title and doc.get_content('html').include? 'test content'
|
63
|
+
successful
|
64
|
+
else
|
65
|
+
failed
|
66
|
+
end
|
67
|
+
|
68
|
+
puts "2. Update Document"
|
69
|
+
doc.title = title1
|
70
|
+
doc.content = content1
|
71
|
+
doc.content_type = content_type
|
72
|
+
if doc.save and doc.title == title1 and doc.get_content('html').include? 'new content'
|
73
|
+
successful
|
74
|
+
else
|
75
|
+
failed
|
76
|
+
end
|
77
|
+
|
78
|
+
puts "3. Delete Document"
|
79
|
+
if doc.delete
|
80
|
+
successful
|
81
|
+
else
|
82
|
+
failed
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def find_document
|
87
|
+
puts "---Starting Query Test---"
|
88
|
+
puts "1. Create Document"
|
89
|
+
doc = Document.new(@service)
|
90
|
+
doc.title = title
|
91
|
+
doc.content = content
|
92
|
+
doc.content_type = content_type
|
93
|
+
if doc.save and doc.title == title and doc.get_content('html').include? 'test content'
|
94
|
+
successful
|
95
|
+
else
|
96
|
+
failed
|
97
|
+
end
|
98
|
+
|
99
|
+
puts "2. Find Document"
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
def failed(m = nil)
|
104
|
+
puts "Test Failed"
|
105
|
+
puts m if m
|
106
|
+
exit()
|
107
|
+
end
|
108
|
+
|
109
|
+
def successful(m = nil)
|
110
|
+
puts "Test Successful"
|
111
|
+
puts m if m
|
112
|
+
end
|
113
|
+
|
114
|
+
tester
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gdocs4ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 2
|
9
|
+
version: 0.1.2
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Mike Reich
|
@@ -9,19 +14,23 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-05-16 00:00:00 +10:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: gdata4ruby
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
23
|
-
|
24
|
-
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 1
|
30
|
+
- 1
|
31
|
+
version: 0.1.1
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
25
34
|
description: GDocs4Ruby is a full featured wrapper for version 2.0 of the Google Documents API (aka DocList). GDocs4Ruby provides the ability to create, update and delete google documents, metadata and content. The gem also includes support for folders, modifying permissions for documents via ACL feeds, and much more.
|
26
35
|
email: mike@seabourneconsulting.com
|
27
36
|
executables: []
|
@@ -53,18 +62,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
62
|
requirements:
|
54
63
|
- - ">="
|
55
64
|
- !ruby/object:Gem::Version
|
65
|
+
segments:
|
66
|
+
- 0
|
56
67
|
version: "0"
|
57
|
-
version:
|
58
68
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
69
|
requirements:
|
60
70
|
- - ">="
|
61
71
|
- !ruby/object:Gem::Version
|
72
|
+
segments:
|
73
|
+
- 0
|
62
74
|
version: "0"
|
63
|
-
version:
|
64
75
|
requirements: []
|
65
76
|
|
66
77
|
rubyforge_project: gdocs4ruby
|
67
|
-
rubygems_version: 1.3.
|
78
|
+
rubygems_version: 1.3.6
|
68
79
|
signing_key:
|
69
80
|
specification_version: 3
|
70
81
|
summary: A full featured wrapper for interacting with the Google Docs API
|