ril_text 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +49 -0
- data/Rakefile +2 -0
- data/lib/ril_text.rb +71 -0
- data/lib/ril_text/version.rb +3 -0
- data/ril_text.gemspec +19 -0
- data/spec/ril_text_spec.rb +24 -0
- data/spec/spec_helper.rb +13 -0
- metadata +77 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 tomykaira
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# RilText
|
2
|
+
|
3
|
+
This is a thin wrapper of [Read It Later Text API](http://readitlaterlist.com/api/docs/).
|
4
|
+
|
5
|
+
At first, you should get [your API key](http://readitlaterlist.com/api/signup/).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'ril_text'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ril_text
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
require 'ril_text'
|
24
|
+
RilText.get('http://readitlaterlist.com/api/docs')
|
25
|
+
|
26
|
+
will return a hash. The hash contains following fields.
|
27
|
+
|
28
|
+
- `text`: Extracted body of the document.
|
29
|
+
- `title`: Title of the document.
|
30
|
+
- `resolved`: Resolved URL. RIL Text API follows redirect chain until it gets 200.
|
31
|
+
- `image`: Favicon of the document.
|
32
|
+
|
33
|
+
## Coniguration
|
34
|
+
|
35
|
+
Set `apikey` using `RilText.configure` before use.
|
36
|
+
|
37
|
+
RilText.configure do |c|
|
38
|
+
c.apikey = 'yourapikey'
|
39
|
+
c.images = 1
|
40
|
+
c.mode = 'more'
|
41
|
+
end
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/ril_text.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require "ril_text/version"
|
2
|
+
require 'net/https'
|
3
|
+
require 'uri'
|
4
|
+
require 'singleton'
|
5
|
+
|
6
|
+
module RilText
|
7
|
+
extend RilText
|
8
|
+
|
9
|
+
API_DOMAIN = 'text.readitlaterlist.com'
|
10
|
+
API_VERSION = 'v2'
|
11
|
+
|
12
|
+
class Configuration
|
13
|
+
include Singleton
|
14
|
+
|
15
|
+
KEYS = [:apikey, :mode, :images]
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@params = {
|
19
|
+
:apikey => 'yourapikey',
|
20
|
+
:mode => 'less',
|
21
|
+
:images => 0
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def params(hash = {})
|
26
|
+
@params.merge(hash)
|
27
|
+
end
|
28
|
+
|
29
|
+
KEYS.each do |key|
|
30
|
+
define_method("#{key}=") { |val| @params[key] = val }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def config
|
35
|
+
Configuration.instance
|
36
|
+
end
|
37
|
+
|
38
|
+
def configure
|
39
|
+
yield config
|
40
|
+
end
|
41
|
+
|
42
|
+
def get(url)
|
43
|
+
https = Net::HTTP.new(API_DOMAIN, 443)
|
44
|
+
https.use_ssl = true
|
45
|
+
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
46
|
+
|
47
|
+
result = Hash.new
|
48
|
+
https.start do |access|
|
49
|
+
response = access.get(request_uri(config.params(:url => url)))
|
50
|
+
result[:text] = response.body
|
51
|
+
response.each_header do |k, v|
|
52
|
+
case k
|
53
|
+
when 'x-title'
|
54
|
+
result[:title] = v
|
55
|
+
when 'x-resolved'
|
56
|
+
result[:resolved] = v
|
57
|
+
when 'x-image'
|
58
|
+
result[:image] = v
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
result
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
def request_uri(params)
|
68
|
+
query_string = params.map{ |k, v| "#{URI.escape(k.to_s)}=#{URI.escape(v.to_s)}" }.join('&')
|
69
|
+
"/#{API_VERSION}/text" + '?' + query_string
|
70
|
+
end
|
71
|
+
end
|
data/ril_text.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/ril_text/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["tomykaira"]
|
6
|
+
gem.email = ["tomykaira@gmail.com"]
|
7
|
+
gem.description = %q{A thin wrapper of Read It Later Text API}
|
8
|
+
gem.summary = %q{A thin wrapper of Read It Later Text API}
|
9
|
+
gem.homepage = "https://github.com/tomykaira/ril_text"
|
10
|
+
|
11
|
+
gem.add_development_dependency('rspec')
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split($\)
|
14
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
15
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
16
|
+
gem.name = "ril_text"
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
gem.version = RilText::VERSION
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'ril_text'
|
2
|
+
|
3
|
+
describe RilText do
|
4
|
+
let(:url) { 'http://readitlaterlist.com/api/docs' }
|
5
|
+
let(:res) { RilText.get(url) }
|
6
|
+
it "should have body and meta info" do
|
7
|
+
res[:text].should include 'API Documentation'
|
8
|
+
res[:title].should == 'Read It Later: Developer API: Documentation'
|
9
|
+
res[:resolved].should == 'http://readitlaterlist.com/api/docs'
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "configure" do
|
13
|
+
before do
|
14
|
+
RilText.configure do |c|
|
15
|
+
c.images = 1
|
16
|
+
c.mode = 'more'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
subject { RilText.config.params }
|
21
|
+
its([:images]) { should == 1 }
|
22
|
+
its([:mode]) { should == 'more' }
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper.rb"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
$LOAD_PATH.push File.expand_path('../lib/', __FILE__)
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
config.filter_run :current
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ril_text
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- tomykaira
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-03-16 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :development
|
25
|
+
version_requirements: *id001
|
26
|
+
description: A thin wrapper of Read It Later Text API
|
27
|
+
email:
|
28
|
+
- tomykaira@gmail.com
|
29
|
+
executables: []
|
30
|
+
|
31
|
+
extensions: []
|
32
|
+
|
33
|
+
extra_rdoc_files: []
|
34
|
+
|
35
|
+
files:
|
36
|
+
- .gitignore
|
37
|
+
- .rspec
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- lib/ril_text.rb
|
43
|
+
- lib/ril_text/version.rb
|
44
|
+
- ril_text.gemspec
|
45
|
+
- spec/ril_text_spec.rb
|
46
|
+
- spec/spec_helper.rb
|
47
|
+
homepage: https://github.com/tomykaira/ril_text
|
48
|
+
licenses: []
|
49
|
+
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.8.17
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: A thin wrapper of Read It Later Text API
|
74
|
+
test_files:
|
75
|
+
- spec/ril_text_spec.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
has_rdoc:
|