googlereader 0.0.1 → 0.0.3

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/History.txt CHANGED
@@ -1,2 +1,8 @@
1
+ * 0.0.3
2
+ - updated manifest to include all files, 0.0.2 release was not up to date
3
+ * 0.0.2
4
+ - added wrapper for subscriptions
5
+ - added wrapper for preferences
6
+ - added Base#get_token for retrieving tokens from google
1
7
  * 0.0.1
2
8
  - labels and counts are working
data/Manifest.txt CHANGED
@@ -5,12 +5,19 @@ README.txt
5
5
  Rakefile
6
6
  config/hoe.rb
7
7
  config/requirements.rb
8
+ examples/base.rb
8
9
  examples/counts.rb
9
10
  examples/labels.rb
11
+ examples/preferences.rb
12
+ examples/search.rb
13
+ examples/subscriptions.rb
10
14
  lib/google/reader.rb
11
15
  lib/google/reader/base.rb
12
16
  lib/google/reader/count.rb
13
17
  lib/google/reader/label.rb
18
+ lib/google/reader/preference.rb
19
+ lib/google/reader/search.rb
20
+ lib/google/reader/subscription.rb
14
21
  lib/google/reader/version.rb
15
22
  log/debug.log
16
23
  script/destroy
data/README.txt CHANGED
@@ -1,12 +1,37 @@
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.
1
+ = Installation
3
2
 
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.
3
+ sudo gem install googlereader
7
4
 
8
- I'm using the following links below as documentation
9
- (and also a bit of reverse engineering with Firebug):
5
+ = Usage
6
+
7
+ require 'google/reader'
8
+ Google::Reader::Base.establish_connection('username', 'password')
9
+
10
+ # => all feeds and labels unread counts
11
+ pp Google::Reader::Count.all
12
+
13
+ # => all unread counts for labels
14
+ pp Google::Reader::Count.labels
15
+
16
+ # => all unread counts for feeds
17
+ pp Google::Reader::Count.feeds
18
+
19
+ # => all items for a label
20
+ pp Google::Reader::Label.all
21
+
22
+ puts 'Links'
23
+ # 5 latest unread items
24
+ unread = Google::Reader::Label.new('links').entries(:unread, :n => 5)
25
+ unread.each { |p| puts p.title }
26
+
27
+ puts 'Using Continuation'
28
+ # next 5 latest items after the unread above
29
+ more_unread = Google::Reader::Label.new('links').entries(:unread, :n => 5, :c => unread.continuation)
30
+ more_unread.each { |p| puts p.title }
31
+
32
+ = Notes
33
+
34
+ I'm using the following links below as documentation (and also a bit of reverse engineering with Firebug) until google releases an official and documented api:
10
35
 
11
36
  * http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI
12
37
  * http://blog.gpowered.net/2007/08/google-reader-api-functions.html
data/config/hoe.rb CHANGED
@@ -59,7 +59,7 @@ hoe = Hoe.new(GEM_NAME, VERS) do |p|
59
59
 
60
60
  # == Optional
61
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'] ]
62
+ p.extra_deps = [['googlebase', '>= 0.1.1'], ['atom', '>= 0.3'], ['json', '>= 1.1.1']] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
63
63
 
64
64
  #p.spec_extras = {} # A hash of extra values to set in the gemspec.
65
65
 
data/examples/base.rb ADDED
@@ -0,0 +1,10 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '/../lib')
2
+ require 'google/reader'
3
+ require 'pp'
4
+ require 'yaml'
5
+
6
+ config = YAML::load(open("#{ENV['HOME']}/.google"))
7
+ Google::Base.establish_connection(config[:email], config[:password])
8
+
9
+ pp Google::Reader::Base.get_token
10
+ pp Google::Reader::Base.user_info
data/examples/labels.rb CHANGED
@@ -14,7 +14,7 @@ pp labels
14
14
 
15
15
  # puts '', '==Links=='
16
16
  # unread = Google::Reader::Label.new('links').entries(:unread, :n => 5)
