|
1 |
| -require 'gdata/base' |
| 1 | +require 'gdata/client' |
2 | 2 | require 'builder'
|
3 |
| -require 'hpricot' |
4 |
| -require 'rexml/document' |
| 3 | +require 'hpricot' |
| 4 | +require 'rexml/document' |
5 | 5 |
|
6 | 6 | module GData
|
7 | 7 |
|
8 | 8 | class Blogger < GData::Client
|
9 |
| - attr_reader :blog_id, :entry_id, :user_id, :blogs |
10 |
| - attr_writer :blog_id, :entry_id |
11 |
| - # Default initialization method. The blog ID and the entry ID may |
| 9 | + attr_reader :blog_id, :entry_id, :user_id, :blogs |
| 10 | + attr_writer :blog_id, :entry_id |
| 11 | + # Default initialization method. The blog ID and the entry ID may |
12 | 12 | # or may not be known ahead of time.
|
13 | 13 | def initialize(blog_id=nil, entry_id=nil)
|
14 | 14 | @blog_id = blog_id
|
15 | 15 | @entry_id = entry_id
|
16 | 16 | super 'blogger', 'gdata-ruby', 'www.blogger.com'
|
17 |
| - end |
18 |
| - |
19 |
| - # Pull down a list of the user's blogs. This allows the use of muliple blogs |
20 |
| - # per user. The @blogs Array will store the available blogs by internal hash. |
21 |
| - # |
22 |
| - def retrieve_blog_list |
23 |
| - # retrieve the user's list of blogs from |
24 |
| - blog_feed = get('/feeds/default/blogs') |
25 |
| - @blog_list = REXML::Document.new(blog_feed[1]).root |
26 |
| - @blogs = Array.new |
27 |
| - @blog_list.elements.each('entry'){|entry| @blogs.push({entry.elements['title'].get_text.to_s => entry.elements['id'].get_text.to_s.split(/blog-/).last})} |
28 |
| - # By default, set the first blog to @blog_id |
29 |
| - @blog_id = @blogs[0].values.to_s |
30 |
| - @blogs |
31 |
| - end |
32 |
| - # retrieves the user$ ID from the blog_list feed. |
33 |
| - def get_user_id |
34 |
| - # Because someone might call this method without the blog_list called, |
35 |
| - # we wouldn't have data to pull from. So let's call that method. |
36 |
| - self.blog_list |
37 |
| - uid = @blog_list.elements['id'].get_text.to_s.split(/-|\:/) |
38 |
| - @user_id = uid[uid.index("user")+1].delete(".blogs") |
39 |
| - end |
| 17 | + end |
| 18 | + |
| 19 | + # Pull down a list of the user's blogs. This allows the use of muliple blogs |
| 20 | + # per user. The @blogs Array will store the available blogs by internal hash. |
| 21 | + # |
| 22 | + def retrieve_blog_list |
| 23 | + # retrieve the user's list of blogs from |
| 24 | + blog_feed = get('/feeds/default/blogs') |
| 25 | + @blog_list = REXML::Document.new(blog_feed[1]).root |
| 26 | + @blogs = Array.new |
| 27 | + @blog_list.elements.each('entry'){|entry| @blogs.push({entry.elements['title'].get_text.to_s => entry.elements['id'].get_text.to_s.split(/blog-/).last})} |
| 28 | + # By default, set the first blog to @blog_id |
| 29 | + @blog_id = @blogs[0].values.to_s |
| 30 | + @blogs |
| 31 | + end |
| 32 | + # retrieves the user$ ID from the blog_list feed. |
| 33 | + def get_user_id |
| 34 | + # Because someone might call this method without the blog_list called, |
| 35 | + # we wouldn't have data to pull from. So let's call that method. |
| 36 | + self.blog_list |
| 37 | + uid = @blog_list.elements['id'].get_text.to_s.split(/-|\:/) |
| 38 | + @user_id = uid[uid.index("user")+1].delete(".blogs") |
| 39 | + end |
40 | 40 |
|
41 | 41 | def feed
|
42 | 42 | request "/feeds/#{@blog_id}/posts/default"
|
|
0 commit comments