Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

changed ricepaper to a gem, uploaded to rubyforge

  • Loading branch information...
commit 3573b48834e2757f389199aa9250258f40302324 1 parent 8d38f7e
dakrone authored
View
41 Rakefile
@@ -0,0 +1,41 @@
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gemspec|
+ gemspec.name = "ricepaper"
+ gemspec.summary = "A small library for adding URLs to Instapaper"
+ gemspec.email = "lee@writequit.org"
+ gemspec.homepage = "http://github.com/dakrone/ricepaper"
+ 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."
+ gemspec.authors = ["Lee Hinman"]
+ gemspec.rubyforge_project = 'writequit'
+ end
+rescue LoadError
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
+end
+
+begin
+ require 'rake/contrib/sshpublisher'
+ namespace :rubyforge do
+
+ desc "Release gem and RDoc documentation to RubyForge"
+ task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
+
+ namespace :release do
+ desc "Publish RDoc to RubyForge."
+ task :docs => [:rdoc] do
+ config = YAML.load(
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
+ )
+
+ host = "#{config['username']}@rubyforge.org"
+ remote_dir = "/var/www/gforge-projects/ricepaper/"
+ local_dir = 'rdoc'
+
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
+ end
+ end
+ end
+rescue LoadError
+ puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
+end
+
View
1  VERSION
@@ -0,0 +1 @@
+0.0.1
View
41 bin/ricepaper
@@ -0,0 +1,41 @@
+#!/usr/bin/env ruby
+#
+# CLI interface to adding articles to your instantpaper account
+# by Matthew Lee Hinman (http://writequit.org)
+
+require 'ricepaper'
+require 'optparse'
+
+
+opthash = Hash.new
+options = OptionParser.new do |opts|
+ opts.banner = %q|Usage: #{$0} [options] "<url>" ["<url>" "<url>" ...]|
+ opts.on("-u", "--username [USER]", "Username") { |opt| opthash['username'] = opt }
+ opts.on("-p", "--password [PASS]", "Password") { |opt| opthash['password'] = opt }
+ opts.on("-a", "--authenticate", "Only attempt to authenticate to Instapaper") { |opt| opthash['authenticate'] = opt }
+ opts.on("-t", "--title [TITLE]", "Optional title for instantpaper entry") { |opt| opthash['title'] = opt }
+end
+
+options.parse!(ARGV)
+rp = RicePaper.new(opthash['username'],opthash['password'])
+
+if opthash['authenticate']
+ print "Authenticating... "
+ result = rp.authenticate
+
+ puts result ? "Successful." : "Failed."
+ puts "Error: #{rp.error}" unless result
+ exit(0)
+end
+
+if ARGV.size < 1
+ puts "I need a url to add to InstantPaper"
+end
+
+ARGV.each do |url|
+ print "Submitting '#{url}' #{opthash['title'].nil? ? "" : "with title '#{opthash['title']}'"} ... "
+ result = rp.add(url,opthash['title'])
+
+ puts result ? "Successful." : "Failed."
+ puts "Error: #{rp.error}" unless result
+end
View
60 lib/ricepaper.rb
@@ -0,0 +1,60 @@
+#!/usr/bin/env ruby
+#
+# Library for adding URLs to instapaper.
+# by Matthew Lee Hinman (http://writequit.org)
+#
+
+require 'rubygems'
+require 'rest_client'
+
+# Encapsulation class
+
+class RicePaper
+
+ attr_accessor :username, :password, :apiurl
+ attr_reader :error
+
+ def initialize(username, password, apiurl = "https://www.instapaper.com/api/")
+ @username = username
+ @password = password
+ @apiurl = apiurl
+ @error = ""
+ end
+
+ # Handle Errors - sets the error code appropriately
+ # so that it can be reported
+ def handle_error(err)
+ result = /(\d+)/.match(err.to_s)[1]
+ @error = case result
+ when "400" then "Bad Request"
+ when "403" then "Invalid username of password"
+ when "500" then "There was a server error. Please try again later."
+ else "An unknown error occured"
+ end
+ end
+
+ # Authenticate with instapaper, returning true if auth
+ # was successful, false otherwise
+ def authenticate
+ RestClient.post @apiurl + "authenticate",
+ :username => @username,
+ :password => @password
+ rescue RestClient::RequestFailed
+ handle_error($!)
+ return false
+ end
+
+ # Add a url to instapaper, given a url and an optional
+ # title; if no title is given, auto-title by instapaper
+ def add(url, title=nil)
+ result = RestClient.post @apiurl + "add",
+ :username => @username,
+ :password => @password,
+ :url => url,
+ :title => title,
+ :"auto-title" => title.nil? ? "1" : "0"
+ rescue RestClient::RequestFailed
+ handle_error($!)
+ return false
+ end
+end
View
41 ricepaper.gemspec
@@ -0,0 +1,41 @@
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{ricepaper}
+ s.version = "0.0.1"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Lee Hinman"]
+ s.date = %q{2009-06-10}
+ s.default_executable = %q{ricepaper}
+ 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.}
+ s.email = %q{lee@writequit.org}
+ s.executables = ["ricepaper"]
+ s.extra_rdoc_files = [
+ "README.txt"
+ ]
+ s.files = [
+ "ricepaper.gemspec",
+ "Rakefile",
+ "VERSION",
+ "README.txt",
+ "bin/ricepaper",
+ "lib/ricepaper.rb",
+ ]
+ s.homepage = %q{http://github.com/dakrone/ricepaper}
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.rubyforge_project = %q{writequit}
+ s.rubygems_version = %q{1.3.4}
+ s.summary = %q{A small library for adding URLs to Instapaper}
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ else
+ end
+ else
+ end
+end
View
97 ricepaper.rb
@@ -1,97 +0,0 @@
-#!/usr/bin/env ruby
-#
-# CLI interface to adding articles to your instantpaper account
-# Also works as a library in a pinch
-
-require 'rubygems'
-require 'rest_client'
-require 'optparse'
-
-# Encapsulation class
-
-class RicePaper
-
- attr_accessor :username, :password, :apiurl
- attr_reader :error
-
- def initialize(username, password, apiurl = "https://www.instapaper.com/api/")
- @username = username
- @password = password
- @apiurl = apiurl
- @error = ""
- end
-
- # Handle Errors - sets the error code appropriately
- # so that it can be reported
- def handle_error(err)
- result = /(\d+)/.match(err.to_s)[1]
- @error = case result
- when "400" : "Bad Request"
- when "403" : "Invalid username of password"
- when "500" : "There was a server error. Please try again later."
- else "An unknown error occured"
- end
- end
-
- # Authenticate with instapaper, returning true if auth
- # was successful, false otherwise
- def authenticate
- RestClient.post @apiurl + "authenticate",
- :username => @username,
- :password => @password
- rescue RestClient::RequestFailed
- handle_error($!)
- return false
- end
-
- # Add a url to instapaper, given a url and an optional
- # title; if no title is given, auto-title at instapaper
- def add(url, title=nil)
- result = RestClient.post @apiurl + "add",
- :username => @username,
- :password => @password,
- :url => url,
- :title => title,
- :"auto-title" => title.nil? ? "1" : "0"
- rescue RestClient::RequestFailed
- handle_error($!)
- return false
- end
-end
-
-# Only run CLI if actually running the script instead of requiring it.
-if __FILE__ == $0
-
- opthash = Hash.new
- options = OptionParser.new do |opts|
- opts.banner = %q|Usage: #{$0} [options] "<url>" ["<url>" "<url>" ...]|
- opts.on("-u", "--username [USER]", "Username") { |opt| opthash['username'] = opt }
- opts.on("-p", "--password [PASS]", "Password") { |opt| opthash['password'] = opt }
- opts.on("-a", "--authenticate", "Only attempt to authenticate to Instapaper") { |opt| opthash['authenticate'] = opt }
- opts.on("-t", "--title [TITLE]", "Optional title for instantpaper entry") { |opt| opthash['title'] = opt }
- end
-
- options.parse!(ARGV)
- rp = RicePaper.new(opthash['username'],opthash['password'])
-
- if opthash['authenticate']
- print "Authenticating... "
- result = rp.authenticate
-
- puts result ? "Successful." : "Failed."
- puts "Error: #{rp.error}" unless result
- exit(0)
- end
-
- if ARGV.size < 1
- puts "I need a url to add to InstantPaper"
- end
-
- ARGV.each do |url|
- print "Submitting '#{url}' #{opthash['title'].nil? ? "" : "with title '#{opthash['title']}'"} ... "
- result = rp.add(url,opthash['title'])
-
- puts result ? "Successful." : "Failed."
- puts "Error: #{rp.error}" unless result
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.