googlereader 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +2 -0
- data/License.txt +20 -0
- data/Manifest.txt +25 -0
- data/README.txt +12 -0
- data/Rakefile +4 -0
- data/config/hoe.rb +71 -0
- data/config/requirements.rb +17 -0
- data/examples/counts.rb +12 -0
- data/examples/labels.rb +21 -0
- data/lib/google/reader.rb +42 -0
- data/lib/google/reader/base.rb +38 -0
- data/lib/google/reader/count.rb +41 -0
- data/lib/google/reader/label.rb +80 -0
- data/lib/google/reader/version.rb +11 -0
- data/log/debug.log +0 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/setup.rb +1585 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +14 -0
- data/test/test_googlereader.rb +11 -0
- data/test/test_helper.rb +2 -0
- data/website/css/common.css +47 -0
- data/website/index.html +44 -0
- metadata +75 -0
data/History.txt
ADDED
data/License.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2007 John Nunemaker
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
config/hoe.rb
|
7
|
+
config/requirements.rb
|
8
|
+
examples/counts.rb
|
9
|
+
examples/labels.rb
|
10
|
+
lib/google/reader.rb
|
11
|
+
lib/google/reader/base.rb
|
12
|
+
lib/google/reader/count.rb
|
13
|
+
lib/google/reader/label.rb
|
14
|
+
lib/google/reader/version.rb
|
15
|
+
log/debug.log
|
16
|
+
script/destroy
|
17
|
+
script/generate
|
18
|
+
setup.rb
|
19
|
+
tasks/deployment.rake
|
20
|
+
tasks/environment.rake
|
21
|
+
tasks/website.rake
|
22
|
+
test/test_googlereader.rb
|
23
|
+
test/test_helper.rb
|
24
|
+
website/css/common.css
|
25
|
+
website/index.html
|
data/README.txt
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
Do not use this yet unless you are dying to help out.
|
2
|
+
I'm going to gem this up and such when I finish the full api.
|
3
|
+
|
4
|
+
Also, I'm going to separate Google::Connection into it's own
|
5
|
+
gem and add that as a dependency for the reader gem. This will
|
6
|
+
allow easy reuse of the google authentication.
|
7
|
+
|
8
|
+
I'm using the following links below as documentation
|
9
|
+
(and also a bit of reverse engineering with Firebug):
|
10
|
+
|
11
|
+
* http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI
|
12
|
+
* http://blog.gpowered.net/2007/08/google-reader-api-functions.html
|
data/Rakefile
ADDED
data/config/hoe.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'google/reader/version'
|
2
|
+
|
3
|
+
AUTHOR = 'John Nunemaker' # can also be an array of Authors
|
4
|
+
EMAIL = "nunemaker@gmail.com"
|
5
|
+
DESCRIPTION = "Wrapper for the undocumented and potentially unstable Google Reader API"
|
6
|
+
GEM_NAME = 'googlereader' # what ppl will type to install your gem
|
7
|
+
RUBYFORGE_PROJECT = 'googlereader' # The unix name for your project
|
8
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
9
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
10
|
+
|
11
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
12
|
+
@config = nil
|
13
|
+
RUBYFORGE_USERNAME = "jnunemaker"
|
14
|
+
def rubyforge_username
|
15
|
+
unless @config
|
16
|
+
begin
|
17
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
18
|
+
rescue
|
19
|
+
puts <<-EOS
|
20
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
21
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
22
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
23
|
+
EOS
|
24
|
+
exit
|
25
|
+
end
|
26
|
+
end
|
27
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
REV = nil
|
32
|
+
# UNCOMMENT IF REQUIRED:
|
33
|
+
# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
|
34
|
+
VERS = Google::Reader::VERSION::STRING + (REV ? ".#{REV}" : "")
|
35
|
+
RDOC_OPTS = ['--quiet', '--title', 'googlereader documentation',
|
36
|
+
"--opname", "index.html",
|
37
|
+
"--line-numbers",
|
38
|
+
"--main", "README",
|
39
|
+
"--inline-source"]
|
40
|
+
|
41
|
+
class Hoe
|
42
|
+
def extra_deps
|
43
|
+
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
44
|
+
@extra_deps
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Generate all the Rake tasks
|
49
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
50
|
+
hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
51
|
+
p.author = AUTHOR
|
52
|
+
p.description = DESCRIPTION
|
53
|
+
p.email = EMAIL
|
54
|
+
p.summary = DESCRIPTION
|
55
|
+
p.url = HOMEPATH
|
56
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
57
|
+
p.test_globs = ["test/**/test_*.rb"]
|
58
|
+
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
59
|
+
|
60
|
+
# == Optional
|
61
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
62
|
+
#p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
|
63
|
+
|
64
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
69
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
70
|
+
hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
71
|
+
hoe.rsync_args = '-av --delete --ignore-errors'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
include FileUtils
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
%w[rake hoe newgem rubigen].each do |req_gem|
|
6
|
+
begin
|
7
|
+
require req_gem
|
8
|
+
rescue LoadError
|
9
|
+
puts "This Rakefile requires the '#{req_gem}' RubyGem."
|
10
|
+
puts "Installation: gem install #{req_gem} -y"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
16
|
+
|
17
|
+
require 'google/reader'
|
data/examples/counts.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), '/../lib')
|
2
|
+
require 'google/reader'
|
3
|
+
|
4
|
+
require 'pp'
|
5
|
+
require 'yaml'
|
6
|
+
config = YAML::load(open("#{ENV['HOME']}/.google"))
|
7
|
+
|
8
|
+
Google::Base.establish_connection(config[:email], config[:password])
|
9
|
+
|
10
|
+
# pp Google::Reader::Count.all
|
11
|
+
pp Google::Reader::Count.labels
|
12
|
+
# pp Google::Reader::Count.feeds
|
data/examples/labels.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), '/../lib')
|
2
|
+
require 'google/reader'
|
3
|
+
|
4
|
+
require 'pp'
|
5
|
+
require 'yaml'
|
6
|
+
config = YAML::load(open("#{ENV['HOME']}/.google"))
|
7
|
+
|
8
|
+
Google::Base.establish_connection(config[:email], config[:password])
|
9
|
+
# Google::Base.set_connection(Google::Base.new(config[:email], config[:password]))
|
10
|
+
|
11
|
+
puts '', '=Labels='
|
12
|
+
labels = Google::Reader::Label.all
|
13
|
+
pp labels
|
14
|
+
|
15
|
+
# puts '', '==Links=='
|
16
|
+
# unread = Google::Reader::Label.new('links').entries(:unread, :n => 5)
|
17
|
+
# unread.each { |p| puts p.title }
|
18
|
+
#
|
19
|
+
# puts '', '===Using Continuation==='
|
20
|
+
# more_unread = Google::Reader::Label.new('links').entries(:unread, :n => 5, :c => unread.continuation)
|
21
|
+
# more_unread.each { |p| puts p.title }
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/https'
|
3
|
+
require 'net/http'
|
4
|
+
require 'rubygems'
|
5
|
+
|
6
|
+
gem 'atom', '>= 0.3'
|
7
|
+
gem 'json', '>= 1.1.1'
|
8
|
+
gem 'googlebase', '>= 0.1.0'
|
9
|
+
|
10
|
+
require 'atom'
|
11
|
+
require 'json'
|
12
|
+
require 'google/base'
|
13
|
+
require 'google/reader/base'
|
14
|
+
require 'google/reader/count'
|
15
|
+
require 'google/reader/label'
|
16
|
+
|
17
|
+
module Google
|
18
|
+
module Reader
|
19
|
+
READER_URL = Google::URL + "/reader"
|
20
|
+
TOKEN_URL = READER_URL + "/api/0/token"
|
21
|
+
SUBSCRIPTION_LIST_URL = READER_URL + '/api/0/subscription/list'
|
22
|
+
SUBSCRIPTION_EDIT_URL = READER_URL + '/api/0/subscription/edit'
|
23
|
+
FEED_URL = READER_URL + '/atom/feed/%s'
|
24
|
+
LABELS_URL = READER_URL + '/api/0/tag/list?output=json'
|
25
|
+
LABEL_URL = READER_URL + '/atom/user/-/label/%s'
|
26
|
+
UNREAD_COUNT_URL = READER_URL + '/api/0/unread-count?all=true&output=json'
|
27
|
+
PACKAGE = "user/-/state/com.google"
|
28
|
+
|
29
|
+
module State
|
30
|
+
READ = "#{PACKAGE}/read"
|
31
|
+
KEPT_UNREAD = "#{PACKAGE}/kept-unread"
|
32
|
+
FRESH = "#{PACKAGE}/fresh"
|
33
|
+
STARRED = "#{PACKAGE}/starred"
|
34
|
+
BROADCAST = "#{PACKAGE}/broadcast"
|
35
|
+
READING_LIST = "#{PACKAGE}/reading-list"
|
36
|
+
TRACKING_BODY_LINK_USED = "#{PACKAGE}/tracking-body-link-used"
|
37
|
+
TRACKING_EMAILED = "#{PACKAGE}/tracking-emailed"
|
38
|
+
TRACKING_ITEM_LINK_USED = "#{PACKAGE}/tracking-item-link-used"
|
39
|
+
TRACKING_KEPT_UNREAD = "#{PACKAGE}/tracking-kept-unread"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Google
|
2
|
+
module Reader
|
3
|
+
class Base < Base
|
4
|
+
class << self
|
5
|
+
def parse(atom_feed)
|
6
|
+
Atom::Feed.new(atom_feed)
|
7
|
+
end
|
8
|
+
|
9
|
+
def parse_json(json_str)
|
10
|
+
JSON.parse(json_str)
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_entries(url, o={})
|
14
|
+
options = {:continuation => true,}.merge(o)
|
15
|
+
body = get(url)
|
16
|
+
if options[:continuation]
|
17
|
+
entries = parse(body).entries
|
18
|
+
entries.class.class_eval "attr_accessor :continuation"
|
19
|
+
entries.continuation = extract_continuation(body)
|
20
|
+
entries
|
21
|
+
else
|
22
|
+
parse(body).entries
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
# atom parser doesn't bring in google's custom atom fields
|
28
|
+
# this method grabs the continuation so that i can instantly
|
29
|
+
# grab the next set of items
|
30
|
+
# <gr:continuation>CO3urYix4Y8C</gr:continuation>
|
31
|
+
def extract_continuation(body)
|
32
|
+
matches = body.match(/<gr:continuation>(.*)<\/gr:continuation>/)
|
33
|
+
matches.nil? ? nil : matches[0].gsub(/<\/?gr:continuation>/, '')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
module Google
|
3
|
+
module Reader
|
4
|
+
class Count < Base
|
5
|
+
class << self
|
6
|
+
# Gets all the unread counts
|
7
|
+
# Usage:
|
8
|
+
# Google::Reader::Count.all
|
9
|
+
#
|
10
|
+
# Returns and array of open structs with each entry looking like one of the following:
|
11
|
+
# #<OpenStruct google_id="feed/http://feeds.feedburner.com/johnnunemaker", count=0> # => feed
|
12
|
+
# #<OpenStruct google_id="user/{user_id}/label/friends", count=0> # => label
|
13
|
+
def all
|
14
|
+
parse_json(get(UNREAD_COUNT_URL))['unreadcounts'].inject([]) do |counts, c|
|
15
|
+
counts << OpenStruct.new(:google_id => c['id'], :count => c['count'])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Gets all the unread counts, selects all the labels and converts them to Label objects
|
20
|
+
# Usage:
|
21
|
+
# Google::Reader::Count.labels
|
22
|
+
#
|
23
|
+
# Returns an array of these:
|
24
|
+
# #<Google::Reader::Label:0x14923ec @count=0, @name="friends", @shared=false>
|
25
|
+
def labels
|
26
|
+
all.select { |c| c.google_id =~ /^user/ }.collect { |c| Label.new(c.google_id, nil, c.count) }
|
27
|
+
end
|
28
|
+
|
29
|
+
# Gets all the unread counts and selects all the feeds
|
30
|
+
# Usage:
|
31
|
+
# Google::Reader::Count.feeds
|
32
|
+
#
|
33
|
+
# Returns and array of these:
|
34
|
+
# #<OpenStruct google_id="feed/http://feeds.feedburner.com/johnnunemaker", count=0>
|
35
|
+
def feeds
|
36
|
+
all.select { |c| c.google_id =~ /^feed/ }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module Google
|
2
|
+
module Reader
|
3
|
+
class Label < Base
|
4
|
+
class << self
|
5
|
+
# Usage:
|
6
|
+
# Google::Reader::Label.all
|
7
|
+
def all
|
8
|
+
parse_json(get(LABELS_URL))['tags'].inject([]) do |labels, l|
|
9
|
+
labels << new(l['id'], l['shared'])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
VALID_KEYS = [:n, :c]
|
15
|
+
|
16
|
+
attr_reader :shared
|
17
|
+
attr_accessor :count
|
18
|
+
|
19
|
+
# Usage:
|
20
|
+
# Google::Reader::Label.new('friends')
|
21
|
+
# Google::Reader::Label.new('friends', false)
|
22
|
+
# Google::Reader::Label.new('friends', false, 3)
|
23
|
+
def initialize(name, shared=false, count=0)
|
24
|
+
self.name = name
|
25
|
+
self.shared = shared
|
26
|
+
self.count = count
|
27
|
+
end
|
28
|
+
|
29
|
+
# Converts user/{user-id}/label/security to security.
|
30
|
+
def name=(new_name)
|
31
|
+
@name = new_name.split('/').last
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns name; converts broadcast label to shared to be consistent with google
|
35
|
+
def name
|
36
|
+
@name == 'broadcast' ? 'shared' : @name
|
37
|
+
end
|
38
|
+
|
39
|
+
def shared=(new_shared)
|
40
|
+
if new_shared.is_a?(String)
|
41
|
+
@shared = new_shared == 'no' ? false : true
|
42
|
+
else
|
43
|
+
@shared = new_shared.nil? ? false : true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Usage:
|
48
|
+
# Google::Reader::Label.new('friends').entries
|
49
|
+
# Google::Reader::Label.new('friends').entries(:all, :n => 25)
|
50
|
+
# Google::Reader::Label.new('friends').entries(:unread)
|
51
|
+
# Google::Reader::Label.new('friends').entries(:unread, :n => 25)
|
52
|
+
#
|
53
|
+
# To use with continuations:
|
54
|
+
# unread = Google::Reader::Label.new('friends').entries(:unread)
|
55
|
+
# next_unread = Google::Reader::Label.new('friends').entries(:unread, :c => unread.continuation)
|
56
|
+
#
|
57
|
+
# The examples above would grab the first 15 unread entries and then using google reader's
|
58
|
+
# continuations, the next 15 unread after the first 15.
|
59
|
+
def entries(which=nil, o={})
|
60
|
+
options = {:n => 15,}.merge(o)
|
61
|
+
query_str = valid_keys_to_query_string(o)
|
62
|
+
url = case which
|
63
|
+
when :unread
|
64
|
+
sprintf(LABEL_URL, @name) + "?xt=#{State::READ}&#{query_str}"
|
65
|
+
else
|
66
|
+
sprintf(LABEL_URL, @name)
|
67
|
+
end
|
68
|
+
self.class.get_entries(url, :continuation => true)
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
# Converts a hash to a query string but only keys that are valid
|
73
|
+
def valid_keys_to_query_string(o)
|
74
|
+
str = ''
|
75
|
+
o.each { |k,v| str << "#{k}=#{v}&" if VALID_KEYS.include?(k) }
|
76
|
+
str
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/log/debug.log
ADDED
File without changes
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.join(File.dirname(__FILE__), '..')
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.join(File.dirname(__FILE__), '..')
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|