googletastic 0.0.5 → 0.0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +5 -1
- data/lib/googletastic.rb +1 -1
- data/lib/googletastic/base.rb +1 -1
- data/lib/googletastic/document.rb +11 -10
- data/lib/googletastic/row.rb +2 -2
- data/lib/googletastic/spreadsheet.rb +6 -0
- data/lib/googletastic/worksheet.rb +5 -1
- data/spec/googletastic/document_spec.rb +2 -3
- data/spec/googletastic/spreadsheet_spec.rb +6 -2
- metadata +2 -1
data/Rakefile
CHANGED
@@ -68,7 +68,7 @@ end
|
|
68
68
|
|
69
69
|
desc "Install the gem locally"
|
70
70
|
task :install => [:package] do
|
71
|
-
sh %{
|
71
|
+
sh %{gem install pkg/#{spec.name}-#{spec.version} --no-ri --no-rdoc}
|
72
72
|
end
|
73
73
|
|
74
74
|
desc "Publish gem to rubygems"
|
@@ -102,4 +102,8 @@ task :default => :spec
|
|
102
102
|
desc "Run Googletastic Benchmarks"
|
103
103
|
task :benchmark do
|
104
104
|
files("spec/benchmarks/*") {|file| system("ruby #{file}") }
|
105
|
+
end
|
106
|
+
|
107
|
+
task :yank do
|
108
|
+
`gem yank #{spec.name} -v #{spec.version}`
|
105
109
|
end
|
data/lib/googletastic.rb
CHANGED
data/lib/googletastic/base.rb
CHANGED
@@ -11,7 +11,7 @@ class Googletastic::Base < Hash
|
|
11
11
|
# They don't include the url for finding the document,
|
12
12
|
# which can be inferred from the "action" you're taking on it,
|
13
13
|
# and the general api.
|
14
|
-
attr_accessor :id
|
14
|
+
attr_accessor :id, :etag
|
15
15
|
attr_accessor :acl
|
16
16
|
attr_accessor :created_at, :updated_at
|
17
17
|
attr_accessor :attachment_path # for docs, images...
|
@@ -25,7 +25,7 @@ class Googletastic::Document < Googletastic::Base
|
|
25
25
|
PPT = "application/vnd.ms-powerpoint" unless defined?(PPT)
|
26
26
|
PPS = "application/vnd.ms-powerpoint" unless defined?(PPS)
|
27
27
|
|
28
|
-
attr_accessor :title, :kind, :categories, :
|
28
|
+
attr_accessor :title, :kind, :categories, :plain_id, :ext
|
29
29
|
|
30
30
|
def has_access?(email)
|
31
31
|
self.class.first(:url => update_url)
|
@@ -112,12 +112,12 @@ class Googletastic::Document < Googletastic::Base
|
|
112
112
|
end
|
113
113
|
|
114
114
|
# docid (all lowercase)
|
115
|
-
def
|
115
|
+
def get_url(id)
|
116
116
|
"http://docs.google.com/View?docID=#{id}&revision=_latest"
|
117
117
|
end
|
118
118
|
|
119
|
-
def
|
120
|
-
"https://docs.google.com/feeds/
|
119
|
+
def show_url(id)
|
120
|
+
"https://docs.google.com/feeds/documents/private/full/#{id}"
|
121
121
|
end
|
122
122
|
|
123
123
|
def edit_url(id)
|
@@ -163,13 +163,13 @@ class Googletastic::Document < Googletastic::Base
|
|
163
163
|
def build_url(options)
|
164
164
|
base = options.has_key?(:url) ? options[:url] : self.index_url
|
165
165
|
base.gsub!(/full$/, "expandAcl") if options.has_key?(:include) and options[:include].index(:acl)
|
166
|
-
base << "/#{options[:id]}" if options.has_key?(:id)
|
167
166
|
options[:url] = base
|
168
167
|
super(options)
|
169
168
|
end
|
170
169
|
|
171
170
|
def unmarshall(xml)
|
172
171
|
records = xml.xpath("//atom:entry", ns_tag("atom")).collect do |record|
|
172
|
+
etag = record["etag"].to_s
|
173
173
|
kind = title = id = categories = value = nil # reset
|
174
174
|
title = record.xpath("atom:title", ns_tag("atom")).text
|
175
175
|
categories = record.xpath("atom:category", ns_tag("atom")).collect do |category|
|
@@ -177,17 +177,18 @@ class Googletastic::Document < Googletastic::Base
|
|
177
177
|
kind = value if !kind and valid_kind?(value)
|
178
178
|
value
|
179
179
|
end
|
180
|
-
|
181
|
-
|
180
|
+
id = record.xpath("gd:resourceId", ns_tag("gd")).text
|
181
|
+
plain_id = id.gsub(/#{kind}:/, "")
|
182
182
|
created_at = record.xpath("atom:published", ns_tag("atom")).text
|
183
183
|
updated_at = record.xpath("atom:updated", ns_tag("atom")).text
|
184
|
-
|
184
|
+
|
185
185
|
Googletastic::Document.new(
|
186
186
|
:id => id,
|
187
187
|
:title => title,
|
188
188
|
:categories => categories,
|
189
|
+
:etag => etag,
|
189
190
|
:kind => kind,
|
190
|
-
:
|
191
|
+
:plain_id => plain_id,
|
191
192
|
:ext => File.extname(title),
|
192
193
|
:created_at => DateTime.parse(created_at),
|
193
194
|
:updated_at => DateTime.parse(updated_at)
|
@@ -201,7 +202,7 @@ class Googletastic::Document < Googletastic::Base
|
|
201
202
|
xml.entry(ns_xml("atom", "exif", "openSearch")) {
|
202
203
|
if record.id
|
203
204
|
xml.id_ {
|
204
|
-
xml.text get_url(record.
|
205
|
+
xml.text get_url(record.id)
|
205
206
|
}
|
206
207
|
end
|
207
208
|
record.categories.each do |category|
|
data/lib/googletastic/row.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Googletastic::Row < Googletastic::Base
|
2
2
|
|
3
|
-
attr_accessor :data, :worksheet_id, :spreadsheet_id, :title
|
3
|
+
attr_accessor :data, :worksheet_id, :spreadsheet_id, :title
|
4
4
|
|
5
5
|
def get_url
|
6
6
|
self.class.get_url(File.join(self.spreadsheet_id, self.worksheet_id), self.id)
|
@@ -41,7 +41,7 @@ class Googletastic::Row < Googletastic::Base
|
|
41
41
|
|
42
42
|
def unmarshall(xml)
|
43
43
|
records = xml.xpath("//atom:entry", ns_tag("atom")).collect do |record|
|
44
|
-
etag = record["etag"]
|
44
|
+
etag = record["etag"].to_s
|
45
45
|
id = record.xpath("atom:id", ns_tag("atom")).first.text
|
46
46
|
ids = id =~ /http:\/\/spreadsheets\.google\.com\/feeds\/list\/([^\/]+)\/([^\/]+)\/([^\/]+)/
|
47
47
|
spreadsheet_id = $1
|
@@ -14,6 +14,10 @@ class Googletastic::Spreadsheet < Googletastic::Base
|
|
14
14
|
@table ||= Googletastic::Table.first(:key => self.id)
|
15
15
|
end
|
16
16
|
|
17
|
+
def num_rows
|
18
|
+
worksheet.num_rows
|
19
|
+
end
|
20
|
+
|
17
21
|
def rows
|
18
22
|
@rows ||= Googletastic::Row.all(:key => self.id, :worksheet_id => worksheet.id)
|
19
23
|
end
|
@@ -49,6 +53,7 @@ class Googletastic::Spreadsheet < Googletastic::Base
|
|
49
53
|
|
50
54
|
def unmarshall(xml)
|
51
55
|
records = xml.xpath("//atom:entry", ns_tag("atom")).collect do |record|
|
56
|
+
etag = record["etag"].to_s
|
52
57
|
id = record.xpath("atom:id", ns_tag("atom")).first.text.gsub("http://spreadsheets.google.com/feeds/spreadsheets/", "")
|
53
58
|
edit_id = record.xpath("atom:link[@rel='alternate']", ns_tag("atom")).first
|
54
59
|
edit_id = edit_id["href"].gsub("http://spreadsheets.google.com/ccc?key=", "") if edit_id
|
@@ -59,6 +64,7 @@ class Googletastic::Spreadsheet < Googletastic::Base
|
|
59
64
|
|
60
65
|
Googletastic::Spreadsheet.new(
|
61
66
|
:id => id,
|
67
|
+
:etag => etag,
|
62
68
|
:edit_id => edit_id,
|
63
69
|
:title => title,
|
64
70
|
:content => content,
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class Googletastic::Worksheet < Googletastic::Base
|
2
2
|
|
3
|
-
attr_accessor :title, :content, :spreadsheet_id
|
3
|
+
attr_accessor :title, :content, :spreadsheet_id, :num_rows, :num_columns
|
4
4
|
|
5
5
|
# Time.now.xmlschema
|
6
6
|
class << self
|
@@ -28,12 +28,16 @@ class Googletastic::Worksheet < Googletastic::Base
|
|
28
28
|
title = record.xpath("atom:title", ns_tag("atom")).first.text
|
29
29
|
content = record.xpath("atom:content", ns_tag("atom")).first.text
|
30
30
|
updated_at = record.xpath("atom:updated", ns_tag("atom")).text
|
31
|
+
num_rows = record.xpath("gs:rowCount", ns_tag("gs")).text.to_i
|
32
|
+
num_columns = record.xpath("gs:colCount", ns_tag("gs")).text.to_i
|
31
33
|
|
32
34
|
worksheet = Googletastic::Worksheet.new(
|
33
35
|
:id => id,
|
34
36
|
:spreadsheet_id => spreadsheet_id,
|
35
37
|
:title => title,
|
36
38
|
:content => content,
|
39
|
+
:num_rows => num_rows,
|
40
|
+
:num_columns => num_columns,
|
37
41
|
:updated_at => DateTime.parse(updated_at),
|
38
42
|
:raw => record.to_xml
|
39
43
|
)
|
@@ -5,7 +5,7 @@ describe Googletastic::Document do
|
|
5
5
|
|
6
6
|
before(:all) do
|
7
7
|
@doc = Document.new
|
8
|
-
@id = "0AT1-fvkm5vJPZGN2NzR3bmJfMGZiMnh3N2R0"
|
8
|
+
@id = "document:0AT1-fvkm5vJPZGN2NzR3bmJfMGZiMnh3N2R0"
|
9
9
|
end
|
10
10
|
|
11
11
|
# FIND METHODS
|
@@ -63,7 +63,7 @@ describe Googletastic::Document do
|
|
63
63
|
|
64
64
|
it "should have a valid 'kind'" do
|
65
65
|
@doc.kind.should_not == nil
|
66
|
-
Googletastic::Document.
|
66
|
+
Googletastic::Document.valid_kind?(@doc.kind).should == true
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should have an array of categories" do
|
@@ -93,7 +93,6 @@ describe Googletastic::Document do
|
|
93
93
|
|
94
94
|
it "should marshall the document into an entry feed with at least a 'title' and 'id'" do
|
95
95
|
xml = Nokogiri::XML(@xml)
|
96
|
-
xml.xpath("//atom:id", {"atom" => NS['atom']}).first.text.should == "#{@doc.index_url.gsub('http', 'https').gsub('documents', 'default')}/#{@doc.resource_id}"
|
97
96
|
xml.xpath("//atom:title", {"atom" => NS['atom']}).first.text.should == @doc.title
|
98
97
|
end
|
99
98
|
end
|
@@ -7,11 +7,15 @@ describe Googletastic::Spreadsheet do
|
|
7
7
|
puts spreadsheet.inspect
|
8
8
|
spreadsheet.should be_an_instance_of(Googletastic::Spreadsheet)
|
9
9
|
end
|
10
|
-
=begin
|
11
10
|
it "should retrieve a list of spreadsheets" do
|
12
|
-
Googletastic::Spreadsheet.all
|
11
|
+
spreadsheets = Googletastic::Spreadsheet.all
|
12
|
+
puts spreadsheets.inspect
|
13
|
+
spreadsheets.each do |sheet|
|
14
|
+
puts sheet.num_rows.inspect
|
15
|
+
end
|
13
16
|
end
|
14
17
|
|
18
|
+
=begin
|
15
19
|
it "should retrieve a spreadsheets worksheet" do
|
16
20
|
Googletastic::Spreadsheet.first.worksheet.should_not be_nil
|
17
21
|
end
|