ricepaper 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.txt CHANGED
@@ -1,4 +1,6 @@
1
1
  RicePaper is a tiny little command-line utility to post URLs to
2
2
  InstantPaper. It also works as a Ruby library in a pinch also.
3
3
 
4
- RicePaper is still a work in progress.
4
+ See the examples/ directory for example usage, or use
5
+ 'ricepaper -h' for command-line usage.
6
+
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.2
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Add sites to Instapaper using Ricepaper
4
+ #
5
+
6
+ require 'ricepaper'
7
+
8
+ rp = RicePaper.new("username", "password")
9
+
10
+ sites = [
11
+ "http://google.com",
12
+ "http://ruby-lang.org",
13
+ "http://instapaper.com"
14
+ ]
15
+
16
+ sites.each { |site|
17
+ puts "Added #{site}." if rp.add(site)
18
+ }
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Test authenticating the user to Instapaper
4
+ #
5
+
6
+ require 'ricepaper'
7
+
8
+ rp = RicePaper.new("username", "password")
9
+
10
+ if rp.authenticate
11
+ puts "Authentication successfull."
12
+ else
13
+ puts "Authentication failed."
14
+ 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,47 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{ricepaper}
5
+ s.version = "0.0.2"
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-07-21}
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
+ "README.txt",
19
+ "Rakefile",
20
+ "VERSION",
21
+ "bin/ricepaper",
22
+ "examples/add_sites.rb",
23
+ "examples/authentication_test.rb",
24
+ "lib/ricepaper.rb",
25
+ "ricepaper.gemspec"
26
+ ]
27
+ s.homepage = %q{http://github.com/dakrone/ricepaper}
28
+ s.rdoc_options = ["--charset=UTF-8"]
29
+ s.require_paths = ["lib"]
30
+ s.rubyforge_project = %q{writequit}
31
+ s.rubygems_version = %q{1.3.4}
32
+ s.summary = %q{A small library for adding URLs to Instapaper}
33
+ s.test_files = [
34
+ "examples/add_sites.rb",
35
+ "examples/authentication_test.rb"
36
+ ]
37
+
38
+ if s.respond_to? :specification_version then
39
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
43
+ else
44
+ end
45
+ else
46
+ end
47
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ricepaper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Hinman
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-10 00:00:00 -06:00
12
+ date: 2009-07-21 00:00:00 -06:00
13
13
  default_executable: ricepaper
14
14
  dependencies: []
15
15
 
@@ -23,6 +23,13 @@ extra_rdoc_files:
23
23
  - README.txt
24
24
  files:
25
25
  - README.txt
26
+ - Rakefile
27
+ - VERSION
28
+ - bin/ricepaper
29
+ - examples/add_sites.rb
30
+ - examples/authentication_test.rb
31
+ - lib/ricepaper.rb
32
+ - ricepaper.gemspec
26
33
  has_rdoc: true
27
34
  homepage: http://github.com/dakrone/ricepaper
28
35
  licenses: []
@@ -51,5 +58,6 @@ rubygems_version: 1.3.4
51
58
  signing_key:
52
59
  specification_version: 3
53
60
  summary: A small library for adding URLs to Instapaper
54
- test_files: []
55
-
61
+ test_files:
62
+ - examples/add_sites.rb
63
+ - examples/authentication_test.rb