17
- # unread.each { |p| puts p.title }
17
+ # pp unread.first
18
18
  #
19
19
  # puts '', '===Using Continuation==='
20
20
  # more_unread = Google::Reader::Label.new('links').entries(:unread, :n => 5, :c => unread.continuation)
@@ -0,0 +1,14 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '/../lib')
2
+ require 'google/reader'
3
+ require 'pp'
4
+ require 'yaml'
5
+
6
+ config = YAML::load(open("#{ENV['HOME']}/.google"))
7
+ Google::Base.establish_connection(config[:email], config[:password])
8
+
9
+ pp Google::Reader::Preference.available
10
+ pp Google::Reader::Preference[:design]
11
+ pp Google::Reader::Preference[:mobile_use_transcoder]
12
+ pp Google::Reader::Preference[:mobile_num_entries]
13
+
14
+ pp Google::Reader::Preference.stream
@@ -0,0 +1,11 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '/../lib')
2
+ require 'google/reader'
3
+ require 'pp'
4
+ require 'yaml'
5
+
6
+ config = YAML::load(open("#{ENV['HOME']}/.google"))
7
+ Google::Base.establish_connection(config[:email], config[:password])
8
+
9
+ search = Google::Reader::Search.new('test')
10
+ search.execute
11
+ pp search.results
@@ -0,0 +1,9 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '/../lib')
2
+ require 'google/reader'
3
+ require 'pp'
4
+ require 'yaml'
5
+
6
+ config = YAML::load(open("#{ENV['HOME']}/.google"))
7
+ Google::Base.establish_connection(config[:email], config[:password])
8
+
9
+ pp Google::Reader::Subscription.all.detect { |s| s.categories.size > 1 }
data/lib/google/reader.rb CHANGED
@@ -5,7 +5,7 @@ require 'rubygems'
5
5
 
6
6
  gem 'atom', '>= 0.3'
7
7
  gem 'json', '>= 1.1.1'
8
- gem 'googlebase', '>= 0.1.0'
8
+ gem 'googlebase', '>= 0.1.1'
9
9
 
10
10
  require 'atom'
11
11
  require 'json'
@@ -13,17 +13,25 @@ require 'google/base'
13
13
  require 'google/reader/base'
14
14
  require 'google/reader/count'
15
15
  require 'google/reader/label'
16
+ require 'google/reader/preference'
17
+ require 'google/reader/search'
18
+ require 'google/reader/subscription'
16
19
 
17
20
  module Google
18
21
  module Reader
19
- READER_URL = Google::URL + "/reader"
22
+ READER_URL = Google::URL + '/reader'
20
23
  TOKEN_URL = READER_URL + "/api/0/token"
21
- SUBSCRIPTION_LIST_URL = READER_URL + '/api/0/subscription/list'
24
+ SEARCH_IDS_URL = READER_URL + "/api/0/search/items/ids"
25
+ SEARCH_CONTENTS_URL = READER_URL + "/api/0/stream/items/contents"
26
+ SUBSCRIPTION_LIST_URL = READER_URL + '/api/0/subscription/list?output=json'
22
27
  SUBSCRIPTION_EDIT_URL = READER_URL + '/api/0/subscription/edit'
23
28
  FEED_URL = READER_URL + '/atom/feed/%s'
24
29
  LABELS_URL = READER_URL + '/api/0/tag/list?output=json'
25
30
  LABEL_URL = READER_URL + '/atom/user/-/label/%s'
31
+ PREFERENCE_URL = READER_URL + '/api/0/preference/list?output=json'
32
+ PREFERENCE_STREAM_URL = READER_URL + '/api/0/preference/stream/list?output=json'
26
33
  UNREAD_COUNT_URL = READER_URL + '/api/0/unread-count?all=true&output=json'
34
+ USER_INFO_URL = READER_URL + '/user-info'
27
35
  PACKAGE = "user/-/state/com.google"
28
36
 
29
37
  module State
