readlists-anonymous 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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +6 -0
- data/bin/readlists-anonymous +61 -0
- data/lib/readlists/anonymous.rb +107 -0
- data/lib/readlists/anonymous/version.rb +5 -0
- data/readlists-anonymous.gemspec +24 -0
- data/spec/readlists/anonymous_spec.rb +7 -0
- data/spec/spec_helper.rb +2 -0
- metadata +102 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: c1ceec4912c67c47395b4e0893dac7bd01ea27d7
|
|
4
|
+
data.tar.gz: e723e0838c4dbebdd5300c0b4e1177a403fc1654
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 595c46d9f8ed608139d5fdbb5a17610b6548128ec15ac3e3b140d4e477a7aafdf11d9137f29dfcd697fd917781d2091cc10ef8310a367fbdbe53817005cf7142
|
|
7
|
+
data.tar.gz: ef7b32fd3cf3b43371ff1569fbce863c5b1702aaa482ab4e568c5fe6e5644b6a4c8f67fdfb58c91581fda863eff080f6f8a487bee6e29a95c73e387305ec49f4
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2014 Yuichi Tateno
|
|
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,37 @@
|
|
|
1
|
+
# Readlists::Anonymous
|
|
2
|
+
|
|
3
|
+
[Readlists](http://readlists.com/) API for anonymous lists.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
### Ruby
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
readlists = Readlists::Anonymous.create
|
|
11
|
+
readlists.title = title
|
|
12
|
+
readlists.description = description
|
|
13
|
+
|
|
14
|
+
urls.each do |url|
|
|
15
|
+
begin
|
|
16
|
+
readlists << url
|
|
17
|
+
rescue Readlists::Anonymous::RequestError => e
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
puts "* Created anynymous readlists"
|
|
22
|
+
puts "share-url: #{readlists.share_url}"
|
|
23
|
+
puts "public-edit-url: #{readlists.public_edit_url}"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### command-line
|
|
27
|
+
|
|
28
|
+
```shell
|
|
29
|
+
$ readlists-anonymous [-t title] [-d description] http://example.com/?url1 http://example.com/?url2 [more url...]
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
Or install it yourself as:
|
|
35
|
+
|
|
36
|
+
$ gem install readlists-anonymous
|
|
37
|
+
|
data/Rakefile
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'readlists/anonymous'
|
|
4
|
+
require 'optparse'
|
|
5
|
+
require 'uri'
|
|
6
|
+
require 'rbconfig'
|
|
7
|
+
|
|
8
|
+
options = {}
|
|
9
|
+
optparse = OptionParser.new {|opts|
|
|
10
|
+
opts.banner = "Usage: readlists-anonymous [-t title] [-d description] http://example.com/?url1 http://example.com/?url2 [more url...]"
|
|
11
|
+
|
|
12
|
+
opts.on("-t title", "Set title") do |v|
|
|
13
|
+
options[:title] = v
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
opts.on("-d description", "Set Description") do |v|
|
|
17
|
+
options[:description] = v
|
|
18
|
+
end
|
|
19
|
+
}
|
|
20
|
+
optparse.parse!
|
|
21
|
+
|
|
22
|
+
urls = ARGV.to_a
|
|
23
|
+
if urls.size == 0
|
|
24
|
+
warn optparse.banner
|
|
25
|
+
exit 1
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
urls.each {|url| abort("URL scheme '#{url}' is invalid.") unless ['http', 'https'].include?(URI.parse(url).scheme) }
|
|
29
|
+
|
|
30
|
+
readlists = Readlists::Anonymous.create
|
|
31
|
+
puts "* Created anynymous readlists"
|
|
32
|
+
puts "share-url: #{readlists.share_url}"
|
|
33
|
+
puts "public-edit-url: #{readlists.public_edit_url}"
|
|
34
|
+
|
|
35
|
+
readlists.title = options[:title] if options[:title]
|
|
36
|
+
readlists.description = options[:description] if options[:description]
|
|
37
|
+
|
|
38
|
+
urls.each do |url|
|
|
39
|
+
retried = false
|
|
40
|
+
begin
|
|
41
|
+
puts "Add #{url}"
|
|
42
|
+
readlists << url
|
|
43
|
+
rescue Readlists::Anonymous::RequestError => e
|
|
44
|
+
if retried
|
|
45
|
+
puts "* 2nd error.. ignore #{url}"
|
|
46
|
+
else
|
|
47
|
+
puts "* Error.. retry"
|
|
48
|
+
retried = true
|
|
49
|
+
retry
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
puts "* Created anynymous readlists"
|
|
55
|
+
puts "share-url: #{readlists.share_url}"
|
|
56
|
+
puts "public-edit-url: #{readlists.public_edit_url}"
|
|
57
|
+
|
|
58
|
+
if RbConfig::CONFIG['host_os'] =~ /^darwin/
|
|
59
|
+
system 'open', readlists.public_edit_url
|
|
60
|
+
end
|
|
61
|
+
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
require "readlists/anonymous/version"
|
|
2
|
+
require 'net/http'
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
module Readlists
|
|
6
|
+
class Anonymous
|
|
7
|
+
API_ENDPOINT = 'http://readlists.com/api/v1/readlists/'
|
|
8
|
+
DEFAULT_READLIST_PARAMS = { "is_from_edit_id" => false, "entries" => "[]", "class" => "sharing"}.freeze
|
|
9
|
+
DEFAULT_HEADERS = { 'Content-Type' => 'application/json' }.freeze
|
|
10
|
+
|
|
11
|
+
class RequestError < StandardError; end
|
|
12
|
+
def self.request(method, url, params, headers = {})
|
|
13
|
+
headers = DEFAULT_HEADERS.merge headers
|
|
14
|
+
req = case method
|
|
15
|
+
when :get
|
|
16
|
+
Net::HTTP::Get.new(url, headers)
|
|
17
|
+
when :post
|
|
18
|
+
Net::HTTP::Post.new(url, headers)
|
|
19
|
+
when :put
|
|
20
|
+
Net::HTTP::Put.new(url, headers)
|
|
21
|
+
end
|
|
22
|
+
req.basic_auth url.user, url.password if url.user
|
|
23
|
+
req.body = params.to_json
|
|
24
|
+
res = nil
|
|
25
|
+
Net::HTTP.start(url.hostname, url.port, :use_ssl => url.scheme == 'https' ) {|http|
|
|
26
|
+
res = http.request(req)
|
|
27
|
+
}
|
|
28
|
+
raise RequestError.new("#{res.code}: #{res.body}") unless res.code =~ /[234]/
|
|
29
|
+
res
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.base_uri
|
|
33
|
+
URI.parse API_ENDPOINT
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.create
|
|
37
|
+
res = request(:post, base_uri, DEFAULT_READLIST_PARAMS)
|
|
38
|
+
id, session_id = nil, nil
|
|
39
|
+
res.each_header {|key, value|
|
|
40
|
+
case key
|
|
41
|
+
when 'set-cookie'
|
|
42
|
+
# "sessionid=#{id}; expires=Fri, 17-Jan-2014 05:05:06 GMT; httponly; Max-Age=1209600; Path=/"
|
|
43
|
+
session_id = value.match(/sessionid=(\S+?);/)[1]
|
|
44
|
+
when 'location'
|
|
45
|
+
# 'http://readlists.com/api/v1/readlists/#{id}/'
|
|
46
|
+
id = value.split('/')[-1]
|
|
47
|
+
end
|
|
48
|
+
}
|
|
49
|
+
new(id, session_id)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
attr_reader :id, :session_id, :title, :description, :edit_id
|
|
53
|
+
def initialize(id, session_id)
|
|
54
|
+
@id = id
|
|
55
|
+
@session_id = session_id
|
|
56
|
+
set_edit_id
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def set_edit_id
|
|
60
|
+
res = request(:get)
|
|
61
|
+
@edit_id = JSON.parse(res.body)['edit_id']
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def public_edit_url
|
|
65
|
+
"http://readlists.com/#{edit_id}/"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def share_url
|
|
69
|
+
"http://readlists.com/#{id}/"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def entry_endpoint
|
|
73
|
+
URI "#{API_ENDPOINT}#{id}/entries/"
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def endpoint
|
|
77
|
+
URI "#{API_ENDPOINT}#{id}/"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def title=(title)
|
|
81
|
+
request(:put, "readlist_title" => title)
|
|
82
|
+
@title = title
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def description=(desc)
|
|
86
|
+
request(:put, "description" => desc)
|
|
87
|
+
@description = desc
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def cookie
|
|
91
|
+
"sessionid=#{session_id}"
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def <<(url)
|
|
95
|
+
headers = { "Cookie" => cookie }
|
|
96
|
+
params = { "readlist" => DEFAULT_READLIST_PARAMS }.merge("article_url" => url)
|
|
97
|
+
self.class.request(:post, entry_endpoint, params, headers)
|
|
98
|
+
end
|
|
99
|
+
alias_method :add, :<<
|
|
100
|
+
|
|
101
|
+
def request(method, params = {}, headers = {})
|
|
102
|
+
headers = { "Cookie" => cookie }
|
|
103
|
+
params = DEFAULT_READLIST_PARAMS.merge(params)
|
|
104
|
+
self.class.request(method, endpoint, params, headers)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'readlists/anonymous/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "readlists-anonymous"
|
|
8
|
+
spec.version = Readlists::Anonymous::VERSION
|
|
9
|
+
spec.authors = ["Yuichi Tateno"]
|
|
10
|
+
spec.email = ["hotchpotch@gmail.com"]
|
|
11
|
+
spec.summary = %q{Readlists API for anonymous lists.}
|
|
12
|
+
spec.description = %q{Readlists API for anonymous lists.}
|
|
13
|
+
spec.homepage = "https://github.com/hotchpotch/readlists-anonymous"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/)
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency "bundler"
|
|
22
|
+
spec.add_development_dependency "rake"
|
|
23
|
+
spec.add_development_dependency "rspec"
|
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: readlists-anonymous
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Yuichi Tateno
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-01-05 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
description: Readlists API for anonymous lists.
|
|
56
|
+
email:
|
|
57
|
+
- hotchpotch@gmail.com
|
|
58
|
+
executables:
|
|
59
|
+
- readlists-anonymous
|
|
60
|
+
extensions: []
|
|
61
|
+
extra_rdoc_files: []
|
|
62
|
+
files:
|
|
63
|
+
- ".gitignore"
|
|
64
|
+
- ".rspec"
|
|
65
|
+
- ".travis.yml"
|
|
66
|
+
- Gemfile
|
|
67
|
+
- LICENSE.txt
|
|
68
|
+
- README.md
|
|
69
|
+
- Rakefile
|
|
70
|
+
- bin/readlists-anonymous
|
|
71
|
+
- lib/readlists/anonymous.rb
|
|
72
|
+
- lib/readlists/anonymous/version.rb
|
|
73
|
+
- readlists-anonymous.gemspec
|
|
74
|
+
- spec/readlists/anonymous_spec.rb
|
|
75
|
+
- spec/spec_helper.rb
|
|
76
|
+
homepage: https://github.com/hotchpotch/readlists-anonymous
|
|
77
|
+
licenses:
|
|
78
|
+
- MIT
|
|
79
|
+
metadata: {}
|
|
80
|
+
post_install_message:
|
|
81
|
+
rdoc_options: []
|
|
82
|
+
require_paths:
|
|
83
|
+
- lib
|
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0'
|
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
|
+
requirements:
|
|
91
|
+
- - ">="
|
|
92
|
+
- !ruby/object:Gem::Version
|
|
93
|
+
version: '0'
|
|
94
|
+
requirements: []
|
|
95
|
+
rubyforge_project:
|
|
96
|
+
rubygems_version: 2.2.0
|
|
97
|
+
signing_key:
|
|
98
|
+
specification_version: 4
|
|
99
|
+
summary: Readlists API for anonymous lists.
|
|
100
|
+
test_files:
|
|
101
|
+
- spec/readlists/anonymous_spec.rb
|
|
102
|
+
- spec/spec_helper.rb
|