collin-google_ajax_feed_api 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile.rb +2 -1
- data/lib/google_ajax_feed_api.rb +8 -208
- data/lib/google_ajax_feed_api/api.rb +14 -0
- data/lib/google_ajax_feed_api/api/one_zero.rb +58 -0
- data/lib/google_ajax_feed_api/entry.rb +45 -0
- data/lib/google_ajax_feed_api/feed.rb +112 -0
- data/spec/api_spec.rb +57 -0
- data/spec/entry_spec.rb +31 -0
- data/spec/feed_spec.rb +73 -0
- data/spec/helper.rb +6 -0
- metadata +11 -2
- data/spec/google_ajax_feed_spec.rb +0 -160
data/Rakefile.rb
CHANGED
data/lib/google_ajax_feed_api.rb
CHANGED
@@ -4,218 +4,18 @@ require 'extlib'
|
|
4
4
|
require 'json'
|
5
5
|
require 'open-uri'
|
6
6
|
|
7
|
+
$LOAD_PATH << File.dirname(__FILE__)
|
8
|
+
|
7
9
|
module Google #:nodoc:
|
8
10
|
module Ajax #:nodoc:
|
9
11
|
class Feed
|
10
|
-
|
11
|
-
|
12
|
-
def inspect # :nodoc:
|
13
|
-
"<#Google::Ajax::Feed::Entry link=#{link} title=#{title}>"
|
14
|
-
end
|
15
|
-
|
16
|
-
# The permalink for this entry
|
17
|
-
def link
|
18
|
-
@data["link"]
|
19
|
-
end
|
20
|
-
|
21
|
-
# The title for this entry
|
22
|
-
def title
|
23
|
-
@data["title"]
|
24
|
-
end
|
25
|
-
|
26
|
-
# The content of this entry
|
27
|
-
def content
|
28
|
-
@data["content"]
|
29
|
-
end
|
30
|
-
|
31
|
-
# A snippet of this entries content
|
32
|
-
def snippet
|
33
|
-
@data["contentSnippet"]
|
34
|
-
end
|
35
|
-
|
36
|
-
# The author for this specific entry
|
37
|
-
def author
|
38
|
-
@data["author"]
|
39
|
-
end
|
40
|
-
|
41
|
-
# The publication date for this entry
|
42
|
-
def created_at
|
43
|
-
@data["publishedDate"]
|
44
|
-
end
|
45
|
-
|
46
|
-
def initialize data #:nodoc:
|
47
|
-
@data = data
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
module API #:nodoc:
|
52
|
-
def self.[] version
|
53
|
-
case version
|
54
|
-
when '1.0'
|
55
|
-
OneZero
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
class OneZero
|
60
|
-
class << self
|
61
|
-
# The endpoint URI for lookup requests
|
62
|
-
def lookup
|
63
|
-
"http://ajax.googleapis.com/ajax/services/feed/lookup"
|
64
|
-
end
|
65
|
-
|
66
|
-
# The endpoint URI for search requests
|
67
|
-
def find
|
68
|
-
"http://ajax.googleapis.com/ajax/services/feed/find"
|
69
|
-
end
|
70
|
-
|
71
|
-
# The endpoint URI for loading feeds
|
72
|
-
def load
|
73
|
-
"http://ajax.googleapis.com/ajax/services/feed/load"
|
74
|
-
end
|
75
|
-
|
76
|
-
# Builds a query to lookup a feed for a url
|
77
|
-
def lookup_query url
|
78
|
-
"#{lookup}#{params url}"
|
79
|
-
end
|
80
|
-
|
81
|
-
|
82
|
-
# Builds a query to search for feeds
|
83
|
-
# query is a search term
|
84
|
-
def find_query query
|
85
|
-
"#{find}#{params query}"
|
86
|
-
end
|
87
|
-
|
88
|
-
|
89
|
-
# Builds a query
|
90
|
-
# options are overrides for Feed#config options
|
91
|
-
def load_query url, options={}
|
92
|
-
"#{load}#{params url}#{load_params options}"
|
93
|
-
end
|
94
|
-
|
95
|
-
def load_params options={} #:nodoc
|
96
|
-
options = ({
|
97
|
-
:limit => Feed.config.limit,
|
98
|
-
:history => Feed.config.history
|
99
|
-
}).merge(options)
|
100
|
-
|
101
|
-
params = "&num=#{options[:limit]}"
|
102
|
-
params << '&scoring=h' if options[:history]
|
103
|
-
params
|
104
|
-
end
|
105
|
-
|
106
|
-
def params query #:nodoc:
|
107
|
-
"?v=1.0&q=#{URI.encode query}"
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
class << self
|
114
|
-
# Default values are:
|
115
|
-
# * config.version = '1.0'
|
116
|
-
#
|
117
|
-
# version specifies what version of the feed API to use.
|
118
|
-
# 1.0 is the only version that exists and thusly the only
|
119
|
-
# option supported. DO NOT CHANGE THIS
|
120
|
-
#
|
121
|
-
# * config.limit = 15
|
122
|
-
#
|
123
|
-
# limit specifies how many feed items may be fetched at once
|
124
|
-
# Google specifies a hard limit of 100.
|
125
|
-
# But an individual feed might have it's own, lower limit.
|
126
|
-
#
|
127
|
-
# * config.history = false
|
128
|
-
# Which is where the history option comes into play.
|
129
|
-
# History pulls from Googls cache of the feed, not from the current
|
130
|
-
# state of the feed. With this option you can fetch up to 100 items
|
131
|
-
# from a feed that shows fewer than 100 at any given time.
|
132
|
-
def config
|
133
|
-
@config ||= OpenStruct.new(
|
134
|
-
:version => '1.0',
|
135
|
-
:limit => 15,
|
136
|
-
:history => false
|
137
|
-
)
|
138
|
-
end
|
139
|
-
|
140
|
-
# Lookup will take any of these url formats:
|
141
|
-
# * http://example.com
|
142
|
-
# * http://example.com/
|
143
|
-
# * http://www.example.com/
|
144
|
-
# * www.example.com
|
145
|
-
# * example.com/rss
|
146
|
-
# * etc.
|
147
|
-
#
|
148
|
-
# And the object created will have the same Feed#canonical_id
|
149
|
-
# Use of Feed#new is strongly discouraged
|
150
|
-
def lookup url
|
151
|
-
http_response = JSON.parse open(api.lookup_query(url)).read
|
152
|
-
url = http_response["responseData"]["url"]
|
153
|
-
new url
|
154
|
-
end
|
155
|
-
|
156
|
-
def api #:nodoc:
|
157
|
-
API[config.version]
|
158
|
-
end
|
159
|
-
end
|
12
|
+
Version = "0.0.3"
|
13
|
+
end
|
160
14
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
@url
|
166
|
-
end
|
167
|
-
|
168
|
-
# true if the lookup returned a positive match for a feed
|
169
|
-
def valid?
|
170
|
-
not @url.nil?
|
171
|
-
end
|
15
|
+
require 'google_ajax_feed_api/feed'
|
16
|
+
require 'google_ajax_feed_api/entry'
|
17
|
+
require 'google_ajax_feed_api/api'
|
18
|
+
require 'google_ajax_feed_api/api/one_zero'
|
172
19
|
|
173
|
-
# The link of the feed.
|
174
|
-
def link
|
175
|
-
feed["link"]
|
176
|
-
end
|
177
|
-
|
178
|
-
# The author of the feed.
|
179
|
-
def author
|
180
|
-
feed["author"]
|
181
|
-
end
|
182
|
-
|
183
|
-
# The title of the feed.
|
184
|
-
def title
|
185
|
-
feed["title"]
|
186
|
-
end
|
187
|
-
|
188
|
-
# The description of the feed.
|
189
|
-
def description
|
190
|
-
feed["description"]
|
191
|
-
end
|
192
|
-
|
193
|
-
# List of Entry objects for this feed.
|
194
|
-
def entries
|
195
|
-
@entries ||= feed["entries"].map do |entry|
|
196
|
-
Entry.new(entry)
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
def load options={} #:nodoc:
|
201
|
-
url = self.class.api.load_query @url, options
|
202
|
-
|
203
|
-
# Very strange json bug. Bye bye tabs
|
204
|
-
http_response = JSON.parse open(url).read.gsub("\t", '')
|
205
|
-
|
206
|
-
@feed = http_response["responseData"]["feed"]
|
207
|
-
|
208
|
-
return @feed.length
|
209
|
-
end
|
210
|
-
|
211
|
-
def feed #:nodoc:
|
212
|
-
load if @feed.nil?
|
213
|
-
@feed
|
214
|
-
end
|
215
|
-
|
216
|
-
def initialize url #:nodoc:
|
217
|
-
@url = url
|
218
|
-
end
|
219
|
-
end
|
220
20
|
end
|
221
21
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Google
|
2
|
+
module Ajax
|
3
|
+
class Feed
|
4
|
+
module API
|
5
|
+
class OneZero
|
6
|
+
class << self
|
7
|
+
# The endpoint URI for lookup requests
|
8
|
+
def lookup
|
9
|
+
"http://ajax.googleapis.com/ajax/services/feed/lookup"
|
10
|
+
end
|
11
|
+
|
12
|
+
# The endpoint URI for search requests
|
13
|
+
def find
|
14
|
+
"http://ajax.googleapis.com/ajax/services/feed/find"
|
15
|
+
end
|
16
|
+
|
17
|
+
# The endpoint URI for loading feeds
|
18
|
+
def load
|
19
|
+
"http://ajax.googleapis.com/ajax/services/feed/load"
|
20
|
+
end
|
21
|
+
|
22
|
+
# Builds a query to lookup a feed for a url
|
23
|
+
def lookup_query url
|
24
|
+
"#{lookup}#{params url}"
|
25
|
+
end
|
26
|
+
|
27
|
+
# Builds a query to search for feeds
|
28
|
+
# query is a search term
|
29
|
+
def find_query query
|
30
|
+
"#{find}#{params query}"
|
31
|
+
end
|
32
|
+
|
33
|
+
# Builds a query
|
34
|
+
# options are overrides for Feed#config options
|
35
|
+
def load_query url, options={}
|
36
|
+
"#{load}#{params url}#{load_params options}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def load_params options={} #:nodoc
|
40
|
+
options = ({
|
41
|
+
:limit => Feed.config.limit,
|
42
|
+
:history => Feed.config.history
|
43
|
+
}).merge(options)
|
44
|
+
|
45
|
+
params = "&num=#{options[:limit]}"
|
46
|
+
params << '&scoring=h' if options[:history]
|
47
|
+
params
|
48
|
+
end
|
49
|
+
|
50
|
+
def params query #:nodoc:
|
51
|
+
"?v=1.0&q=#{URI.encode query}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Google
|
2
|
+
module Ajax
|
3
|
+
class Feed
|
4
|
+
class Entry
|
5
|
+
def inspect # :nodoc:
|
6
|
+
"<#Google::Ajax::Feed::Entry link=#{link} title=#{title}>"
|
7
|
+
end
|
8
|
+
|
9
|
+
# The permalink for this entry
|
10
|
+
def link
|
11
|
+
@data["link"]
|
12
|
+
end
|
13
|
+
|
14
|
+
# The title for this entry
|
15
|
+
def title
|
16
|
+
@data["title"]
|
17
|
+
end
|
18
|
+
|
19
|
+
# The content of this entry
|
20
|
+
def content
|
21
|
+
@data["content"]
|
22
|
+
end
|
23
|
+
|
24
|
+
# A snippet of this entries content
|
25
|
+
def snippet
|
26
|
+
@data["contentSnippet"]
|
27
|
+
end
|
28
|
+
|
29
|
+
# The author for this specific entry
|
30
|
+
def author
|
31
|
+
@data["author"]
|
32
|
+
end
|
33
|
+
|
34
|
+
# The publication date for this entry
|
35
|
+
def created_at
|
36
|
+
@data["publishedDate"]
|
37
|
+
end
|
38
|
+
|
39
|
+
def initialize data #:nodoc:
|
40
|
+
@data = data
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module Google #:nodoc:
|
2
|
+
module Ajax #:nodoc:
|
3
|
+
class Feed
|
4
|
+
class << self
|
5
|
+
# Default values are:
|
6
|
+
# * config.version = '1.0'
|
7
|
+
#
|
8
|
+
# version specifies what version of the feed API to use.
|
9
|
+
# 1.0 is the only version that exists and thusly the only
|
10
|
+
# option supported. DO NOT CHANGE THIS
|
11
|
+
#
|
12
|
+
# * config.limit = 15
|
13
|
+
#
|
14
|
+
# limit specifies how many feed items may be fetched at once
|
15
|
+
# Google specifies a hard limit of 100.
|
16
|
+
# But an individual feed might have it's own, lower limit.
|
17
|
+
#
|
18
|
+
# * config.history = false
|
19
|
+
# Which is where the history option comes into play.
|
20
|
+
# History pulls from Googls cache of the feed, not from the current
|
21
|
+
# state of the feed. With this option you can fetch up to 100 items
|
22
|
+
# from a feed that shows fewer than 100 at any given time.
|
23
|
+
def config
|
24
|
+
@config ||= OpenStruct.new(
|
25
|
+
:version => '1.0',
|
26
|
+
:limit => 15,
|
27
|
+
:history => false
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Lookup will take any of these url formats:
|
32
|
+
# * http://example.com
|
33
|
+
# * http://example.com/
|
34
|
+
# * http://www.example.com/
|
35
|
+
# * www.example.com
|
36
|
+
# * example.com/rss
|
37
|
+
# * etc.
|
38
|
+
#
|
39
|
+
# And the object created will have the same Feed#canonical_id
|
40
|
+
# Use of Feed#new is strongly discouraged
|
41
|
+
def lookup url
|
42
|
+
http_response = JSON.parse open(api.lookup_query(url)).read
|
43
|
+
url = http_response["responseData"]["url"]
|
44
|
+
new url
|
45
|
+
end
|
46
|
+
|
47
|
+
def api #:nodoc:
|
48
|
+
API[config.version]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# A canonical identifier for the feed. Feeds found with Feed#lookup
|
53
|
+
# will have the some canonical_id even if the url used to find them
|
54
|
+
# was not 100% the same. (Missing '/' etc.)
|
55
|
+
def canonical_id
|
56
|
+
@url
|
57
|
+
end
|
58
|
+
|
59
|
+
# true if the lookup returned a positive match for a feed
|
60
|
+
def valid?
|
61
|
+
not @url.nil?
|
62
|
+
end
|
63
|
+
|
64
|
+
# The link of the feed.
|
65
|
+
def link
|
66
|
+
feed["link"]
|
67
|
+
end
|
68
|
+
|
69
|
+
# The author of the feed.
|
70
|
+
def author
|
71
|
+
feed["author"]
|
72
|
+
end
|
73
|
+
|
74
|
+
# The title of the feed.
|
75
|
+
def title
|
76
|
+
feed["title"]
|
77
|
+
end
|
78
|
+
|
79
|
+
# The description of the feed.
|
80
|
+
def description
|
81
|
+
feed["description"]
|
82
|
+
end
|
83
|
+
|
84
|
+
# List of Entry objects for this feed.
|
85
|
+
def entries
|
86
|
+
@entries ||= feed["entries"].map do |entry|
|
87
|
+
Entry.new(entry)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def load options={} #:nodoc:
|
92
|
+
url = self.class.api.load_query @url, options
|
93
|
+
|
94
|
+
# Very strange json bug. Bye bye tabs
|
95
|
+
http_response = JSON.parse open(url).read.gsub("\t", '')
|
96
|
+
|
97
|
+
@feed = http_response["responseData"]["feed"]
|
98
|
+
|
99
|
+
return @feed.length
|
100
|
+
end
|
101
|
+
|
102
|
+
def feed #:nodoc:
|
103
|
+
load if @feed.nil?
|
104
|
+
@feed
|
105
|
+
end
|
106
|
+
|
107
|
+
def initialize url #:nodoc:
|
108
|
+
@url = url
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
data/spec/api_spec.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec/helper'
|
2
|
+
|
3
|
+
describe Google::Ajax::Feed::API do
|
4
|
+
it "has V1.0 constants" do
|
5
|
+
GAF::API['1.0'].should_not be_nil
|
6
|
+
end
|
7
|
+
|
8
|
+
it "has 1.0 lookup endpoint" do
|
9
|
+
GAF::API['1.0'].lookup.
|
10
|
+
should == "http://ajax.googleapis.com/ajax/services/feed/lookup"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "has 1.0 find endpoint" do
|
14
|
+
GAF::API['1.0'].find.
|
15
|
+
should == "http://ajax.googleapis.com/ajax/services/feed/find"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "has 1.0 load endpoint" do
|
19
|
+
GAF::API['1.0'].load.
|
20
|
+
should == "http://ajax.googleapis.com/ajax/services/feed/load"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "constructs 1.0 lookups" do
|
24
|
+
blog_url = "http://someblog.com/?blog=franklins passion"
|
25
|
+
GAF::API['1.0'].lookup_query(blog_url).
|
26
|
+
should == "#{GAF::API['1.0'].lookup}?v=1.0&q=#{URI.encode blog_url}"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "constructs 1.0 finds" do
|
30
|
+
query = "senior superman's @w3s0me l33t <<>> machine"
|
31
|
+
GAF::API['1.0'].find_query(query).
|
32
|
+
should == "#{GAF::API['1.0'].find}?v=1.0&q=#{URI.encode query}"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "constructs 1.0 loads" do
|
36
|
+
blog_url = "http://someblog.com/?blog=franklins passion"
|
37
|
+
GAF::API['1.0'].load_query(blog_url).
|
38
|
+
should ==
|
39
|
+
"#{GAF::API['1.0'].load}?v=1.0&q=#{URI.encode blog_url}&num=15"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "constructs 1.0 loads with options" do
|
43
|
+
blog_url = "http://someblog.com/?blog=franklins passion"
|
44
|
+
GAF::API['1.0'].load_query(blog_url, :limit => 100, :history => true).
|
45
|
+
should ==
|
46
|
+
"#{GAF::API['1.0'].load}?v=1.0&q=#{URI.encode blog_url}&num=100&scoring=h"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "constructs 1.0 loads with config options" do
|
50
|
+
blog_url = "http://someblog.com/?blog=franklins passion"
|
51
|
+
GAF.config.history = true
|
52
|
+
GAF::API['1.0'].load_query(blog_url).
|
53
|
+
should ==
|
54
|
+
"#{GAF::API['1.0'].load}?v=1.0&q=#{URI.encode blog_url}&num=15&scoring=h"
|
55
|
+
GAF.config.history = nil
|
56
|
+
end
|
57
|
+
end
|
data/spec/entry_spec.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec/helper'
|
2
|
+
|
3
|
+
describe Google::Ajax::Feed::Entry do
|
4
|
+
before :each do
|
5
|
+
@feed = GAF.lookup('http://ajaxian.com')
|
6
|
+
@entry = @feed.entries.first
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "entry" do
|
10
|
+
it "exposes title" do
|
11
|
+
@entry.title.should_not be_nil
|
12
|
+
end
|
13
|
+
|
14
|
+
it "exposes link" do
|
15
|
+
@entry.link.should_not be_nil
|
16
|
+
end
|
17
|
+
|
18
|
+
it "exposes author" do
|
19
|
+
@entry.author.should_not be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it "exposes content" do
|
23
|
+
@entry.content.should_not be_nil
|
24
|
+
end
|
25
|
+
|
26
|
+
it "exposes snippet" do
|
27
|
+
@entry.snippet.should_not be_nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
data/spec/feed_spec.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec/helper'
|
2
|
+
|
3
|
+
describe Google::Ajax::Feed do
|
4
|
+
it "has configuration" do
|
5
|
+
GAF.config.should be_is_a(OpenStruct)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "has default version" do
|
9
|
+
GAF.config.version.should == '1.0'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "has default number to load" do
|
13
|
+
GAF.config.limit.should == 15
|
14
|
+
end
|
15
|
+
|
16
|
+
it "api set from config" do
|
17
|
+
GAF.api.should == GAF::API['1.0']
|
18
|
+
end
|
19
|
+
|
20
|
+
it "looks up feeds" do
|
21
|
+
GAF.lookup('http://ajaxian.com').should_not be_nil
|
22
|
+
end
|
23
|
+
|
24
|
+
it "validates feeds" do
|
25
|
+
GAF.new(nil).should_not be_valid
|
26
|
+
end
|
27
|
+
|
28
|
+
it "loads feed" do
|
29
|
+
f = GAF.lookup('http://ajaxian.com')
|
30
|
+
f.load
|
31
|
+
f.feed.should_not be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "feed attributes" do
|
35
|
+
before :each do
|
36
|
+
@feed = GAF.lookup('http://ajaxian.com')
|
37
|
+
end
|
38
|
+
|
39
|
+
it "exposes title" do
|
40
|
+
@feed.title.should == "Ajaxian » Front Page"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "exposes link" do
|
44
|
+
@feed.link.should == "http://ajaxian.com"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "exposes author" do
|
48
|
+
@feed.author.should == ""
|
49
|
+
end
|
50
|
+
|
51
|
+
it "exposes description" do
|
52
|
+
@feed.description.should == "Cleaning up the web with Ajax"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "exposes entries" do
|
56
|
+
@feed.entries.should be_is_a(Array)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it "feeds have canonical_id" do
|
61
|
+
a= GAF.lookup('http://ajaxian.com')
|
62
|
+
b= GAF.lookup('http://www.ajaxian.com')
|
63
|
+
c= GAF.lookup('http://ajaxian.com/')
|
64
|
+
d= GAF.lookup('http://www.ajaxian.com/')
|
65
|
+
e= GAF.lookup('http://ajaxian.com/index.xml')
|
66
|
+
|
67
|
+
a.canonical_id.should_not be_nil
|
68
|
+
a.canonical_id.should == b.canonical_id
|
69
|
+
a.canonical_id.should == c.canonical_id
|
70
|
+
a.canonical_id.should == d.canonical_id
|
71
|
+
a.canonical_id.should == e.canonical_id
|
72
|
+
end
|
73
|
+
end
|
data/spec/helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: collin-google_ajax_feed_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Collin Miller
|
@@ -59,8 +59,17 @@ extra_rdoc_files: []
|
|
59
59
|
files:
|
60
60
|
- README
|
61
61
|
- Rakefile.rb
|
62
|
+
- lib/google_ajax_feed_api
|
63
|
+
- lib/google_ajax_feed_api/api.rb
|
64
|
+
- lib/google_ajax_feed_api/api
|
65
|
+
- lib/google_ajax_feed_api/api/one_zero.rb
|
66
|
+
- lib/google_ajax_feed_api/feed.rb
|
67
|
+
- lib/google_ajax_feed_api/entry.rb
|
62
68
|
- lib/google_ajax_feed_api.rb
|
63
|
-
- spec/
|
69
|
+
- spec/helper.rb
|
70
|
+
- spec/entry_spec.rb
|
71
|
+
- spec/feed_spec.rb
|
72
|
+
- spec/api_spec.rb
|
64
73
|
has_rdoc: true
|
65
74
|
homepage: http://github.com/collin/fold
|
66
75
|
post_install_message:
|
@@ -1,160 +0,0 @@
|
|
1
|
-
require 'lib/google_ajax_feed_api'
|
2
|
-
require 'rubygems'
|
3
|
-
require 'spec'
|
4
|
-
|
5
|
-
GAF = Google::Ajax::Feed
|
6
|
-
|
7
|
-
describe Google::Ajax::Feed::Entry do
|
8
|
-
before :each do
|
9
|
-
@feed = GAF.lookup('http://ajaxian.com')
|
10
|
-
@entry = @feed.entries.first
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "entry" do
|
14
|
-
it "exposes title" do
|
15
|
-
@entry.title.should_not be_nil
|
16
|
-
end
|
17
|
-
|
18
|
-
it "exposes link" do
|
19
|
-
@entry.link.should_not be_nil
|
20
|
-
end
|
21
|
-
|
22
|
-
it "exposes author" do
|
23
|
-
@entry.author.should_not be_nil
|
24
|
-
end
|
25
|
-
|
26
|
-
it "exposes content" do
|
27
|
-
@entry.content.should_not be_nil
|
28
|
-
end
|
29
|
-
|
30
|
-
it "exposes snippet" do
|
31
|
-
@entry.snippet.should_not be_nil
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe Google::Ajax::Feed do
|
37
|
-
it "has V1.0 constants" do
|
38
|
-
GAF::API['1.0'].should_not be_nil
|
39
|
-
end
|
40
|
-
|
41
|
-
it "has 1.0 lookup endpoint" do
|
42
|
-
GAF::API['1.0'].lookup.
|
43
|
-
should == "http://ajax.googleapis.com/ajax/services/feed/lookup"
|
44
|
-
end
|
45
|
-
|
46
|
-
it "has 1.0 find endpoint" do
|
47
|
-
GAF::API['1.0'].find.
|
48
|
-
should == "http://ajax.googleapis.com/ajax/services/feed/find"
|
49
|
-
end
|
50
|
-
|
51
|
-
it "has 1.0 load endpoint" do
|
52
|
-
GAF::API['1.0'].load.
|
53
|
-
should == "http://ajax.googleapis.com/ajax/services/feed/load"
|
54
|
-
end
|
55
|
-
|
56
|
-
it "constructs 1.0 lookups" do
|
57
|
-
blog_url = "http://someblog.com/?blog=franklins passion"
|
58
|
-
GAF::API['1.0'].lookup_query(blog_url).
|
59
|
-
should == "#{GAF::API['1.0'].lookup}?v=1.0&q=#{URI.encode blog_url}"
|
60
|
-
end
|
61
|
-
|
62
|
-
it "constructs 1.0 finds" do
|
63
|
-
query = "senior superman's @w3s0me l33t <<>> machine"
|
64
|
-
GAF::API['1.0'].find_query(query).
|
65
|
-
should == "#{GAF::API['1.0'].find}?v=1.0&q=#{URI.encode query}"
|
66
|
-
end
|
67
|
-
|
68
|
-
it "constructs 1.0 loads" do
|
69
|
-
blog_url = "http://someblog.com/?blog=franklins passion"
|
70
|
-
GAF::API['1.0'].load_query(blog_url).
|
71
|
-
should ==
|
72
|
-
"#{GAF::API['1.0'].load}?v=1.0&q=#{URI.encode blog_url}&num=15"
|
73
|
-
end
|
74
|
-
|
75
|
-
it "constructs 1.0 loads with options" do
|
76
|
-
blog_url = "http://someblog.com/?blog=franklins passion"
|
77
|
-
GAF::API['1.0'].load_query(blog_url, :limit => 100, :history => true).
|
78
|
-
should ==
|
79
|
-
"#{GAF::API['1.0'].load}?v=1.0&q=#{URI.encode blog_url}&num=100&scoring=h"
|
80
|
-
end
|
81
|
-
|
82
|
-
it "constructs 1.0 loads with config options" do
|
83
|
-
blog_url = "http://someblog.com/?blog=franklins passion"
|
84
|
-
GAF.config.history = true
|
85
|
-
GAF::API['1.0'].load_query(blog_url).
|
86
|
-
should ==
|
87
|
-
"#{GAF::API['1.0'].load}?v=1.0&q=#{URI.encode blog_url}&num=15&scoring=h"
|
88
|
-
GAF.config.history = nil
|
89
|
-
end
|
90
|
-
|
91
|
-
it "has configuration" do
|
92
|
-
GAF.config.should be_is_a(OpenStruct)
|
93
|
-
end
|
94
|
-
|
95
|
-
it "has default version" do
|
96
|
-
GAF.config.version.should == '1.0'
|
97
|
-
end
|
98
|
-
|
99
|
-
it "has default number to load" do
|
100
|
-
GAF.config.limit.should == 15
|
101
|
-
end
|
102
|
-
|
103
|
-
it "api set from config" do
|
104
|
-
GAF.api.should == GAF::API['1.0']
|
105
|
-
end
|
106
|
-
|
107
|
-
it "looks up feeds" do
|
108
|
-
GAF.lookup('http://ajaxian.com').should_not be_nil
|
109
|
-
end
|
110
|
-
|
111
|
-
it "validates feeds" do
|
112
|
-
GAF.new(nil).should_not be_valid
|
113
|
-
end
|
114
|
-
|
115
|
-
it "loads feed" do
|
116
|
-
f = GAF.lookup('http://ajaxian.com')
|
117
|
-
f.load
|
118
|
-
f.feed.should_not be_nil
|
119
|
-
end
|
120
|
-
|
121
|
-
describe "feed attributes" do
|
122
|
-
before :each do
|
123
|
-
@feed = GAF.lookup('http://ajaxian.com')
|
124
|
-
end
|
125
|
-
|
126
|
-
it "exposes title" do
|
127
|
-
@feed.title.should == "Ajaxian » Front Page"
|
128
|
-
end
|
129
|
-
|
130
|
-
it "exposes link" do
|
131
|
-
@feed.link.should == "http://ajaxian.com"
|
132
|
-
end
|
133
|
-
|
134
|
-
it "exposes author" do
|
135
|
-
@feed.author.should == ""
|
136
|
-
end
|
137
|
-
|
138
|
-
it "exposes description" do
|
139
|
-
@feed.description.should == "Cleaning up the web with Ajax"
|
140
|
-
end
|
141
|
-
|
142
|
-
it "exposes entries" do
|
143
|
-
@feed.entries.should be_is_a(Array)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
it "feeds have canonical_id" do
|
148
|
-
a= GAF.lookup('http://ajaxian.com')
|
149
|
-
b= GAF.lookup('http://www.ajaxian.com')
|
150
|
-
c= GAF.lookup('http://ajaxian.com/')
|
151
|
-
d= GAF.lookup('http://www.ajaxian.com/')
|
152
|
-
e= GAF.lookup('http://ajaxian.com/index.xml')
|
153
|
-
|
154
|
-
a.canonical_id.should_not be_nil
|
155
|
-
a.canonical_id.should == b.canonical_id
|
156
|
-
a.canonical_id.should == c.canonical_id
|
157
|
-
a.canonical_id.should == d.canonical_id
|
158
|
-
a.canonical_id.should == e.canonical_id
|
159
|
-
end
|
160
|
-
end
|