readit 0.0.1

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 ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ readability.yml
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source 'http://rubygems.org'
2
+ gem 'multi_json'
3
+
4
+ group :development, :test do
5
+ gem 'rspec'
6
+ # Testing infrastructure
7
+ gem 'guard'
8
+ gem 'guard-rspec'
9
+
10
+ # if RUBY_PLATFORM =~ /darwin/
11
+ # # OS X integration
12
+ # gem "ruby_gntp"
13
+ # gem "rb-fsevent", "~> 0.4.3.1"
14
+ # end
15
+ end
16
+ gem 'oauth'
17
+
18
+
19
+ # Specify your gem's dependencies in readit.gemspec
20
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,8 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+ guard 'rspec', :version => 2 do
4
+ watch(%r{^spec/.+_spec\.rb$})
5
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
6
+ watch('spec/spec_helper.rb') { "spec" }
7
+ end
8
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/Readme.md ADDED
@@ -0,0 +1,36 @@
1
+ ### Simple api client of [readability](http://www.readability.com)
2
+ not ready to use
3
+ ### Configuration
4
+ #### Rails
5
+ config/readability.yml
6
+
7
+ ``` ruby
8
+
9
+ development:
10
+ consumer_key: some_key
11
+ consumer_secret: some_secret
12
+ ```
13
+
14
+ #### or in your code
15
+
16
+ ``` ruby
17
+
18
+ Readit::Config.consumer_key = some_key
19
+ Readit::Config.consumer_secret = some_value
20
+ ```
21
+
22
+ ### API use
23
+ ``` ruby
24
+
25
+ @api = Readit::API.new 'access_token','access_token_secret'
26
+
27
+ # get user info
28
+ @api.me
29
+ # get all bookmarks
30
+ @api.bookmarks
31
+ # get one artile by article_id
32
+ @api.article 'article_id'
33
+ # add bookmark
34
+ @api.add_bookmark :url=>'http://some_article_url.html'
35
+ ```
36
+
@@ -0,0 +1,11 @@
1
+ module Readit
2
+ class Railtie < Rails::Railtie
3
+ config.after_initialize do
4
+ if File.exists?('config/readability.yml')
5
+ consumer_info = YAML.load_file(File.join(Rails.root.to_s, 'config', 'readability.yml'))[Rails.env || "development"]
6
+ Readit::Config.consumer_key = consumer_info["consumer_key"]
7
+ Readit::Config.consumer_secret = consumer_info["consumer_secret"]
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Readit
2
+ VERSION = "0.0.1"
3
+ end
data/lib/readit.rb ADDED
@@ -0,0 +1,131 @@
1
+ require "readit/version"
2
+ require 'multi_json'
3
+ require 'oauth'
4
+ # plugin railtie hook when using rails
5
+ require 'readit/railtie' if defined?(Rails)
6
+
7
+ module Readit
8
+
9
+ class ReaditError < StandardError;end
10
+
11
+ module Config
12
+
13
+ def self.consumer_key
14
+ @@consumer_key
15
+ end
16
+
17
+ def self.consumer_key=(val)
18
+ @@consumer_key = val
19
+ end
20
+
21
+ def self.consumer_secret
22
+ @@consumer_secret
23
+ end
24
+
25
+ def self.consumer_secret=(val)
26
+ @@consumer_secret = val
27
+ end
28
+
29
+ end
30
+
31
+ class API
32
+ # Create a new Readit API client
33
+ def initialize(access_token='',access_token_secret='')
34
+ @access_token = access_token
35
+ @access_token_secret = access_token_secret
36
+ load_config
37
+ end
38
+
39
+ attr_reader :access_token
40
+
41
+ SITE_URL = 'https://www.readability.com/'
42
+
43
+ # Retrieve the base API URI - information about subresources.
44
+ # /
45
+ def resource_info
46
+ request(:get,'/')
47
+ end
48
+
49
+ # Retrieve a single Article, including its content.
50
+ # /articles/{article_id}
51
+ def article(article_id)
52
+ request(:get,"/articles/#{article_id}")
53
+ end
54
+
55
+ # 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
+ def bookmarks(args={})
64
+ if args[:bookmark_id] and args[:bookmark_id]!=''
65
+ request(:get,"/bookmarks/#{args[:bookmark_id]}")
66
+ else
67
+ params = args.map{|k,v| "#{k}=#{v}"}.join('&')
68
+ request(:get,'/bookmarks',args)
69
+ end
70
+ end
71
+
72
+ # Add a bookmark. Returns 202 Accepted, meaning that the bookmark has been added but no guarantees are made as
73
+ # 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={})
79
+ request(:post,'/bookmarks',args)
80
+ end
81
+
82
+ # Update a bookmark. Returns 200 on successful update.
83
+ # /bookmarks/{bookmark_id}
84
+ def update_bookmark(bookmark_id,args={})
85
+ request(:post,"/bookmarks/#{bookmark_id}",args)
86
+ end
87
+
88
+ def archive(bookmark_id)
89
+ update_bookmark(bookmark_id,:archive=>1)
90
+ end
91
+
92
+ # Remove a single bookmark from this user's history.
93
+ # NOTE: THIS IS PROBABLY NOT WHAT YOU WANT. This is particularly for the case where a user accidentally bookmarks
94
+ # something they have no intention of reading or supporting.
95
+ # In almost all cases, you'll probably want to use archive by POSTing archive=1 to this bookmark.
96
+ # If you use DELETE and this months bookmarks have not yet been tallied,
97
+ # the site associated with this bookmark will not receive any contributions for this bookmark.
98
+ # Use archive! It's better.
99
+ # Returns a 204 on successful remove.
100
+ def delete_bookmark(bookmark_id)
101
+ request(:delete,"/bookmarks/#{bookmark_id}")
102
+ end
103
+
104
+ # 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
107
+ def contributions(args={})
108
+ request(:get,"/contributions",args)
109
+ end
110
+
111
+ # Retrieve the current user's information.
112
+ # /users/_current
113
+ def me
114
+ request(:get,"/users/_current")
115
+ end
116
+
117
+ private
118
+ def request(method,url,args={})
119
+ consumer = ::OAuth::Consumer.new(Readit::Config.consumer_key,Readit::Config.consumer_secret,:site=>SITE_URL)
120
+ atoken = ::OAuth::AccessToken.new(consumer, @access_token, @access_token_secret)
121
+ #response = client.send(method,"/api/rest/v1#{url}",args.merge!('oauth_token'=>@access_token,'oauth_token_secret'=>'5VEnMNPr7Q4393wxAYdnTWnpWwn7bHm4','oauth_consumer_key'=>'lidongbin','oauth_consumer_secret'=>'gvjSYqH4PLWQtQG8Ywk7wKZnEgd4xf2C'))
122
+ response = atoken.send(method,"/api/rest/v1#{url}",args)
123
+ if response.body==nil or response.body==''
124
+ {:status => response.code}
125
+ else
126
+ MultiJson.decode response.body
127
+ end
128
+ end
129
+
130
+ end
131
+ end
@@ -0,0 +1,3 @@
1
+ development:
2
+ consumer_key: consumer_key
3
+ consumer_secret: consumer_secret
data/readit.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/readit/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["dongbin.li"]
6
+ gem.email = ["mike.d.1984@gmail.com"]
7
+ gem.description = %q{a simple readability api client}
8
+ gem.summary = %q{a simple readability api client}
9
+ gem.homepage = "https://github.com/29decibel/readit"
10
+
11
+ gem.rubyforge_project = "readit"
12
+ gem.add_dependency 'multi_json'
13
+ gem.add_dependency 'oauth'
14
+
15
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ gem.files = `git ls-files`.split("\n")
17
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ gem.name = "readit"
19
+ gem.require_paths = ["lib"]
20
+ gem.version = Readit::VERSION
21
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Readit::API" do
4
+ before do
5
+ # load consumer infos
6
+ consumer_info = YAML.load_file(File.join(File.dirname(__FILE__),'../readability.yml'))["development"]
7
+ puts consumer_info
8
+ Readit::Config.consumer_key = consumer_info['consumer_key']
9
+ Readit::Config.consumer_secret = consumer_info['consumer_secret']
10
+ @api = Readit::API.new 'zQuzAzVW4Ark7VZvm2','5VEnMNPr7Q4393wxAYdnTWnpWwn7bHm4'
11
+ end
12
+
13
+ it "should get user infos" do
14
+ @api.me.should_not == nil
15
+ end
16
+
17
+ it "should get user's bookmarks" do
18
+ @api.bookmarks.should_not == nil
19
+ end
20
+
21
+ 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
25
+ puts resp.inspect
26
+ resp.should_not == nil
27
+ end
28
+
29
+ it "should get the article content" do
30
+ article = @api.article 'eg60dxbv'
31
+ #puts article
32
+ article.should_not == nil
33
+ end
34
+
35
+ end
36
+
@@ -0,0 +1,7 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'Although not required, bundler is recommended for running the tests.'
5
+ end
6
+
7
+ require 'readit'
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: readit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - dongbin.li
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-22 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: multi_json
16
+ requirement: &2157022360 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2157022360
25
+ - !ruby/object:Gem::Dependency
26
+ name: oauth
27
+ requirement: &2157021940 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2157021940
36
+ description: a simple readability api client
37
+ email:
38
+ - mike.d.1984@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - Guardfile
46
+ - Rakefile
47
+ - Readme.md
48
+ - lib/readit.rb
49
+ - lib/readit/railtie.rb
50
+ - lib/readit/version.rb
51
+ - readability.yml.sample
52
+ - readit.gemspec
53
+ - spec/cases/api_spec.rb
54
+ - spec/spec_helper.rb
55
+ homepage: https://github.com/29decibel/readit
56
+ licenses: []
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project: readit
75
+ rubygems_version: 1.8.11
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: a simple readability api client
79
+ test_files:
80
+ - spec/cases/api_spec.rb
81
+ - spec/spec_helper.rb