@@ -1,7 +1,7 @@
1
1
  module Google
2
2
  module Reader
3
3
  class Base < Base
4
- class << self
4
+ class << self
5
5
  def parse(atom_feed)
6
6
  Atom::Feed.new(atom_feed)
7
7
  end
@@ -23,6 +23,17 @@ module Google
23
23
  end
24
24
  end
25
25
 
26
+ # Gets a new token which can be used with all non-get requests.
27
+ def get_token
28
+ get(TOKEN_URL)
29
+ end
30
+
31
+ # Last time I checked this returns a hash like:
32
+ # {"isBloggerUser": true, "userId": "<user id number>", "userEmail": "nunemaker@gmail.com"}
33
+ def user_info
34
+ parse_json(get(USER_INFO_URL))
35
+ end
36
+
26
37
  private
27
38
  # atom parser doesn't bring in google's custom atom fields
28
39
  # this method grabs the continuation so that i can instantly
@@ -0,0 +1,50 @@
1
+ module Google
2
+ module Reader
3
+ class Preference < Base
4
+ @@greader_preferences = {}
5
+
6
+ class << self
7
+ # Returns a sorted list of all the available preference keys
8
+ #
9
+ # Usage:
10
+ # Google::Reader::Preference.available
11
+ def available
12
+ ensure_preferences_loaded
13
+ @@greader_preferences.keys.sort
14
+ end
15
+
16
+ # Gives access to an individual preference. Replace any dash
17
+ # in preference key with an underscore. (ie: mobile-num-entries
18
+ # is accessed using mobile_num_entries)
19
+ #
20
+ # Usage:
21
+ # Google::Reader::Preference[:design]
22
+ # Google::Reader::Preference[:mobile_use_transcoder]
23
+ def [](pref)
24
+ ensure_preferences_loaded
25
+ @@greader_preferences[pref.to_s.gsub('_', '-')]
26
+ end
27
+
28
+ # Returns any preferences set for each feed and label. Not sure
29
+ # what this could be helpful for so I'm not sure how to make things
30
+ # easily accessible. Right now just returns straight up hash, not
31
+ # very useful.
32
+ def stream #:nodoc:
33
+ parse_json(get(PREFERENCE_STREAM_URL))['streamprefs'].reject { |k,v| v == [] }
34
+ end
35
+
36
+ private
37
+ # Gets all the preferences from google
38
+ def load_all
39
+ parse_json(get(PREFERENCE_URL))['prefs'].each do |p|
40
+ @@greader_preferences[p['id']] = p['value']
41
+ end
42
+ end
43
+
44
+ def ensure_preferences_loaded
45
+ load_all if @@greader_preferences.keys.size == 0
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,45 @@
1
+ # This is getting the ids fine but I haven't figured out how
2
+ # to post multiple elements of the same name yet in ruby so
3
+ # don't use it unless you want to fix it.
4
+ module Google #:nodoc:
5
+ module Reader #:nodoc:
6
+ class Search < Base #:nodoc:
7
+ attr_accessor :q, :ids
8
+
9
+ def initialize(q)
10
+ self.q = q
11
+ @executed = false
12
+ end
13
+
14
+ def execute
15
+ response = self.class.get(SEARCH_IDS_URL, :query_hash => {
16
+ :num => 1000,
17
+ :output => 'json',
18
+ :q => q
19
+ })
20
+ self.ids = self.class.parse_json(response)['results'].collect { |r| r['id'] }
21
+ @executed = true
22
+ end
23
+
24
+ def results(o={})
25
+ options = {
26
+ :token => nil,
27
+ :start => 0,
28
+ :num => 20,
29
+ }.merge(o)
30
+
31
+ options[:token] ||= self.class.get_token
32
+
33
+ if ids.size > 0
34
+ i_str = ids[options[:start]] + '&'
35
+ i_str += ids[(options[:start]+1)..options[:num]].collect { |id| ["i=#{id}&"] unless id.nil? }.join('')
36
+
37
+ self.class.post(SEARCH_CONTENTS_URL, :form_data => {
38
+ :T => options[:token],
39
+ :i => i_str,
40
+ })
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,17 @@
1
+ require 'ostruct'
2
+ module Google
3
+ module Reader
4
+ class Subscription < Base
5
+ class << self
6
+ def all
7
+ parse_json(get(SUBSCRIPTION_LIST_URL))['subscriptions'].inject([]) do |subs, s|
8
+ subs << OpenStruct.new( :firstitemmsec => s['firstitemmsec'],
9
+ :title => s['title'],
10
+ :google_id => s['id'],
11
+ :categories => s['categories'].inject([]) { |cats, c| cats << OpenStruct.new(:google_id => c['id'], :name => c['label']) })
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -3,7 +3,7 @@ module Google #:nodoc:
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = 0
5
5
  MINOR = 0
