readability-engine 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/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", "3.0.7"
4
+ gem "sqlite3"
5
+
6
+ # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
7
+ # gem 'ruby-debug'
8
+ group :development, :test do
9
+ gem 'ruby-debug19'
10
+ gem "capybara", ">= 0.4.0"
11
+ end
12
+
13
+ gem 'yajl-ruby'
14
+ gem 'oauth'
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 YOURNAME
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.markdown ADDED
@@ -0,0 +1,42 @@
1
+ Readability
2
+ ==========
3
+
4
+ Install
5
+ -------
6
+
7
+ Simply include
8
+
9
+ `gem readability`
10
+
11
+ in your Gemfile. `bundle`, and then run
12
+
13
+ `rails g readability:install`
14
+
15
+ This will create a `readability.yml` file in your config dir. All you'll need to configure
16
+ at that point is to add your consumer key/secret and then add `acts_as_readability` into controllers
17
+ you want to use Readability api methods within.
18
+
19
+ The installer will give further instructions on how to configure your app once ou install.
20
+
21
+ API Docs
22
+ --------
23
+
24
+ I'm working on documenting more of the code and putting together an actual API, but really, it just
25
+ references the Readability API, found at [http://readability.com/publishers/api][1].
26
+
27
+ Contribute
28
+ ----------
29
+
30
+ This is a pretty basic API, so do your worst:
31
+
32
+ * fork
33
+ * fix
34
+ * write tests (yes I know I didn't...)
35
+ * pull request!
36
+
37
+ License
38
+ -------
39
+
40
+ See MIT-LICENSE.
41
+
42
+ [1]: http://readability.com/publishers/api
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rake'
10
+ require 'rake/rdoctask'
11
+
12
+ require 'rake/testtask'
13
+
14
+ Bundler::GemHelper.install_tasks
15
+
16
+ Rake::TestTask.new(:test) do |t|
17
+ t.libs << 'lib'
18
+ t.libs << 'test'
19
+ t.pattern = 'test/**/*_test.rb'
20
+ t.verbose = false
21
+ end
22
+
23
+ task :default => :test
24
+
25
+ Rake::RDocTask.new(:rdoc) do |rdoc|
26
+ rdoc.rdoc_dir = 'rdoc'
27
+ rdoc.title = 'Readability'
28
+ rdoc.options << '--line-numbers' << '--inline-source'
29
+ rdoc.rdoc_files.include('README.rdoc')
30
+ rdoc.rdoc_files.include('lib/**/*.rb')
31
+ end
@@ -0,0 +1,55 @@
1
+ class Readability::SessionController < ApplicationController
2
+ before_filter :parse_options, only: [:show]
3
+ unloadable
4
+
5
+ def show
6
+ flash[:alert] = "Could not authenticate with Readability" unless access_token
7
+ redirect_to "/readability/callback"
8
+ end
9
+
10
+ def new
11
+ request_token = consumer.get_request_token(:oauth_callback => callback_url)
12
+ session[:request_token] = request_token
13
+ redirect_to request_token.authorize_url(:oauth_callback => callback_url)
14
+ end
15
+
16
+ private
17
+ def access_token
18
+ verifier = params[:oauth_verifier]
19
+
20
+ return nil unless session[:request_token] && verifier
21
+ access_token = session[:request_token].get_access_token(:oauth_verifier => verifier)
22
+
23
+ session[:readability_access] = access_token
24
+ session[:request_token] = nil
25
+
26
+ access_token
27
+ end
28
+
29
+ def parse_options
30
+ @options = "?"
31
+ @options += "archive=#{params[:archive] ? 1 : 0}"
32
+ @options += "&favorite=#{params[:favorite] ? 1 : 0}"
33
+ end
34
+
35
+ def callback_url
36
+ uri = URI.parse(request.url)
37
+ uri.path = readability_session_path
38
+ uri.query = nil
39
+ uri.to_s
40
+ end
41
+
42
+ def consumer_keys
43
+ @consumer_keys ||= YAML.load_file( File.join(Rails.root, 'config', 'readability.yml') )
44
+ end
45
+
46
+ def consumer
47
+ @consumer ||= OAuth::Consumer.new(consumer_keys['consumer_key'], consumer_keys['consumer_secret'], {
48
+ site: "https://www.readability.com",
49
+ authorize_path: "/api/rest/v1//oauth/authorize/",
50
+ access_token_path: "/api/rest/v1/oauth/access_token/",
51
+ request_token_path: "/api/rest/v1/oauth/request_token/"})
52
+ end
53
+
54
+ end
55
+
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ ActionController::Routing::Routes.draw do
2
+ resource :readability_session, controller: 'readability/session'
3
+ end
data/lib/engine.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'readability'
2
+ require 'rails'
3
+
4
+ module Readability
5
+ class Engine < Rails::Engine
6
+ paths["app/helpers"] << 'lib/readability/helpers'
7
+ generators do
8
+ require "rails/generators/install_generator"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ module Readability
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../templates", __FILE__)
5
+ desc "Creates a Readability config file for you to modify."
6
+
7
+ def copy_config
8
+ template "readability.yml", "config/readability.yml"
9
+ end
10
+
11
+ def show_readme
12
+ readme "README" if behavior == :invoke
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ You've just installed Readability authentication. It's pretty simple to setup. Simply set the 'key' and 'secret'
2
+ to your consumer key/secret in the readability.yml file.
3
+
4
+ To start off the auth process, direct the user to the `readability_sessions_path`
5
+
6
+ In your routes, set a path:
7
+ match "readability/callback" => "controller#action", as: "name_me"
8
+
9
+ so that once Readability has verified, you will be returned to this path.
10
+
11
+ To access helper methods and the general query interface, be sure to include the `readabilify` call at the
12
+ top of your controller (or in ApplicationController).
13
+
14
+ To check if you have access, you can use before_filter, or simply check with the `readabilified?` method:
15
+ before_filter :readabilified?
16
+
17
+ Once you want to make API calls to Readability, use the `readability` method to make calls. For example:
18
+
19
+ readabilty :bookmarks, {favorite: true} # return a listing of all the bookmarks which are favorited.
20
+ readabilty :article, [id] # return an article
21
+
@@ -0,0 +1,2 @@
1
+ consumer_key: 'consumer key'
2
+ consumer_secret: 'consumer secret'
@@ -0,0 +1,21 @@
1
+ module Readability
2
+ module ActsAsReadability
3
+ module Base
4
+ def self.included(klass)
5
+ klass.class_eval do
6
+ extend Config
7
+ end
8
+ end
9
+
10
+ module Config
11
+ def readabilify
12
+ include Readability::Helpers::Authentication
13
+ helper Readability::Helpers::Authentication
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ ::ActionController::Base.send :include, Readability::ActsAsReadability::Base
21
+
@@ -0,0 +1,37 @@
1
+ # This is the base query class. It handles making requests to the API and returning the data as a hash.
2
+ module Readability
3
+ class Client
4
+ attr_accessor :resources
5
+
6
+ BASE_API = "/api/rest/v1"
7
+
8
+ def initialize(token)
9
+ @token = token.dup
10
+
11
+ # get available resource types
12
+ @resources = get
13
+ end
14
+
15
+ def get(resource="", args={})
16
+ response = @token.get(format_query(resource, args))
17
+ case response
18
+ when Net::HTTPSuccess
19
+ data = JSON.parse(response.body)
20
+ data = data[resource.to_s] unless resource.blank?
21
+ data
22
+ else
23
+ raise StandardError, "Could not get data."
24
+ end
25
+ end
26
+
27
+ def format_query(resource, args)
28
+ query = "#{BASE_API}/#{resource}"
29
+ query << "?#{parameterize(args)}" unless args.empty?
30
+ query
31
+ end
32
+
33
+ def parameterize(params)
34
+ URI.escape(params.collect{|k,v| "#{k}=#{v}"}.join('&'))
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,21 @@
1
+ module Readability
2
+ module Helpers
3
+ module Authentication
4
+ def readabilified?
5
+ !!readability_access
6
+ end
7
+
8
+ def readability_access
9
+ session[:readability_access]
10
+ end
11
+
12
+ def readability(resource, args = {})
13
+ readability_client.get(resource, args)
14
+ end
15
+
16
+ def readability_client
17
+ @client ||= Readability::Client.new(readability_access)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ module Readability
2
+ require 'engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
3
+ SITE = "https://www.readability.com"
4
+
5
+ require 'readability/client'
6
+ require 'readability/acts_as_readability'
7
+ require 'readability/helpers/authentication'
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: readability-engine
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Luke van der Hoeven
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-19 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: yajl-ruby
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: oauth
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ description: This gem/engine allows you to access Readability APIs.
39
+ email:
40
+ - hungerandthirst@gmail.com
41
+ executables: []
42
+
43
+ extensions: []
44
+
45
+ extra_rdoc_files: []
46
+
47
+ files:
48
+ - app/controllers/readability/session_controller.rb
49
+ - lib/engine.rb
50
+ - lib/rails/generators/install_generator.rb
51
+ - lib/rails/generators/templates/readability.yml
52
+ - lib/rails/generators/templates/README
53
+ - lib/readability/acts_as_readability.rb
54
+ - lib/readability/client.rb
55
+ - lib/readability/helpers/authentication.rb
56
+ - lib/readability.rb
57
+ - config/routes.rb
58
+ - MIT-LICENSE
59
+ - Rakefile
60
+ - Gemfile
61
+ - README.markdown
62
+ has_rdoc: true
63
+ homepage:
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options: []
68
+
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3492997948071565615
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ requirements: []
87
+
88
+ rubyforge_project:
89
+ rubygems_version: 1.6.2
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: A simple engine to allow you to tie into Readability for auth or API access
93
+ test_files: []
94
+