markauskas-googlereader 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -9,9 +9,10 @@ begin
9
9
  gemspec.email = "info@tamole.net"
10
10
  gemspec.homepage = "http://github.com/markauskas/googlereader"
11
11
  gemspec.authors = ["Tomas Markauskas", "John Nunemaker"]
12
+ gemspec.add_dependency('activesupport') # For JSON && deep_merge
12
13
  gemspec.add_dependency('atom', '>= 0.3')
13
14
  gemspec.add_dependency('json', '>= 1.2.0')
14
- gemspec.add_dependency('markauskas-googlebase', '>= 0.3.0')
15
+ gemspec.add_dependency('markauskas-googlebase', '>= 0.3.2')
15
16
  end
16
17
 
17
18
  Jeweler::GemcutterTasks.new
@@ -26,3 +27,12 @@ Rake::TestTask.new(:test) do |test|
26
27
  end
27
28
 
28
29
  task :default => :test
30
+
31
+ task :a do
32
+ require 'yaml'
33
+ require File.dirname(__FILE__) + '/lib/google/reader'
34
+
35
+ GOOGLE_CONFIG = YAML::load(open(File.dirname(__FILE__) + '/test/.credentials.yml'))
36
+ Google::Base.establish_connection(GOOGLE_CONFIG['username'], GOOGLE_CONFIG['password'])
37
+ puts Google::Reader::Subscription.all.inspect
38
+ end
@@ -12,7 +12,8 @@ module Google
12
12
  end
13
13
 
14
14
  def parse_json(json_str)
15
- JSON.parse(json_str)
15
+ # JSON.parse(json_str)
16
+ ActiveSupport::JSON.decode(json_str)
16
17
  end
17
18
 
18
19
  def get_entries(url, o={})
@@ -0,0 +1,28 @@
1
+ module Google
2
+ module Reader
3
+ class Item < Base
4
+ # a = add state
5
+ # r = remove state
6
+ # s = feed/stream
7
+ # i = item
8
+ # T = token
9
+ def self.add_label(feed, item, label)
10
+ token = get_token
11
+ puts token
12
+ options = { :form_data => { :s => feed, :a => label, :i => item, :T => token } }
13
+ result = post(EDIT_LABEL_URL, options)
14
+ puts result
15
+ !!result =~ "OK"
16
+ end
17
+
18
+ def self.remove_label(feed, item, label)
19
+ token = get_token
20
+ puts token
21
+ options = { :form_data => { :s => feed, :r => label, :i => item, :T => token } }
22
+ result = post(EDIT_LABEL_URL, options)
23
+ puts result
24
+ !!result =~ "OK"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,17 +1,29 @@
1
1
  module Google
2
2
  module Reader
3
3
  class Stream < Base
4
- def self.fetch(feed_url, count = 20, o = {})
5
- feed_url = normalize_feed_url(feed_url)
6
- url = sprintf(JSON_FEED_URL, CGI.escape(feed_url))
4
+ # Params:
5
+ # xt - exclude target, e.g. xt=user/-/state/com.google/read
6
+ # r - order (n - newest first, o - oldest first)
7
+ # ot - if r=o, only items posted after ot are returned (unix timestamp)
8
+ # ck - current timestamp?
9
+ # c - continuation
10
+ # n - count
11
+ # client - ?
12
+ def self.fetch(feed_url, options = {})
13
+ url = sprintf(STREAM_URL, feed_url)
7
14
  options = {
8
15
  :query_hash => {
9
16
  :ck => Time.now.to_i,
10
- :n => count
17
+ :n => 20
11
18
  }
12
- }.merge(o)
19
+ }.deep_merge(options)
13
20
  json = get(url, options)
14
- data = JSON.parse(json)
21
+ data = parse_json(json)
22
+ end
23
+
24
+ def self.fetch_feed(feed_url, options = {})
25
+ feed_url = 'feed/' + CGI.escape(normalize_feed_url(feed_url))
26
+ fetch feed_url, options
15
27
  end
16
28
  end
17
29
  end
@@ -1,15 +1,11 @@
1
- require 'ostruct'
2
1
  module Google
3
2
  module Reader
4
3
  class Subscription < Base
5
4
  class << self
6
5
  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
6
+ json_str = get(SUBSCRIPTION_LIST_URL)
7
+ json = parse_json json_str
8
+ json['subscriptions']
13
9
  end
14
10
  end
15
11
  end
@@ -3,7 +3,7 @@ module Google #:nodoc:
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = 0
5
5
  MINOR = 1
