googletastic 0.0.5.1 → 0.0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +3 -1
- data/Rakefile +1 -0
- data/lib/googletastic.rb +1 -1
- data/lib/googletastic/base.rb +2 -1
- data/lib/googletastic/document.rb +3 -1
- data/lib/googletastic/head.rb +30 -0
- data/lib/googletastic/mixins/finders.rb +7 -0
- data/lib/googletastic/mixins/namespaces.rb +1 -1
- data/lib/googletastic/mixins/pagination.rb +32 -0
- data/lib/googletastic/mixins/parsing.rb +4 -0
- data/lib/googletastic/mixins/requesting.rb +1 -1
- data/lib/googletastic/row.rb +2 -1
- data/lib/googletastic/spreadsheet.rb +8 -1
- data/lib/googletastic/worksheet.rb +2 -1
- data/spec/googletastic/spreadsheet_spec.rb +17 -4
- metadata +32 -3
data/README.textile
CHANGED
@@ -46,4 +46,6 @@ http://productideas.appspot.com/#15/e=220cb&t=cabc1
|
|
46
46
|
# Publish the docs as plain text.
|
47
47
|
# Textile and Markdown support
|
48
48
|
# Better font support in PDF documents
|
49
|
-
# Everything Should Be TAGGABLE
|
49
|
+
# Everything Should Be TAGGABLE
|
50
|
+
|
51
|
+
Takes about 5-10 minutes for google to update the feed so that "updated_at" < 1.day.ago if you just made a change.
|
data/Rakefile
CHANGED
data/lib/googletastic.rb
CHANGED
data/lib/googletastic/base.rb
CHANGED
@@ -6,12 +6,13 @@ class Googletastic::Base < Hash
|
|
6
6
|
include Googletastic::Mixins::Parsing
|
7
7
|
include Googletastic::Mixins::Finders
|
8
8
|
include Googletastic::Mixins::Actions
|
9
|
+
include Googletastic::Mixins::Pagination
|
9
10
|
|
10
11
|
# ID's are specifically the hash key for each entry.
|
11
12
|
# They don't include the url for finding the document,
|
12
13
|
# which can be inferred from the "action" you're taking on it,
|
13
14
|
# and the general api.
|
14
|
-
attr_accessor :id, :etag
|
15
|
+
attr_accessor :id, :etag, :head
|
15
16
|
attr_accessor :acl
|
16
17
|
attr_accessor :created_at, :updated_at
|
17
18
|
attr_accessor :attachment_path # for docs, images...
|
@@ -168,6 +168,7 @@ class Googletastic::Document < Googletastic::Base
|
|
168
168
|
end
|
169
169
|
|
170
170
|
def unmarshall(xml)
|
171
|
+
head = unmarshall_head(xml)
|
171
172
|
records = xml.xpath("//atom:entry", ns_tag("atom")).collect do |record|
|
172
173
|
etag = record["etag"].to_s
|
173
174
|
kind = title = id = categories = value = nil # reset
|
@@ -191,7 +192,8 @@ class Googletastic::Document < Googletastic::Base
|
|
191
192
|
:plain_id => plain_id,
|
192
193
|
:ext => File.extname(title),
|
193
194
|
:created_at => DateTime.parse(created_at),
|
194
|
-
:updated_at => DateTime.parse(updated_at)
|
195
|
+
:updated_at => DateTime.parse(updated_at),
|
196
|
+
:head => head
|
195
197
|
)
|
196
198
|
end
|
197
199
|
records
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class Googletastic::Head < Googletastic::Base
|
2
|
+
|
3
|
+
attr_accessor :title, :total_results, :start_index, :per_page
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def unmarshall(xml)
|
8
|
+
feed = xml.xpath("atom:feed", ns_tag("atom")).first
|
9
|
+
return nil unless feed
|
10
|
+
|
11
|
+
id = feed.xpath("atom:id", ns_tag("atom")).text
|
12
|
+
updated_at = feed.xpath("atom:updated", ns_tag("atom")).text
|
13
|
+
title = feed.xpath("atom:title", ns_tag("atom")).text
|
14
|
+
total_results = feed.xpath("openSearch:totalResults", ns_tag("openSearch")).text
|
15
|
+
start_index = feed.xpath("openSearch:startIndex", ns_tag("openSearch")).text
|
16
|
+
per_page = feed.xpath("openSearch:itemsPerPage", ns_tag("openSearch")).text
|
17
|
+
|
18
|
+
head = Googletastic::Head.new(
|
19
|
+
:id => id,
|
20
|
+
:title => title,
|
21
|
+
:updated_at => DateTime.parse(updated_at),
|
22
|
+
:total_results => total_results,
|
23
|
+
:start_index => start_index,
|
24
|
+
:per_page => per_page
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -5,6 +5,13 @@ module Googletastic::Mixins::Finders
|
|
5
5
|
end
|
6
6
|
|
7
7
|
module ClassMethods
|
8
|
+
|
9
|
+
def head(*args)
|
10
|
+
options = args.extract_options!
|
11
|
+
result = find_by_api(options.merge(:limit => 1)).first
|
12
|
+
result.nil? ? nil : result.head
|
13
|
+
end
|
14
|
+
|
8
15
|
def first(*args)
|
9
16
|
find(:first, *args)
|
10
17
|
end
|
@@ -3,7 +3,7 @@ module Googletastic::Mixins::Namespaces
|
|
3
3
|
NAMESPACES = {
|
4
4
|
"gphoto" => "http://schemas.google.com/photos/2007",
|
5
5
|
"media" => "http://search.yahoo.com/mrss",
|
6
|
-
"openSearch" => "http://a9.com/-/spec/
|
6
|
+
"openSearch" => "http://a9.com/-/spec/opensearch/1.1/",
|
7
7
|
"docs" => "http://schemas.google.com/docs/2007",
|
8
8
|
"atom" => "http://www.w3.org/2005/Atom",
|
9
9
|
"gd" => "http://schemas.google.com/g/2005",
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Googletastic::Mixins::Pagination
|
2
|
+
|
3
|
+
def self.included(base)
|
4
|
+
base.extend(ClassMethods)
|
5
|
+
base.class_eval do
|
6
|
+
include InstanceMethods
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
|
12
|
+
# needs to track category and such
|
13
|
+
def paginate(*args, &block)
|
14
|
+
options = args.extract_options!
|
15
|
+
|
16
|
+
per_page = options[:per_page]
|
17
|
+
page = options[:page] || 1
|
18
|
+
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
module InstanceMethods
|
25
|
+
|
26
|
+
def total_results
|
27
|
+
self.head ? self.head.total_results : 1
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/lib/googletastic/row.rb
CHANGED
@@ -40,6 +40,7 @@ class Googletastic::Row < Googletastic::Base
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def unmarshall(xml)
|
43
|
+
head = unmarshall_head(xml)
|
43
44
|
records = xml.xpath("//atom:entry", ns_tag("atom")).collect do |record|
|
44
45
|
etag = record["etag"].to_s
|
45
46
|
id = record.xpath("atom:id", ns_tag("atom")).first.text
|
@@ -66,7 +67,7 @@ class Googletastic::Row < Googletastic::Base
|
|
66
67
|
:worksheet_id => worksheet_id,
|
67
68
|
:data => data,
|
68
69
|
:updated_at => DateTime.parse(updated_at),
|
69
|
-
:
|
70
|
+
:head => head
|
70
71
|
)
|
71
72
|
end
|
72
73
|
records
|
@@ -14,10 +14,16 @@ class Googletastic::Spreadsheet < Googletastic::Base
|
|
14
14
|
@table ||= Googletastic::Table.first(:key => self.id)
|
15
15
|
end
|
16
16
|
|
17
|
+
# some property on google
|
17
18
|
def num_rows
|
18
19
|
worksheet.num_rows
|
19
20
|
end
|
20
21
|
|
22
|
+
# what you want
|
23
|
+
def total_rows
|
24
|
+
@total_rows ||= Googletastic::Row.head(:key => self.id, :worksheet_id => worksheet.id).total_results
|
25
|
+
end
|
26
|
+
|
21
27
|
def rows
|
22
28
|
@rows ||= Googletastic::Row.all(:key => self.id, :worksheet_id => worksheet.id)
|
23
29
|
end
|
@@ -52,6 +58,7 @@ class Googletastic::Spreadsheet < Googletastic::Base
|
|
52
58
|
end
|
53
59
|
|
54
60
|
def unmarshall(xml)
|
61
|
+
head = unmarshall_head(xml)
|
55
62
|
records = xml.xpath("//atom:entry", ns_tag("atom")).collect do |record|
|
56
63
|
etag = record["etag"].to_s
|
57
64
|
id = record.xpath("atom:id", ns_tag("atom")).first.text.gsub("http://spreadsheets.google.com/feeds/spreadsheets/", "")
|
@@ -69,7 +76,7 @@ class Googletastic::Spreadsheet < Googletastic::Base
|
|
69
76
|
:title => title,
|
70
77
|
:content => content,
|
71
78
|
:updated_at => DateTime.parse(updated_at),
|
72
|
-
:
|
79
|
+
:head => head
|
73
80
|
)
|
74
81
|
end
|
75
82
|
records
|
@@ -20,6 +20,7 @@ class Googletastic::Worksheet < Googletastic::Base
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def unmarshall(xml)
|
23
|
+
head = unmarshall_head(xml)
|
23
24
|
records = xml.xpath("//atom:entry", ns_tag("atom")).collect do |record|
|
24
25
|
id = record.xpath("atom:id", ns_tag("atom")).first.text
|
25
26
|
ids = id =~ /http:\/\/spreadsheets\.google\.com\/feeds\/worksheets\/([^\/]+)\/([^\/]+)/
|
@@ -39,7 +40,7 @@ class Googletastic::Worksheet < Googletastic::Base
|
|
39
40
|
:num_rows => num_rows,
|
40
41
|
:num_columns => num_columns,
|
41
42
|
:updated_at => DateTime.parse(updated_at),
|
42
|
-
:
|
43
|
+
:head => head
|
43
44
|
)
|
44
45
|
|
45
46
|
worksheet
|
@@ -7,12 +7,25 @@ describe Googletastic::Spreadsheet do
|
|
7
7
|
puts spreadsheet.inspect
|
8
8
|
spreadsheet.should be_an_instance_of(Googletastic::Spreadsheet)
|
9
9
|
end
|
10
|
+
|
10
11
|
it "should retrieve a list of spreadsheets" do
|
11
12
|
spreadsheets = Googletastic::Spreadsheet.all
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should get the head for a list of spreadsheets" do
|
16
|
+
spreadsheets = Googletastic::Spreadsheet.all
|
17
|
+
first = spreadsheets.first
|
18
|
+
first.head.should_not be_nil
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should be able to get a head by itself" do
|
22
|
+
head = Googletastic::Spreadsheet.head
|
23
|
+
head.should_not be_nil
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should get total number of rows" do
|
27
|
+
sheet = Googletastic::Spreadsheet.first
|
28
|
+
puts sheet.total_rows.inspect
|
16
29
|
end
|
17
30
|
|
18
31
|
=begin
|
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: googletastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 95
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
9
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.0.5.
|
10
|
+
- 2
|
11
|
+
version: 0.0.5.2
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- Lance Pollard
|
@@ -22,9 +23,11 @@ dependencies:
|
|
22
23
|
name: nokogiri
|
23
24
|
prerelease: false
|
24
25
|
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
25
27
|
requirements:
|
26
28
|
- - ">="
|
27
29
|
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
28
31
|
segments:
|
29
32
|
- 0
|
30
33
|
version: "0"
|
@@ -34,9 +37,11 @@ dependencies:
|
|
34
37
|
name: activesupport
|
35
38
|
prerelease: false
|
36
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
37
41
|
requirements:
|
38
42
|
- - ">="
|
39
43
|
- !ruby/object:Gem::Version
|
44
|
+
hash: 9
|
40
45
|
segments:
|
41
46
|
- 2
|
42
47
|
- 3
|
@@ -48,9 +53,11 @@ dependencies:
|
|
48
53
|
name: activerecord
|
49
54
|
prerelease: false
|
50
55
|
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
51
57
|
requirements:
|
52
58
|
- - ">="
|
53
59
|
- !ruby/object:Gem::Version
|
60
|
+
hash: 9
|
54
61
|
segments:
|
55
62
|
- 2
|
56
63
|
- 3
|
@@ -62,14 +69,30 @@ dependencies:
|
|
62
69
|
name: gdata
|
63
70
|
prerelease: false
|
64
71
|
requirement: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
65
73
|
requirements:
|
66
74
|
- - ">="
|
67
75
|
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
68
77
|
segments:
|
69
78
|
- 0
|
70
79
|
version: "0"
|
71
80
|
type: :runtime
|
72
81
|
version_requirements: *id004
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: rspec
|
84
|
+
prerelease: false
|
85
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
type: :runtime
|
95
|
+
version_requirements: *id005
|
73
96
|
description: "Googletastic: A New Way of Googling"
|
74
97
|
email: lancejpollard@gmail.com
|
75
98
|
executables: []
|
@@ -98,6 +121,7 @@ files:
|
|
98
121
|
- lib/googletastic/ext.rb
|
99
122
|
- lib/googletastic/form.rb
|
100
123
|
- lib/googletastic/group.rb
|
124
|
+
- lib/googletastic/head.rb
|
101
125
|
- lib/googletastic/helpers/document.rb
|
102
126
|
- lib/googletastic/helpers/event.rb
|
103
127
|
- lib/googletastic/helpers/form.rb
|
@@ -107,6 +131,7 @@ files:
|
|
107
131
|
- lib/googletastic/mixins/attributes.rb
|
108
132
|
- lib/googletastic/mixins/finders.rb
|
109
133
|
- lib/googletastic/mixins/namespaces.rb
|
134
|
+
- lib/googletastic/mixins/pagination.rb
|
110
135
|
- lib/googletastic/mixins/parsing.rb
|
111
136
|
- lib/googletastic/mixins/requesting.rb
|
112
137
|
- lib/googletastic/mixins.rb
|
@@ -170,23 +195,27 @@ rdoc_options: []
|
|
170
195
|
require_paths:
|
171
196
|
- lib
|
172
197
|
required_ruby_version: !ruby/object:Gem::Requirement
|
198
|
+
none: false
|
173
199
|
requirements:
|
174
200
|
- - ">="
|
175
201
|
- !ruby/object:Gem::Version
|
202
|
+
hash: 3
|
176
203
|
segments:
|
177
204
|
- 0
|
178
205
|
version: "0"
|
179
206
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
207
|
+
none: false
|
180
208
|
requirements:
|
181
209
|
- - ">="
|
182
210
|
- !ruby/object:Gem::Version
|
211
|
+
hash: 3
|
183
212
|
segments:
|
184
213
|
- 0
|
185
214
|
version: "0"
|
186
215
|
requirements: []
|
187
216
|
|
188
217
|
rubyforge_project: googletastic
|
189
|
-
rubygems_version: 1.3.
|
218
|
+
rubygems_version: 1.3.7
|
190
219
|
signing_key:
|
191
220
|
specification_version: 3
|
192
221
|
summary: More than Syncing Rails Apps with the Google Data API
|