6
- TINY = 1
6
+ TINY = 3
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
9
9
  end
metadata CHANGED
@@ -1,33 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: googlereader
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
7
- date: 2007-11-19 00:00:00 -05:00
8
- summary: Wrapper for the undocumented and potentially unstable Google Reader API
9
- require_paths:
10
- - lib
11
- email: nunemaker@gmail.com
12
- homepage: http://googlereader.rubyforge.org
13
- rubyforge_project: googlereader
14
- description: Wrapper for the undocumented and potentially unstable Google Reader API
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
25
- platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
4
+ version: 0.0.3
5
+ platform: ""
29
6
  authors:
30
7
  - John Nunemaker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2007-11-25 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: googlebase
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.1.1
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: atom
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: "0.3"
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: json
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.1
41
+ version:
42
+ description: Wrapper for the undocumented and potentially unstable Google Reader API
43
+ email: nunemaker@gmail.com
44
+ executables: []
45
+
46
+ extensions: []
47
+
48
+ extra_rdoc_files:
49
+ - History.txt
50
+ - License.txt
51
+ - Manifest.txt
52
+ - README.txt
31
53
  files:
32
54
  - History.txt
33
55
  - License.txt
@@ -36,12 +58,19 @@ files:
36
58
  - Rakefile
37
59
  - config/hoe.rb
38
60
  - config/requirements.rb
61
+ - examples/base.rb
39
62
  - examples/counts.rb
40
63
  - examples/labels.rb
64
+ - examples/preferences.rb
65
+ - examples/search.rb
66
+ - examples/subscriptions.rb
41
67
  - lib/google/reader.rb
42
68
  - lib/google/reader/base.rb
43
69
  - lib/google/reader/count.rb
44
70
  - lib/google/reader/label.rb
71
+ - lib/google/reader/preference.rb
72
+ - lib/google/reader/search.rb
73
+ - lib/google/reader/subscription.rb
45
74
  - lib/google/reader/version.rb
46
75
  - log/debug.log
47
76
  - script/destroy
@@ -54,22 +83,33 @@ files:
54
83
  - test/test_helper.rb
55
84
  - website/css/common.css
56
85
  - website/index.html
57
- test_files:
58
- - test/test_googlereader.rb
59
- - test/test_helper.rb
86
+ has_rdoc: true
87
+ homepage: http://googlereader.rubyforge.org
88
+ post_install_message:
60
89
  rdoc_options:
61
90
  - --main
62
91
  - README.txt
63
- extra_rdoc_files:
64
- - History.txt
65
- - License.txt
66
- - Manifest.txt
67
- - README.txt
68
- executables: []
69
-
70
- extensions: []
71
-
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: "0"
99
+ version:
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: "0"
105
+ version:
72
106
  requirements: []
73
107
 
74
- dependencies: []
75
-
108
+ rubyforge_project: googlereader
109
+ rubygems_version: 0.9.5
110
+ signing_key:
111
+ specification_version: 2
112
+ summary: Wrapper for the undocumented and potentially unstable Google Reader API
113
+ test_files:
114
+ - test/test_googlereader.rb
115
+ - test/test_helper.rb