6
- TINY = 1
6
+ TINY = 2
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
9
9
  end
data/lib/google/reader.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'cgi'
1
2
  require 'uri'
2
3
  require 'net/https'
3
4
  require 'net/http'
@@ -5,18 +6,22 @@ require 'rubygems'
5
6
 
6
7
  gem 'atom', '>= 0.3'
7
8
  gem 'json', '>= 1.2.0'
8
- gem 'markauskas-googlebase', '>= 0.3.0'
9
+ gem 'markauskas-googlebase', '>= 0.3.2'
10
+ gem 'activesupport'
9
11
 
10
12
  require 'atom'
11
13
  require 'json'
14
+ require 'active_support'
12
15
  require 'google/base'
13
- require 'google/reader/base'
14
- require 'google/reader/count'
15
- require 'google/reader/label'
16
- require 'google/reader/preference'
17
- require 'google/reader/search'
18
- require 'google/reader/stream'
19
- require 'google/reader/subscription'
16
+
17
+ require File.dirname(__FILE__) + '/reader/base'
18
+ require File.dirname(__FILE__) + '/reader/count'
19
+ require File.dirname(__FILE__) + '/reader/label'
20
+ require File.dirname(__FILE__) + '/reader/preference'
21
+ require File.dirname(__FILE__) + '/reader/search'
22
+ require File.dirname(__FILE__) + '/reader/stream'
23
+ require File.dirname(__FILE__) + '/reader/subscription'
24
+ require File.dirname(__FILE__) + '/reader/item'
20
25
 
21
26
  module Google
22
27
  module Reader
@@ -27,9 +32,10 @@ module Google
27
32
  SUBSCRIPTION_LIST_URL = READER_URL + '/api/0/subscription/list?output=json'
28
33
  SUBSCRIPTION_EDIT_URL = READER_URL + '/api/0/subscription/edit'
29
34
  ATOM_FEED_URL = READER_URL + '/atom/feed/%s'
30
- JSON_FEED_URL = READER_URL + '/api/0/stream/contents/feed/%s'
35
+ STREAM_URL = READER_URL + '/api/0/stream/contents/%s'
31
36
  LABELS_URL = READER_URL + '/api/0/tag/list?output=json'
32
37
  LABEL_URL = READER_URL + '/atom/user/-/label/%s'
38
+ EDIT_LABEL_URL = READER_URL + '/api/0/edit-tag'
33
39
  PREFERENCE_URL = READER_URL + '/api/0/preference/list?output=json'
34
40
  PREFERENCE_STREAM_URL = READER_URL + '/api/0/preference/stream/list?output=json'
35
41
  UNREAD_COUNT_URL = READER_URL + '/api/0/unread-count?all=true&output=json'
@@ -37,12 +43,14 @@ module Google
37
43
  PACKAGE = "user/-/state/com.google"
38
44
 
39
45
  module State
40
- READ = "#{PACKAGE}/read"
41
- KEPT_UNREAD = "#{PACKAGE}/kept-unread"
42
- FRESH = "#{PACKAGE}/fresh"
43
- STARRED = "#{PACKAGE}/starred"
44
- BROADCAST = "#{PACKAGE}/broadcast"
45
- READING_LIST = "#{PACKAGE}/reading-list"
46
+ READ = "#{PACKAGE}/read" # Read items
47
+ KEPT_UNREAD = "#{PACKAGE}/kept-unread" # Items marked as unread
48
+ FRESH = "#{PACKAGE}/fresh" # Unread items
49
+ STARRED = "#{PACKAGE}/starred" # Starred items
50
+ SELF = "#{PACKAGE}/self" # Shared + Notes?
51
+ BROADCAST = "#{PACKAGE}/broadcast" # Shared items from me
52
+ BROADCAST_FRIENDS = "#{PACKAGE}/broadcast-friends" # Shared items from friends
53
+ READING_LIST = "#{PACKAGE}/reading-list" # All items
46
54
  TRACKING_BODY_LINK_USED = "#{PACKAGE}/tracking-body-link-used"
47
55
  TRACKING_EMAILED = "#{PACKAGE}/tracking-emailed"
48
56
  TRACKING_ITEM_LINK_USED = "#{PACKAGE}/tracking-item-link-used"
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{markauskas-googlereader}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tomas Markauskas", "John Nunemaker"]
12
- s.date = %q{2010-02-01}
12
+ s.date = %q{2010-02-12}
13
13
  s.email = %q{info@tamole.net}
