Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: http://svn.addictedtonew.com/public/gems/googlereader@126 fe7eae16-9a24-0410-a59d-9e59979e88be
- Loading branch information
jnunemaker
committed
Nov 20, 2007
0 parents
commit 4e181ed
Showing
25 changed files
with
2,168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* 0.0.1 | ||
- labels and counts are working |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2007 John Nunemaker | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
History.txt | ||
License.txt | ||
Manifest.txt | ||
README.txt | ||
Rakefile | ||
config/hoe.rb | ||
config/requirements.rb | ||
examples/counts.rb | ||
examples/labels.rb | ||
lib/google/reader.rb | ||
lib/google/reader/base.rb | ||
lib/google/reader/count.rb | ||
lib/google/reader/label.rb | ||
lib/google/reader/version.rb | ||
log/debug.log | ||
script/destroy | ||
script/generate | ||
setup.rb | ||
tasks/deployment.rake | ||
tasks/environment.rake | ||
tasks/website.rake | ||
test/test_googlereader.rb | ||
test/test_helper.rb | ||
website/css/common.css | ||
website/index.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Do not use this yet unless you are dying to help out. | ||
I'm going to gem this up and such when I finish the full api. | ||
|
||
Also, I'm going to separate Google::Connection into it's own | ||
gem and add that as a dependency for the reader gem. This will | ||
allow easy reuse of the google authentication. | ||
|
||
I'm using the following links below as documentation | ||
(and also a bit of reverse engineering with Firebug): | ||
|
||
* http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI | ||
* http://blog.gpowered.net/2007/08/google-reader-api-functions.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require 'config/requirements' | ||
require 'config/hoe' # setup Hoe + all gem configuration | ||
|
||
Dir['tasks/**/*.rake'].each { |rake| load rake } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
require 'google/reader/version' | ||
|
||
AUTHOR = 'John Nunemaker' # can also be an array of Authors | ||
EMAIL = "nunemaker@gmail.com" | ||
DESCRIPTION = "Wrapper for the undocumented and potentially unstable Google Reader API" | ||
GEM_NAME = 'googlereader' # what ppl will type to install your gem | ||
RUBYFORGE_PROJECT = 'googlereader' # The unix name for your project | ||
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org" | ||
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}" | ||
|
||
@config_file = "~/.rubyforge/user-config.yml" | ||
@config = nil | ||
RUBYFORGE_USERNAME = "jnunemaker" | ||
def rubyforge_username | ||
unless @config | ||
begin | ||
@config = YAML.load(File.read(File.expand_path(@config_file))) | ||
rescue | ||
puts <<-EOS | ||
ERROR: No rubyforge config file found: #{@config_file} | ||
Run 'rubyforge setup' to prepare your env for access to Rubyforge | ||
- See http://newgem.rubyforge.org/rubyforge.html for more details | ||
EOS | ||
exit | ||
end | ||
end | ||
RUBYFORGE_USERNAME.replace @config["username"] | ||
end | ||
|
||
|
||
REV = nil | ||
# UNCOMMENT IF REQUIRED: | ||
# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil | ||
VERS = Google::Reader::VERSION::STRING + (REV ? ".#{REV}" : "") | ||
RDOC_OPTS = ['--quiet', '--title', 'googlereader documentation', | ||
"--opname", "index.html", | ||
"--line-numbers", | ||
"--main", "README", | ||
"--inline-source"] | ||
|
||
class Hoe | ||
def extra_deps | ||
@extra_deps.reject! { |x| Array(x).first == 'hoe' } | ||
@extra_deps | ||
end | ||
end | ||
|
||
# Generate all the Rake tasks | ||
# Run 'rake -T' to see list of generated tasks (from gem root directory) | ||
hoe = Hoe.new(GEM_NAME, VERS) do |p| | ||
p.author = AUTHOR | ||
p.description = DESCRIPTION | ||
p.email = EMAIL | ||
p.summary = DESCRIPTION | ||
p.url = HOMEPATH | ||
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT | ||
p.test_globs = ["test/**/test_*.rb"] | ||
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean. | ||
|
||
# == Optional | ||
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n") | ||
#p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ] | ||
|
||
#p.spec_extras = {} # A hash of extra values to set in the gemspec. | ||
|
||
end | ||
|
||
CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n") | ||
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}" | ||
hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc') | ||
hoe.rsync_args = '-av --delete --ignore-errors' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require 'fileutils' | ||
include FileUtils | ||
|
||
require 'rubygems' | ||
%w[rake hoe newgem rubigen].each do |req_gem| | ||
begin | ||
require req_gem | ||
rescue LoadError | ||
puts "This Rakefile requires the '#{req_gem}' RubyGem." | ||
puts "Installation: gem install #{req_gem} -y" | ||
exit | ||
end | ||
end | ||
|
||
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib])) | ||
|
||
require 'google/reader' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
$:.unshift File.join(File.dirname(__FILE__), '/../lib') | ||
require 'google/reader' | ||
|
||
require 'pp' | ||
require 'yaml' | ||
config = YAML::load(open("#{ENV['HOME']}/.google")) | ||
|
||
Google::Base.establish_connection(config[:email], config[:password]) | ||
|
||
# pp Google::Reader::Count.all | ||
pp Google::Reader::Count.labels | ||
# pp Google::Reader::Count.feeds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
$:.unshift File.join(File.dirname(__FILE__), '/../lib') | ||
require 'google/reader' | ||
|
||
require 'pp' | ||
require 'yaml' | ||
config = YAML::load(open("#{ENV['HOME']}/.google")) | ||
|
||
Google::Base.establish_connection(config[:email], config[:password]) | ||
# Google::Base.set_connection(Google::Base.new(config[:email], config[:password])) | ||
|
||
puts '', '=Labels=' | ||
labels = Google::Reader::Label.all | ||
pp labels | ||
|
||
# puts '', '==Links==' | ||
# unread = Google::Reader::Label.new('links').entries(:unread, :n => 5) | ||
# unread.each { |p| puts p.title } | ||
# | ||
# puts '', '===Using Continuation===' | ||
# more_unread = Google::Reader::Label.new('links').entries(:unread, :n => 5, :c => unread.continuation) | ||
# more_unread.each { |p| puts p.title } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require 'uri' | ||
require 'net/https' | ||
require 'net/http' | ||
require 'rubygems' | ||
|
||
gem 'atom', '>= 0.3' | ||
gem 'json', '>= 1.1.1' | ||
gem 'googlebase', '>= 0.1.0' | ||
|
||
require 'atom' | ||
require 'json' | ||
require 'google/base' | ||
require 'google/reader/base' | ||
require 'google/reader/count' | ||
require 'google/reader/label' | ||
|
||
module Google | ||
module Reader | ||
READER_URL = Google::URL + "/reader" | ||
TOKEN_URL = READER_URL + "/api/0/token" | ||
SUBSCRIPTION_LIST_URL = READER_URL + '/api/0/subscription/list' | ||
SUBSCRIPTION_EDIT_URL = READER_URL + '/api/0/subscription/edit' | ||
FEED_URL = READER_URL + '/atom/feed/%s' | ||
LABELS_URL = READER_URL + '/api/0/tag/list?output=json' | ||
LABEL_URL = READER_URL + '/atom/user/-/label/%s' | ||
UNREAD_COUNT_URL = READER_URL + '/api/0/unread-count?all=true&output=json' | ||
PACKAGE = "user/-/state/com.google" | ||
|
||
module State | ||
READ = "#{PACKAGE}/read" | ||
KEPT_UNREAD = "#{PACKAGE}/kept-unread" | ||
FRESH = "#{PACKAGE}/fresh" | ||
STARRED = "#{PACKAGE}/starred" | ||
BROADCAST = "#{PACKAGE}/broadcast" | ||
READING_LIST = "#{PACKAGE}/reading-list" | ||
TRACKING_BODY_LINK_USED = "#{PACKAGE}/tracking-body-link-used" | ||
TRACKING_EMAILED = "#{PACKAGE}/tracking-emailed" | ||
TRACKING_ITEM_LINK_USED = "#{PACKAGE}/tracking-item-link-used" | ||
TRACKING_KEPT_UNREAD = "#{PACKAGE}/tracking-kept-unread" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Google | ||
module Reader | ||
class Base < Base | ||
class << self | ||
def parse(atom_feed) | ||
Atom::Feed.new(atom_feed) | ||
end | ||
|
||
def parse_json(json_str) | ||
JSON.parse(json_str) | ||
end | ||
|
||
def get_entries(url, o={}) | ||
options = {:continuation => true,}.merge(o) | ||
body = get(url) | ||
if options[:continuation] | ||
entries = parse(body).entries | ||
entries.class.class_eval "attr_accessor :continuation" | ||
entries.continuation = extract_continuation(body) | ||
entries | ||
else | ||
parse(body).entries | ||
end | ||
end | ||
|
||
private | ||
# atom parser doesn't bring in google's custom atom fields | ||
# this method grabs the continuation so that i can instantly | ||
# grab the next set of items | ||
# <gr:continuation>CO3urYix4Y8C</gr:continuation> | ||
def extract_continuation(body) | ||
matches = body.match(/<gr:continuation>(.*)<\/gr:continuation>/) | ||
matches.nil? ? nil : matches[0].gsub(/<\/?gr:continuation>/, '') | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'ostruct' | ||
module Google | ||
module Reader | ||
class Count < Base | ||
class << self | ||
# Gets all the unread counts | ||
# Usage: | ||
# Google::Reader::Count.all | ||
# | ||
# Returns and array of open structs with each entry looking like one of the following: | ||
# #<OpenStruct google_id="feed/http://feeds.feedburner.com/johnnunemaker", count=0> # => feed | ||
# #<OpenStruct google_id="user/{user_id}/label/friends", count=0> # => label | ||
def all | ||
parse_json(get(UNREAD_COUNT_URL))['unreadcounts'].inject([]) do |counts, c| | ||
counts << OpenStruct.new(:google_id => c['id'], :count => c['count']) | ||
end | ||
end | ||
|
||
# Gets all the unread counts, selects all the labels and converts them to Label objects | ||
# Usage: | ||
# Google::Reader::Count.labels | ||
# | ||
# Returns an array of these: | ||
# #<Google::Reader::Label:0x14923ec @count=0, @name="friends", @shared=false> | ||
def labels | ||
all.select { |c| c.google_id =~ /^user/ }.collect { |c| Label.new(c.google_id, nil, c.count) } | ||
end | ||
|
||
# Gets all the unread counts and selects all the feeds | ||
# Usage: | ||
# Google::Reader::Count.feeds | ||
# | ||
# Returns and array of these: | ||
# #<OpenStruct google_id="feed/http://feeds.feedburner.com/johnnunemaker", count=0> | ||
def feeds | ||
all.select { |c| c.google_id =~ /^feed/ } | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.