readit 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -7,11 +7,11 @@ group :development, :test do
7
7
  gem 'guard'
8
8
  gem 'guard-rspec'
9
9
 
10
- # if RUBY_PLATFORM =~ /darwin/
11
- # # OS X integration
12
- # gem "ruby_gntp"
13
- # gem "rb-fsevent", "~> 0.4.3.1"
14
- # end
10
+ if RUBY_PLATFORM =~ /darwin/
11
+ # OS X integration
12
+ gem "ruby_gntp"
13
+ gem "rb-fsevent", "~> 0.4.3.1"
14
+ end
15
15
  end
16
16
  gem 'oauth'
17
17
 
data/Readme.md CHANGED
@@ -11,6 +11,8 @@ or in your rails gemfile
11
11
  ``` ruby
12
12
 
13
13
  gem 'readit'
14
+ # or latest (recommend)
15
+ gem 'readit',:git=>'git@github.com:29decibel/readit.git'
14
16
  ```
15
17
 
16
18
  ### Configuration
@@ -39,11 +41,13 @@ Readit::Config.consumer_secret = some_value
39
41
 
40
42
  # get user info
41
43
  @api.me
42
- # get all bookmarks
44
+ # get all bookmarks, result will be a hash array
43
45
  @api.bookmarks
44
46
  # get one artile by article_id
45
47
  @api.article 'article_id'
46
48
  # add bookmark
