dakrone-ricepaper 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/README.txt +4 -0
- data/Rakefile +41 -0
- data/VERSION +1 -0
- data/bin/ricepaper +41 -0
- data/lib/ricepaper.rb +60 -0
- data/ricepaper.gemspec +41 -0
- metadata +58 -0
data/README.txt
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gemspec|
|
4
|
+
gemspec.name = "ricepaper"
|
5
|
+
gemspec.summary = "A small library for adding URLs to Instapaper"
|
6
|
+
gemspec.email = "lee@writequit.org"
|
7
|
+
gemspec.homepage = "http://github.com/dakrone/ricepaper"
|
8
|
+
gemspec.description = "Ricepaper is a library that allows you to add URLs to Instapaper, either by using it as a CLI or as a Ruby library."
|
9
|
+
gemspec.authors = ["Lee Hinman"]
|
10
|
+
gemspec.rubyforge_project = 'writequit'
|
11
|
+
end
|
12
|
+
rescue LoadError
|
13
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
14
|
+
end
|
15
|
+
|
16
|
+
begin
|
17
|
+
require 'rake/contrib/sshpublisher'
|
18
|
+
namespace :rubyforge do
|
19
|
+
|
20
|
+
desc "Release gem and RDoc documentation to RubyForge"
|
21
|
+
task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
|
22
|
+
|
23
|
+
namespace :release do
|
24
|
+
desc "Publish RDoc to RubyForge."
|
25
|
+
task :docs => [:rdoc] do
|
26
|
+
config = YAML.load(
|
27
|
+
File.read(File.expand_path('~/.rubyforge/user-config.yml'))
|
28
|
+
)
|
29
|
+
|
30
|
+
host = "#{config['username']}@rubyforge.org"
|
31
|
+
remote_dir = "/var/www/gforge-projects/ricepaper/"
|
32
|
+
local_dir = 'rdoc'
|
33
|
+
|
34
|
+
Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
rescue LoadError
|
39
|
+
puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
|
40
|
+
end
|
41
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/bin/ricepaper
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# CLI interface to adding articles to your instantpaper account
|
4
|
+
# by Matthew Lee Hinman (http://writequit.org)
|
5
|
+
|
6
|
+
require 'ricepaper'
|
7
|
+
require 'optparse'
|
8
|
+
|
9
|
+
|
10
|
+
opthash = Hash.new
|
11
|
+
options = OptionParser.new do |opts|
|
12
|
+
opts.banner = %q|Usage: #{$0} [options] "<url>" ["<url>" "<url>" ...]|
|
13
|
+
opts.on("-u", "--username [USER]", "Username") { |opt| opthash['username'] = opt }
|
14
|
+
opts.on("-p", "--password [PASS]", "Password") { |opt| opthash['password'] = opt }
|
15
|
+
opts.on("-a", "--authenticate", "Only attempt to authenticate to Instapaper") { |opt| opthash['authenticate'] = opt }
|
16
|
+
opts.on("-t", "--title [TITLE]", "Optional title for instantpaper entry") { |opt| opthash['title'] = opt }
|
17
|
+
end
|
18
|
+
|
19
|
+
options.parse!(ARGV)
|
20
|
+
rp = RicePaper.new(opthash['username'],opthash['password'])
|
21
|
+
|
22
|
+
if opthash['authenticate']
|
23
|
+
print "Authenticating... "
|
24
|
+
result = rp.authenticate
|
25
|
+
|
26
|
+
puts result ? "Successful." : "Failed."
|
27
|
+
puts "Error: #{rp.error}" unless result
|
28
|
+
exit(0)
|
29
|
+
end
|
30
|
+
|
31
|
+
if ARGV.size < 1
|
32
|
+
puts "I need a url to add to InstantPaper"
|
33
|
+
end
|
34
|
+
|
35
|
+
ARGV.each do |url|
|
36
|
+
print "Submitting '#{url}' #{opthash['title'].nil? ? "" : "with title '#{opthash['title']}'"} ... "
|
37
|
+
result = rp.add(url,opthash['title'])
|
38
|
+
|
39
|
+
puts result ? "Successful." : "Failed."
|
40
|
+
puts "Error: #{rp.error}" unless result
|
41
|
+
end
|
data/lib/ricepaper.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Library for adding URLs to instapaper.
|
4
|
+
# by Matthew Lee Hinman (http://writequit.org)
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rest_client'
|
9
|
+
|
10
|
+
# Encapsulation class
|
11
|
+
|
12
|
+
class RicePaper
|
13
|
+
|
14
|
+
attr_accessor :username, :password, :apiurl
|
15
|
+
attr_reader :error
|
16
|
+
|
17
|
+
def initialize(username, password, apiurl = "https://www.instapaper.com/api/")
|
18
|
+
@username = username
|
19
|
+
@password = password
|
20
|
+
@apiurl = apiurl
|
21
|
+
@error = ""
|
22
|
+
end
|
23
|
+
|
24
|
+
# Handle Errors - sets the error code appropriately
|
25
|
+
# so that it can be reported
|
26
|
+
def handle_error(err)
|
27
|
+
result = /(\d+)/.match(err.to_s)[1]
|
28
|
+
@error = case result
|
29
|
+
when "400" then "Bad Request"
|
30
|
+
when "403" then "Invalid username of password"
|
31
|
+
when "500" then "There was a server error. Please try again later."
|
32
|
+
else "An unknown error occured"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Authenticate with instapaper, returning true if auth
|
37
|
+
# was successful, false otherwise
|
38
|
+
def authenticate
|
39
|
+
RestClient.post @apiurl + "authenticate",
|
40
|
+
:username => @username,
|
41
|
+
:password => @password
|
42
|
+
rescue RestClient::RequestFailed
|
43
|
+
handle_error($!)
|
44
|
+
return false
|
45
|
+
end
|
46
|
+
|
47
|
+
# Add a url to instapaper, given a url and an optional
|
48
|
+
# title; if no title is given, auto-title by instapaper
|
49
|
+
def add(url, title=nil)
|
50
|
+
result = RestClient.post @apiurl + "add",
|
51
|
+
:username => @username,
|
52
|
+
:password => @password,
|
53
|
+
:url => url,
|
54
|
+
:title => title,
|
55
|
+
:"auto-title" => title.nil? ? "1" : "0"
|
56
|
+
rescue RestClient::RequestFailed
|
57
|
+
handle_error($!)
|
58
|
+
return false
|
59
|
+
end
|
60
|
+
end
|
data/ricepaper.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{ricepaper}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Lee Hinman"]
|
9
|
+
s.date = %q{2009-06-10}
|
10
|
+
s.default_executable = %q{ricepaper}
|
11
|
+
s.description = %q{Ricepaper is a library that allows you to add URLs to Instapaper, either by using it as a CLI or as a Ruby library.}
|
12
|
+
s.email = %q{lee@writequit.org}
|
13
|
+
s.executables = ["ricepaper"]
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"README.txt"
|
16
|
+
]
|
17
|
+
s.files = [
|
18
|
+
"ricepaper.gemspec",
|
19
|
+
"Rakefile",
|
20
|
+
"VERSION",
|
21
|
+
"README.txt",
|
22
|
+
"bin/ricepaper",
|
23
|
+
"lib/ricepaper.rb",
|
24
|
+
]
|
25
|
+
s.homepage = %q{http://github.com/dakrone/ricepaper}
|
26
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
27
|
+
s.require_paths = ["lib"]
|
28
|
+
s.rubyforge_project = %q{writequit}
|
29
|
+
s.rubygems_version = %q{1.3.4}
|
30
|
+
s.summary = %q{A small library for adding URLs to Instapaper}
|
31
|
+
|
32
|
+
if s.respond_to? :specification_version then
|
33
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
34
|
+
s.specification_version = 3
|
35
|
+
|
36
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
37
|
+
else
|
38
|
+
end
|
39
|
+
else
|
40
|
+
end
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dakrone-ricepaper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lee Hinman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-06-10 00:00:00 -07:00
|
13
|
+
default_executable: ricepaper
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Ricepaper is a library that allows you to add URLs to Instapaper, either by using it as a CLI or as a Ruby library.
|
17
|
+
email: lee@writequit.org
|
18
|
+
executables:
|
19
|
+
- ricepaper
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.txt
|
24
|
+
files:
|
25
|
+
- ricepaper.gemspec
|
26
|
+
- Rakefile
|
27
|
+
- VERSION
|
28
|
+
- README.txt
|
29
|
+
- bin/ricepaper
|
30
|
+
- lib/ricepaper.rb
|
31
|
+
has_rdoc: false
|
32
|
+
homepage: http://github.com/dakrone/ricepaper
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options:
|
35
|
+
- --charset=UTF-8
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: "0"
|
43
|
+
version:
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
requirements: []
|
51
|
+
|
52
|
+
rubyforge_project: writequit
|
53
|
+
rubygems_version: 1.2.0
|
54
|
+
signing_key:
|
55
|
+
specification_version: 3
|
56
|
+
summary: A small library for adding URLs to Instapaper
|
57
|
+
test_files: []
|
58
|
+
|