14
14
  s.extra_rdoc_files = [
15
15
  "README.txt"
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
  "lib/google/reader.rb",
24
24
  "lib/google/reader/base.rb",
25
25
  "lib/google/reader/count.rb",
26
+ "lib/google/reader/item.rb",
26
27
  "lib/google/reader/label.rb",
27
28
  "lib/google/reader/preference.rb",
28
29
  "lib/google/reader/search.rb",
@@ -33,6 +34,8 @@ Gem::Specification.new do |s|
33
34
  "markauskas-googlereader.gemspec",
34
35
  "test/.credentials.sample.yml",
35
36
  "test/googlereader_test.rb",
37
+ "test/stream_test.rb",
38
+ "test/subscription_test.rb",
36
39
  "test/test_helper.rb"
37
40
  ]
38
41
  s.homepage = %q{http://github.com/markauskas/googlereader}
@@ -42,6 +45,8 @@ Gem::Specification.new do |s|
42
45
  s.summary = %q{Ruby wrapper for Google Reader}
43
46
  s.test_files = [
44
47
  "test/googlereader_test.rb",
48
+ "test/stream_test.rb",
49
+ "test/subscription_test.rb",
45
50
  "test/test_helper.rb"
46
51
  ]
47
52
 
@@ -50,18 +55,21 @@ Gem::Specification.new do |s|
50
55
  s.specification_version = 3
51
56
 
52
57
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
58
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
53
59
  s.add_runtime_dependency(%q<atom>, [">= 0.3"])
54
60
  s.add_runtime_dependency(%q<json>, [">= 1.2.0"])
55
- s.add_runtime_dependency(%q<markauskas-googlebase>, [">= 0.3.0"])
61
+ s.add_runtime_dependency(%q<markauskas-googlebase>, [">= 0.3.2"])
56
62
  else
63
+ s.add_dependency(%q<activesupport>, [">= 0"])
57
64
  s.add_dependency(%q<atom>, [">= 0.3"])
58
65
  s.add_dependency(%q<json>, [">= 1.2.0"])
59
- s.add_dependency(%q<markauskas-googlebase>, [">= 0.3.0"])
66
+ s.add_dependency(%q<markauskas-googlebase>, [">= 0.3.2"])
60
67
  end
61
68
  else
69
+ s.add_dependency(%q<activesupport>, [">= 0"])
62
70
  s.add_dependency(%q<atom>, [">= 0.3"])
63
71
  s.add_dependency(%q<json>, [">= 1.2.0"])
64
- s.add_dependency(%q<markauskas-googlebase>, [">= 0.3.0"])
72
+ s.add_dependency(%q<markauskas-googlebase>, [">= 0.3.2"])
65
73
  end
66
74
  end
67
75
 
@@ -1,5 +1,4 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
- require 'cgi'
3
2
 
4
3
  class GooglereaderTest < Test::Unit::TestCase
5
4
  def setup
@@ -45,7 +44,7 @@ class GooglereaderTest < Test::Unit::TestCase
45
44
  # if feed_url contains a question mark (`?') it has to be escaped since
46
45
  # otherwise it would be interpreted as a part of the google reader url
47
46
  # and not the feed_url
48
- response = Google::Reader::Stream.fetch(feed_url, 1)
47
+ response = Google::Reader::Stream.fetch_feed(feed_url)
49
48
  assert_not_nil response
50
49
  assert_not_nil response['items']
51
50
  assert_not_nil response['title']
@@ -0,0 +1,88 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class StreamTest < Test::Unit::TestCase
4
+ def test_reading_list
5
+ list = Google::Reader::Stream.fetch(Google::Reader::State::READING_LIST, {:query_hash => {:n => 300}})
6
+ assert_not_nil list
7
+ assert_not_nil list['items']
8
+ assert list['items'].is_a?Array
9
+ list['items'].each do |item|
10
+ assert_not_nil item['id']
11
+
12
+ text = (item['content'] || item['summary'])
13
+ assert text
14
+ assert text.is_a?Hash
15
+ assert text.keys.sort == ['content', 'direction'].sort
16
+
17
+ assert_not_nil item['likingUsers']
18
+ assert item['likingUsers'].is_a?Array
19
+ item['likingUsers'].each do |liking_user|
20
+ assert liking_user.is_a?Hash
21
+ assert liking_user.keys == ["userId"]
22
+ end
23
+
24
+ assert_not_nil item['comments']
25
+ assert item['comments'].is_a?Array
26
+
27
+ assert_not_nil item['author']
28
+ assert item['author'].is_a?String
29
+
30
+ assert_not_nil item['title']
31
+
32
+ assert_not_nil item['annotations']
33
+ assert item['annotations'].is_a?Array
34
+
35
+ assert_not_nil item['alternate']
36
+ assert item['alternate'].is_a?Array
37
+ assert item['alternate'].length > 0
38
+ item['alternate'].each do |alt|
39
+ assert alt.is_a?Hash
40
+ assert alt.keys.sort == ["href", "type"].sort
41
+ end
42
+
43
+ assert_not_nil item['origin']
44
+ assert item['origin'].is_a?Hash
45
+ assert item['origin'].keys.sort == ["title", "htmlUrl", "streamId"].sort
46
+
47
+ assert_not_nil item['categories']
48
+ assert item['categories'].is_a?Array
49
+ item['categories'].each do |category|
50
+ assert category.is_a?String
51
+ end
52
+
53
+ assert_not_nil item['crawlTimeMsec']
54
+
55
+ assert_not_nil item['published']
56
+
57
+ assert_not_nil item['updated']
58
+ end
59
+ end
60
+
61
+ def test_reading_list_without_read_items
62
+ list = Google::Reader::Stream.fetch(Google::Reader::State::READING_LIST, {:query_hash => {:n => 100, :xt => Google::Reader::State::READ}})
63
+ assert_not_nil list
64
+ list['items'].each do |item|
65
+ item['categories'].each do |category|
66
+ assert !(category =~ /\Auser\/[0-9]+\/state\/com.google\/read\Z/)
67
+ end
68
+ end
69
+ end
70
+
71
+ def test_reading_list_order_by_newest
72
+ list = Google::Reader::Stream.fetch(Google::Reader::State::READING_LIST, {:query_hash => {:n => 30, :r => :n}})
73
+ previous = 0
74
+ list['items'].reverse.each do |item|
75
+ assert item['crawlTimeMsec'].to_i >= previous
76
+ previous = item['crawlTimeMsec'].to_i
77
+ end
78
+ end
79
+
80
+ def test_reading_list_order_by_oldest
81
+ list = Google::Reader::Stream.fetch(Google::Reader::State::READING_LIST, {:query_hash => {:n => 30, :r => :o}})
82
+ previous = 0
83
+ list['items'].each do |item|
84
+ assert item['crawlTimeMsec'].to_i >= previous
85
+ previous = item['crawlTimeMsec'].to_i
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class SubscriptionTest < Test::Unit::TestCase
4
+ def test_subscription_list
5
+ subs = Google::Reader::Subscription.all
6
+ assert_not_nil subs
7
+ assert subs.is_a?Array
8
+ subs.each do |sub|
9
+ assert sub.is_a?Hash
10
+ assert_equal sub.keys.sort, ["firstitemmsec", "title", "sortid", "id", "categories"].sort
11
+ end
12
+ end
13
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markauskas-googlereader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Markauskas
@@ -10,9 +10,19 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-02-01 00:00:00 +01:00
13
+ date: 2010-02-12 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: activesupport
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ version:
16
26
  - !ruby/object:Gem::Dependency
17
27
  name: atom
18
28
  type: :runtime
@@ -41,7 +51,7 @@ dependencies:
41
51
  requirements:
42
52
  - - ">="
43
53
  - !ruby/object:Gem::Version
44
- version: 0.3.0
54
+ version: 0.3.2
45
55
  version:
46
56
  description:
47
57
  email: info@tamole.net
@@ -60,6 +70,7 @@ files:
60
70
  - lib/google/reader.rb
61
71
  - lib/google/reader/base.rb
62
72
  - lib/google/reader/count.rb
73
+ - lib/google/reader/item.rb
63
74
  - lib/google/reader/label.rb
64
75
  - lib/google/reader/preference.rb
65
76
  - lib/google/reader/search.rb
@@ -70,6 +81,8 @@ files:
70
81
  - markauskas-googlereader.gemspec
71
82
  - test/.credentials.sample.yml
72
83
  - test/googlereader_test.rb
84
+ - test/stream_test.rb
85
+ - test/subscription_test.rb
73
86
  - test/test_helper.rb
74
87
  has_rdoc: true
75
88
  homepage: http://github.com/markauskas/googlereader
@@ -101,4 +114,6 @@ specification_version: 3
101
114
  summary: Ruby wrapper for Google Reader
102
115
  test_files:
103
116
  - test/googlereader_test.rb
117
+ - test/stream_test.rb
118
+ - test/subscription_test.rb
104
119
  - test/test_helper.rb