47
- @api.add_bookmark :url=>'http://some_article_url.html'
49
+ @api.bookmark :url=>'http://some_article_url.html'
50
+ # get bookmark by bookmark_id
51
+ @api.bookmarks :bookmark_id => some_bookmark_id
48
52
  ```
49
53
 
@@ -1,3 +1,3 @@
1
1
  module Readit
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/readit.rb CHANGED
@@ -29,11 +29,18 @@ module Readit
29
29
  end
30
30
 
31
31
  class API
32
- # Create a new Readit API client
32
+ # initializer if creating a new Readit API client
33
+ # @param access_token access_token of user
34
+ # @param access_token_secret access_token_secret of user
33
35
  def initialize(access_token='',access_token_secret='')
36
+ if access_token == '' or access_token_secret == ''
37
+ raise ReaditError.new('have to provide access_token and access_token_secret')
38
+ end
39
+ if Readit::Config.consumer_key=='' or Readit::Config.consumer_secret==''
40
+ raise ReaditError.new('please set Readit::Config.consumer_key or Readit::Config.consumer_secret first')
41
+ end
34
42
  @access_token = access_token
35
43
  @access_token_secret = access_token_secret
36
- load_config
37
44
  end
38
45
 
39
46
  attr_reader :access_token
@@ -41,54 +48,80 @@ module Readit
41
48
  SITE_URL = 'https://www.readability.com/'
42
49
 
43
50
  # Retrieve the base API URI - information about subresources.
44
- # /
45
51
  def resource_info
46
52
  request(:get,'/')
47
53
  end
48
54
 
49
55
  # Retrieve a single Article, including its content.
50
- # /articles/{article_id}
56
+ # api rest address: /articles/{article_id}
57
+ # @param article_id the article_id
51
58
  def article(article_id)
52
59
  request(:get,"/articles/#{article_id}")
53
60
  end
54
61
 
55
62
  # Retrieve the bookmarks collection. Automatically filtered to the current user.
56
- # bookmark_id support
57
- #
58
- # /bookmarks?archive&favorite&domain&added_since&added_until&opened_since&opened_until&
59
- # archived_since&archived_until&favorited_since&favorited_until&updated_since&updated_until&
60
- # order&page&per_page&exclude_accessibility&only_deleted
61
- #
62
- # /bookmarks/{bookmark_id}
63
+ # api rest address : /bookmarks? or /bookmarks/{bookmark_id}
64
+ # @args support
65
+ # bookmark_id (at most return one record)
66
+ # archive
67
+ # favorite
68
+ # domain
69
+ # added_since
70
+ # added_until
71
+ # opened_since
72
+ # opened_until
73
+ # archived_since
74
+ # archived_until
75
+ # favorited_since
76
+ # favorited_until
77
+ # updated_since
78
+ # updated_until
79
+ # order
80
+ # page
81
+ # per_page
82
+ # exclude_accessibility
83
+ # only_deleted
63
84
  def bookmarks(args={})
64
85
  if args[:bookmark_id] and args[:bookmark_id]!=''
65
86
  request(:get,"/bookmarks/#{args[:bookmark_id]}")
66
87
  else
67
88
  params = args.map{|k,v| "#{k}=#{v}"}.join('&')
68
- request(:get,'/bookmarks',args)
89
+ request(:get,'/bookmarks',args)['bookmarks']
69
90
  end
70
91
  end
71
92
 
72
93
  # Add a bookmark. Returns 202 Accepted, meaning that the bookmark has been added but no guarantees are made as
73
94
  # to whether the article proper has yet been parsed.
74
- #
75
- # /bookmarks?archive&favorite&domain&added_since&added_until&opened_since&opened_until&
76
- # archived_since&archived_until&favorited_since&favorited_until&updated_since&updated_until&
77
- # order&page&per_page&exclude_accessibility&only_deleted
78
- def add_bookmark(args={})
95
+ # @param args args to bookmark a url
96
+ # url the address to bookmark
97
+ # favorite 0 or 1
98
+ # archive 0 or 1
99
+ def bookmark(args={})
79
100
  request(:post,'/bookmarks',args)
80
101
  end
81
102
 
82
103
  # Update a bookmark. Returns 200 on successful update.
83
- # /bookmarks/{bookmark_id}
104
+ # api rest address : /bookmarks/{bookmark_id}
105
+ # @param bookmark_id bookmark to update
106
+ # @param args args to update the bookmark
107
+ # favorite 0 or 1
108
+ # archive 0 or 1
84
109
  def update_bookmark(bookmark_id,args={})
85
110
  request(:post,"/bookmarks/#{bookmark_id}",args)
86
111
  end
87
112
 
113
+ # archive a bookmark by id
114
+ # @param bookmark_id bookmark to archive
88
115
  def archive(bookmark_id)
89
116
  update_bookmark(bookmark_id,:archive=>1)
90
117
  end
91
118
 
119
+ # favorite a bookmark by id
120
+ # @param bookmark_id bookmark_id to favorite
121
+ def favorite(bookmark_id)
122
+ update_bookmark(bookmark_id,:favorite=>1)
123
+ end
124
+
92
125
  # Remove a single bookmark from this user's history.
93
126
  # NOTE: THIS IS PROBABLY NOT WHAT YOU WANT. This is particularly for the case where a user accidentally bookmarks
94
127
  # something they have no intention of reading or supporting.
@@ -97,19 +130,19 @@ module Readit
97
130
  # the site associated with this bookmark will not receive any contributions for this bookmark.
98
131
  # Use archive! It's better.
99
132
  # Returns a 204 on successful remove.
133
+ # @param bookmark_id bookmark to delete
100
134
  def delete_bookmark(bookmark_id)
101
135
  request(:delete,"/bookmarks/#{bookmark_id}")
102
136
  end
103
137
 
104
138
  # Retrieve the contributions collection, which is a set of payments by a user to a specific domain. Automatically filtered to the current user.
105
- #
106
- # /contributions?since&until&domain&page&per_page
139
+ # api rest address : /contributions?since&until&domain&page&per_page
107
140
  def contributions(args={})
108
141
  request(:get,"/contributions",args)
109
142
  end
110
143
 
111
144
  # Retrieve the current user's information.
112
- # /users/_current
145
+ # api rest address :/users/_current
113
146
  def me
114
147
  request(:get,"/users/_current")
115
148
  end
@@ -4,24 +4,31 @@ describe "Readit::API" do
4
4
  before do
5
5
  # load consumer infos
6
6
  consumer_info = YAML.load_file(File.join(File.dirname(__FILE__),'../readability.yml'))["development"]
7
- puts consumer_info
8
7
  Readit::Config.consumer_key = consumer_info['consumer_key']
9
8
  Readit::Config.consumer_secret = consumer_info['consumer_secret']
10
9
  @api = Readit::API.new 'zQuzAzVW4Ark7VZvm2','5VEnMNPr7Q4393wxAYdnTWnpWwn7bHm4'
11
10
  end
12
11
 
12
+ let :bookmarks do
13
+ @bms ||= @api.bookmarks
14
+ end
15
+
16
+ let :bookmark_ids do
17
+ bookmarks.map{|a| a['id']}
18
+ end
19
+
13
20
  it "should get user infos" do
14
21
  @api.me.should_not == nil
15
22
  end
16
23
 
17
24
  it "should get user's bookmarks" do
18
- @api.bookmarks.should_not == nil
25
+ bookmarks.should_not == nil
26
+ bookmarks.count.should > 0
19
27
  end
20
28
 
21
29
  it "should add bookmark" do
22
- url = 'http://www.mihuwa.com/article/5073/'
23
- url = 'http://leewindy.blogbus.com/logs/188360549.html'
24
- resp = @api.add_bookmark :url=>url
30
+ url = 'http://www.tripadvisor.com/Restaurant_Review-g297701-d1182615-Reviews-Cafe_Lotus-Ubud_Bali.html'
31
+ resp = @api.bookmark :url=>url
25
32
  puts resp.inspect
26
33
  resp.should_not == nil
27
34
  end
@@ -32,5 +39,26 @@ describe "Readit::API" do
32
39
  article.should_not == nil
33
40
  end
34
41
 
42
+ it "should get the bookmark info by bookmark id" do
43
+ bookmark = @api.bookmarks :bookmark_id=>bookmark_ids.first
44
+ bookmark.should_not == nil
45
+ puts bookmark
46
+ end
47
+
48
+ it "should update bookmark to favarite" do
49
+ bm_id = bookmark_ids.first
50
+ @api.favorite bm_id
51
+ bookmark = @api.bookmarks :bookmark_id=>bm_id
52
+ bookmark['favorite'].should == true
53
+ end
54
+
55
+ it "should update bookmark to archive" do
56
+ bm_id = bookmark_ids.first
57
+ @api.archive bm_id
58
+ bookmark = @api.bookmarks :bookmark_id=>bm_id
59
+ bookmark['archive'].should == true
60
+ end
61
+
62
+
35
63
  end
36
64
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: readit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-23 00:00:00.000000000Z
12
+ date: 2012-01-28 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
16
- requirement: &2156654960 !ruby/object:Gem::Requirement
16
+ requirement: &2162303000 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2156654960
24
+ version_requirements: *2162303000
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: oauth
27
- requirement: &2156654540 !ruby/object:Gem::Requirement
27
+ requirement: &2162302580 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2156654540
35
+ version_requirements: *2162302580
36
36
  description: a simple readability api client
37
37
  email:
38
38
  - mike.d.1984@gmail.com
@@ -79,3 +79,4 @@ summary: a simple readability api client
79
79
  test_files:
80
80
  - spec/cases/api_spec.rb
81
81
  - spec/spec_helper.rb
82
+ has_rdoc: