grapi 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +21 -0
- data/MIT-LICENSE +20 -0
- data/README.textile +44 -0
- data/Rakefile +55 -0
- data/VERSION +1 -0
- data/example.rb +34 -0
- data/grapi.gemspec +62 -0
- data/lib/core_ext/string.rb +16 -0
- data/lib/grapi.rb +2 -0
- data/lib/grapi/parser.rb +55 -0
- data/lib/grapi/reader.rb +89 -0
- data/test/helper.rb +9 -0
- data/test/test_grapi.rb +7 -0
- metadata +97 -0
data/.gitignore
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009, 2010 Aurelian Oancea, <oancea [at] gmail.com>
|
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/README.textile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
h2. Grapi : Ruby client to access the unofficial Google Reader API
|
2
|
+
|
3
|
+
h3. Client Dependencies
|
4
|
+
|
5
|
+
* "Curb":http://github.com/taf2/curb (gem install curb)
|
6
|
+
|
7
|
+
h3. ReadingList Parser
|
8
|
+
|
9
|
+
* "Nokogiri":http://github.com/tenderlove/nokogiri (gem install nokogiri)
|
10
|
+
* "Loofah":http://github.com/flavorjones/loofah (gem install loofah)
|
11
|
+
|
12
|
+
h3. Synopsis
|
13
|
+
|
14
|
+
<pre>
|
15
|
+
require "rubygems"
|
16
|
+
require "grapi"
|
17
|
+
|
18
|
+
reader = Grapi::Reader.new
|
19
|
+
reader.login USERNAME, PASSWORD
|
20
|
+
|
21
|
+
require "grapi/parser"
|
22
|
+
list= Grapi::Parser::ReadingList.parse reader.reading_list
|
23
|
+
|
24
|
+
</pre>
|
25
|
+
|
26
|
+
h3. API methods
|
27
|
+
|
28
|
+
* initialize(verbose= false)
|
29
|
+
* login(USERNAME, PASSWORD)
|
30
|
+
* reading_list(continuation=nil, dump_data= false)
|
31
|
+
* subscribe(feed_url, label=test)
|
32
|
+
* unsubscribe(feed_url)
|
33
|
+
* mark_as_read(entry_google_id)
|
34
|
+
|
35
|
+
h3. License: see "MIT-LICENSE":http://github.com/aurelian/grapi/blob/master/MIT-LICENSE
|
36
|
+
|
37
|
+
h3. For: contact - ideas - patches please use github infrastructure
|
38
|
+
|
39
|
+
h3. Links
|
40
|
+
|
41
|
+
* "Friends of the Unofficial Google Reader API":http://groups.google.com/group/fougrapi
|
42
|
+
* "pyrfeed":http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI
|
43
|
+
* "Using the Google Reader API – Part 2":http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/
|
44
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "grapi"
|
8
|
+
gem.summary = %Q{Ruby client for unofficial Google Reader API}
|
9
|
+
gem.description = %Q{Ruby client for unofficial Google Reader API}
|
10
|
+
gem.email = "oancea@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/aurelian/grapi"
|
12
|
+
gem.authors = ["Aurelian Oancea"]
|
13
|
+
gem.add_dependency("curb", ">=0.6.1.0")
|
14
|
+
gem.add_dependency("nokogiri", ">=1.4.1")
|
15
|
+
gem.add_dependency("loofah", ">=0.4.1")
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
test.libs << 'lib' << 'test'
|
26
|
+
test.pattern = 'test/**/test_*.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
require 'rcov/rcovtask'
|
32
|
+
Rcov::RcovTask.new do |test|
|
33
|
+
test.libs << 'test'
|
34
|
+
test.pattern = 'test/**/test_*.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
37
|
+
rescue LoadError
|
38
|
+
task :rcov do
|
39
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
task :test => :check_dependencies
|
44
|
+
|
45
|
+
task :default => :test
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "grapi #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
data/example.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
$LOAD_PATH<< "lib"
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "grapi"
|
5
|
+
require "grapi/parser"
|
6
|
+
require "yaml"
|
7
|
+
|
8
|
+
def print_list(list)
|
9
|
+
puts "~> Got: #{list.gid} updated at: #{list.updated_at}\n\t contains: #{list.entries.size} items. continuation: #{list.continuation}"
|
10
|
+
list.entries.each do | entry |
|
11
|
+
puts "~> #{entry.title}"
|
12
|
+
puts "\tpublished at: #{entry.published_at}"
|
13
|
+
puts "\tcategories: \n\t\t#{entry.categories.map{|k| "label= #{k[:label]} | term= #{k[:term]}"}.join("\n\t\t")}"
|
14
|
+
puts "\tsource: #{entry.source[:title]}"
|
15
|
+
puts "\tauthor: #{entry.author}"
|
16
|
+
puts "\turl: #{entry.link}"
|
17
|
+
puts "\tsummary: #{entry.summary}"
|
18
|
+
puts "======================================================================="
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
config= YAML.load_file File.expand_path("~/.gdata.yml")
|
23
|
+
|
24
|
+
reader= Grapi::Reader.new(true)
|
25
|
+
reader.login config["username"], config["password"]
|
26
|
+
|
27
|
+
continuation= nil
|
28
|
+
loop do
|
29
|
+
list= Grapi::Parser::ReadingList.parse(reader.reading_list(continuation))
|
30
|
+
print_list list
|
31
|
+
continuation= list.continuation
|
32
|
+
break if continuation.nil?
|
33
|
+
end
|
34
|
+
|
data/grapi.gemspec
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{grapi}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Aurelian Oancea"]
|
12
|
+
s.date = %q{2009-12-29}
|
13
|
+
s.description = %q{Ruby client for unofficial Google Reader API}
|
14
|
+
s.email = %q{oancea@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.textile"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".gitignore",
|
20
|
+
"MIT-LICENSE",
|
21
|
+
"README.textile",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"example.rb",
|
25
|
+
"grapi.gemspec",
|
26
|
+
"lib/core_ext/string.rb",
|
27
|
+
"lib/grapi.rb",
|
28
|
+
"lib/grapi/parser.rb",
|
29
|
+
"lib/grapi/reader.rb",
|
30
|
+
"test/helper.rb",
|
31
|
+
"test/test_grapi.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/aurelian/grapi}
|
34
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.3.5}
|
37
|
+
s.summary = %q{Ruby client for unofficial Google Reader API}
|
38
|
+
s.test_files = [
|
39
|
+
"test/helper.rb",
|
40
|
+
"test/test_grapi.rb"
|
41
|
+
]
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_runtime_dependency(%q<curb>, [">= 0.6.1.0"])
|
49
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 1.4.1"])
|
50
|
+
s.add_runtime_dependency(%q<loofah>, [">= 0.4.1"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<curb>, [">= 0.6.1.0"])
|
53
|
+
s.add_dependency(%q<nokogiri>, [">= 1.4.1"])
|
54
|
+
s.add_dependency(%q<loofah>, [">= 0.4.1"])
|
55
|
+
end
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<curb>, [">= 0.6.1.0"])
|
58
|
+
s.add_dependency(%q<nokogiri>, [">= 1.4.1"])
|
59
|
+
s.add_dependency(%q<loofah>, [">= 0.4.1"])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
data/lib/grapi.rb
ADDED
data/lib/grapi/parser.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require "nokogiri"
|
2
|
+
require "loofah"
|
3
|
+
require "time"
|
4
|
+
|
5
|
+
module Grapi
|
6
|
+
|
7
|
+
module Parser
|
8
|
+
|
9
|
+
class Entry
|
10
|
+
attr_accessor :crawled_at, :summary, :gid, :categories, :published_at, :updated_at, :author, :source, :title, :link
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@categories= []
|
14
|
+
yield self
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class ReadingList
|
19
|
+
attr_accessor :entries, :gid, :updated_at, :continuation
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
@entries= []
|
23
|
+
yield self
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.parse(xml)
|
27
|
+
doc= Nokogiri::XML xml
|
28
|
+
Grapi::Parser::ReadingList.new do | list |
|
29
|
+
list.gid = doc.search("id").first.inner_text
|
30
|
+
list.updated_at = Time.parse(doc.search("updated").first.inner_text)
|
31
|
+
list.continuation = doc.at_xpath("//gr:continuation").inner_text rescue nil
|
32
|
+
doc.search("entry").each do | entry |
|
33
|
+
list.entries << Grapi::Parser::Entry.new do | e |
|
34
|
+
e.gid = entry.search("id").first.inner_text
|
35
|
+
e.title = entry.search("title").first.inner_text
|
36
|
+
e.published_at = Time.parse(entry.search("published").first.inner_text)
|
37
|
+
e.updated_at = Time.parse(entry.search("updated").first.inner_text)
|
38
|
+
e.link = entry.search("link").attr("href").value
|
39
|
+
e.crawled_at = Time.at(entry["crawl-timestamp-msec"].to_i/1000.0).utc
|
40
|
+
e.summary = Loofah.fragment(entry.search("summary").inner_text).scrub!(:strip).text
|
41
|
+
e.author = entry.search("author/name").inner_text
|
42
|
+
e.source = {
|
43
|
+
:id => entry.search("source/id").inner_text,
|
44
|
+
:title => entry.search("source/title").inner_text,
|
45
|
+
:link => entry.search("source/link").attr("href").value
|
46
|
+
}
|
47
|
+
entry.search("category").each { | category | e.categories << {:term=>category.attr("term"), :label=>category.attr("label")} }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
data/lib/grapi/reader.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'curl'
|
2
|
+
|
3
|
+
module Grapi
|
4
|
+
|
5
|
+
class Reader
|
6
|
+
|
7
|
+
def initialize(verbose= false)
|
8
|
+
@client = ::Curl::Easy.new do | easy |
|
9
|
+
easy.headers= {
|
10
|
+
"User-Agent" => "Grapi::Reader /0.2 +gzip",
|
11
|
+
"Accept-Encoding" => "gzip, deflate",
|
12
|
+
"GData-Version" => 2
|
13
|
+
}
|
14
|
+
easy.follow_location= true
|
15
|
+
easy.verbose= true if verbose
|
16
|
+
end
|
17
|
+
@token = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def get(url)
|
21
|
+
make_request(url){|c| c.http_get }
|
22
|
+
end
|
23
|
+
|
24
|
+
def post(url, params)
|
25
|
+
curl_post_params= params.inject([]){|p, e| p << ::Curl::PostField.content(e[0],e[1])}
|
26
|
+
make_request(url){|c| c.http_post(*curl_post_params)}
|
27
|
+
end
|
28
|
+
|
29
|
+
def post_with_token(url, params)
|
30
|
+
request_token if @token.nil?
|
31
|
+
params["T"]= @token
|
32
|
+
post url, params
|
33
|
+
end
|
34
|
+
|
35
|
+
def login(username, password)
|
36
|
+
post "https://www.google.com/accounts/ClientLogin", {
|
37
|
+
"Email" => username,
|
38
|
+
"Passwd" => password,
|
39
|
+
"source" => @client.headers["User-Agent"],
|
40
|
+
"service" => "reader",
|
41
|
+
"accountType" => "HOSTED_OR_GOOGLE"
|
42
|
+
}
|
43
|
+
@client.body_str.uncompress =~ /^SID=(.*)\n/
|
44
|
+
@client.headers['Cookie']= "SID=#{$1}"
|
45
|
+
self
|
46
|
+
end
|
47
|
+
|
48
|
+
def unsubscribe(feed_url)
|
49
|
+
edit_subscription "feed/#{feed_url}", "unsubscribe"
|
50
|
+
end
|
51
|
+
|
52
|
+
def subscribe(feed_url, label= "test")
|
53
|
+
edit_subscription "feed/#{feed_url}", "subscribe", {"a" => "user/-/label/#{label}"}
|
54
|
+
end
|
55
|
+
|
56
|
+
def mark_as_read(entry_id)
|
57
|
+
post_with_token "http://www.google.com/reader/api/0/edit-tag", {"i" => entry_id, "a" => "user/-/state/com.google/read"}
|
58
|
+
end
|
59
|
+
|
60
|
+
def reading_list(continuation= nil, dump_data= false)
|
61
|
+
get "http://www.google.com/reader/atom/user/-/state/com.google/reading-list?xt=user/-/state/com.google/read&ck=#{Time.now.to_i*1000}&n=1000&c=#{continuation}"
|
62
|
+
response= @client.body_str.uncompress
|
63
|
+
File.open("/tmp/#{Time.now.to_i}-reading_list.atom", "w"){|f|f<<response} if dump_data
|
64
|
+
response
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def edit_subscription(feed_url, action, params={})
|
70
|
+
post_with_token "http://www.google.com/reader/api/0/subscription/edit", { "s" => "feed/#{feed_url}", "ac" => action }.update(params)
|
71
|
+
response = @client.body_str.uncompress
|
72
|
+
unless response == "OK"
|
73
|
+
$stderr<< "WARN: [#{__FILE__}:#{__LINE__}] ~> response is not OK. probably token has expired!\n#{response}\n\n"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def request_token
|
78
|
+
get "http://www.google.com/reader/api/0/token"
|
79
|
+
@token = @client.body_str.uncompress
|
80
|
+
end
|
81
|
+
|
82
|
+
def make_request(url)
|
83
|
+
@client.url= url
|
84
|
+
yield @client
|
85
|
+
@client.perform
|
86
|
+
self
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/test/helper.rb
ADDED
data/test/test_grapi.rb
ADDED
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: grapi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aurelian Oancea
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-29 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: curb
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.6.1.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: nokogiri
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.4.1
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: loofah
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.4.1
|
44
|
+
version:
|
45
|
+
description: Ruby client for unofficial Google Reader API
|
46
|
+
email: oancea@gmail.com
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- README.textile
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- MIT-LICENSE
|
56
|
+
- README.textile
|
57
|
+
- Rakefile
|
58
|
+
- VERSION
|
59
|
+
- example.rb
|
60
|
+
- grapi.gemspec
|
61
|
+
- lib/core_ext/string.rb
|
62
|
+
- lib/grapi.rb
|
63
|
+
- lib/grapi/parser.rb
|
64
|
+
- lib/grapi/reader.rb
|
65
|
+
- test/helper.rb
|
66
|
+
- test/test_grapi.rb
|
67
|
+
has_rdoc: true
|
68
|
+
homepage: http://github.com/aurelian/grapi
|
69
|
+
licenses: []
|
70
|
+
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options:
|
73
|
+
- --charset=UTF-8
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: "0"
|
81
|
+
version:
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: "0"
|
87
|
+
version:
|
88
|
+
requirements: []
|
89
|
+
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 1.3.5
|
92
|
+
signing_key:
|
93
|
+
specification_version: 3
|
94
|
+
summary: Ruby client for unofficial Google Reader API
|
95
|
+
test_files:
|
96
|
+
- test/helper.rb
|
97
|
+
- test/test_grapi.rb
|