instapush 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +27 -0
- data/Rakefile +18 -0
- data/VERSION +1 -0
- data/instapush.gemspec +50 -0
- data/lib/instapush.rb +61 -0
- data/spec/instapush_spec.rb +89 -0
- data/spec/spec_helper.rb +2 -0
- metadata +87 -0
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
InstaPush
|
2
|
+
=========
|
3
|
+
|
4
|
+
Add URLs to Instapaper.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
gem install instapush
|
10
|
+
|
11
|
+
Usage
|
12
|
+
-----
|
13
|
+
|
14
|
+
# Connect to Instapaper and add "http://kimjoar.net" to the user "kjbekkelund@gmail.com"
|
15
|
+
# The password is optional and can be omitted when you don't have a password
|
16
|
+
# on Instapaper.
|
17
|
+
InstaPush.connect "kjbekkelund@gmail.com", "password" do
|
18
|
+
add "http://kimjoar.net"
|
19
|
+
end
|
20
|
+
|
21
|
+
# Similarly you can use:
|
22
|
+
conn = InstaPush.connect "kjbekkelund@gmail.com", "password"
|
23
|
+
conn.add "http://kimjoar.net"
|
24
|
+
|
25
|
+
# Just authenticate with Instapaper. Calling this before adding pages is
|
26
|
+
# not necessary.
|
27
|
+
InstaPush.authenticate "kjbekkelund@gmail.com", "password"
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "instapush"
|
8
|
+
gem.summary = "Ruby wrapper for the Instapaper API."
|
9
|
+
gem.description = "Ruby wrapper for the Instapaper API."
|
10
|
+
gem.email = "kjbekkelund@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/kjbekkelund/instapush"
|
12
|
+
gem.author = "Kim Joar Bekkelund"
|
13
|
+
gem.add_development_dependency "rest_client", ">= 1"
|
14
|
+
end
|
15
|
+
Jeweler::GemcutterTasks.new
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
18
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/instapush.gemspec
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{instapush}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kim Joar Bekkelund"]
|
12
|
+
s.date = %q{2010-07-27}
|
13
|
+
s.description = %q{Ruby wrapper for the Instapaper API.}
|
14
|
+
s.email = %q{kjbekkelund@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.md"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"README.md",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION",
|
22
|
+
"instapush.gemspec",
|
23
|
+
"lib/instapush.rb",
|
24
|
+
"spec/instapush_spec.rb",
|
25
|
+
"spec/spec_helper.rb"
|
26
|
+
]
|
27
|
+
s.homepage = %q{http://github.com/kjbekkelund/instapush}
|
28
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
29
|
+
s.require_paths = ["lib"]
|
30
|
+
s.rubygems_version = %q{1.3.7}
|
31
|
+
s.summary = %q{Ruby wrapper for the Instapaper API.}
|
32
|
+
s.test_files = [
|
33
|
+
"spec/instapush_spec.rb",
|
34
|
+
"spec/spec_helper.rb"
|
35
|
+
]
|
36
|
+
|
37
|
+
if s.respond_to? :specification_version then
|
38
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
39
|
+
s.specification_version = 3
|
40
|
+
|
41
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
42
|
+
s.add_development_dependency(%q<rest_client>, [">= 1"])
|
43
|
+
else
|
44
|
+
s.add_dependency(%q<rest_client>, [">= 1"])
|
45
|
+
end
|
46
|
+
else
|
47
|
+
s.add_dependency(%q<rest_client>, [">= 1"])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
data/lib/instapush.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'rest_client'
|
4
|
+
|
5
|
+
class InstaPush
|
6
|
+
class AuthFailedError < StandardError; end
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def connect(username, password = nil, &block)
|
10
|
+
conn = new username, password
|
11
|
+
|
12
|
+
if block_given?
|
13
|
+
conn.instance_eval(&block)
|
14
|
+
else
|
15
|
+
conn
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def authenticate(username, password = nil)
|
20
|
+
conn = connect(username, password)
|
21
|
+
raise AuthFailedError unless conn.authenticate
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :username, :password, :api_url
|
26
|
+
|
27
|
+
def initialize(username, password)
|
28
|
+
@username = username
|
29
|
+
@password = password
|
30
|
+
@api_url = "https://www.instapaper.com/api/"
|
31
|
+
end
|
32
|
+
|
33
|
+
def authenticate
|
34
|
+
RestClient.post authenticate_url,
|
35
|
+
:username => username,
|
36
|
+
:password => password
|
37
|
+
rescue RestClient::RequestFailed
|
38
|
+
errors << $!
|
39
|
+
false
|
40
|
+
end
|
41
|
+
|
42
|
+
def add(url, opts = {})
|
43
|
+
opts.merge! :url => url,
|
44
|
+
:username => username,
|
45
|
+
:password => password
|
46
|
+
|
47
|
+
RestClient.post add_url, opts
|
48
|
+
rescue RestClient::RequestFailed
|
49
|
+
errors << $!
|
50
|
+
false
|
51
|
+
end
|
52
|
+
|
53
|
+
def errors
|
54
|
+
@errors ||= []
|
55
|
+
end
|
56
|
+
|
57
|
+
def method_missing(sym)
|
58
|
+
raise NoMethodError unless sym.to_s.include? '_url'
|
59
|
+
api_url + sym.to_s.chomp('_url')
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
RSpec::Mocks::setup(RestClient)
|
4
|
+
|
5
|
+
describe InstaPush do
|
6
|
+
before do
|
7
|
+
RestClient.stub!(:post).with("https://www.instapaper.com/api/authenticate", hash_including(:username => 'not_working@gmail.com')).and_raise(RestClient::Forbidden)
|
8
|
+
RestClient.stub!(:post).with("https://www.instapaper.com/api/authenticate", hash_including(:username => 'kjbekkelund@gmail.com')).and_return("200")
|
9
|
+
end
|
10
|
+
|
11
|
+
describe ".connect" do
|
12
|
+
it "should yield an instance of InstaPush if a block is given" do
|
13
|
+
yielded = nil
|
14
|
+
InstaPush.connect("kjbekkelund@gmail.com") { yielded = self }
|
15
|
+
yielded.should be_kind_of(InstaPush)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return an instance of InstaPush if a block is not given" do
|
19
|
+
conn = InstaPush.connect "kjbekkelund@gmail.com"
|
20
|
+
conn.should be_kind_of(InstaPush)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe ".authenticate" do
|
25
|
+
it "should raise an exception when it fails" do
|
26
|
+
lambda { InstaPush.authenticate("not_working@gmail.com") }.should raise_error(InstaPush::AuthFailedError)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#errors" do
|
31
|
+
it "should include an error when an api method has failed" do
|
32
|
+
InstaPush.connect "not_working@gmail.com" do
|
33
|
+
authenticate
|
34
|
+
errors.length.should == 1
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should include the exception raised" do
|
39
|
+
InstaPush.connect "not_working@gmail.com" do
|
40
|
+
authenticate
|
41
|
+
errors.first.to_s.should == "Forbidden"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "a connected user" do
|
47
|
+
before do
|
48
|
+
@conn = InstaPush.connect "kjbekkelund@gmail.com"
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#authenticate" do
|
52
|
+
it "should return a status code of 200 if the authentication is successful" do
|
53
|
+
@conn.authenticate.should == "200"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should return false if the authentication was unsuccessful" do
|
57
|
+
@conn = InstaPush.connect "not_working@gmail.com"
|
58
|
+
@conn.authenticate.should be_false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "#add" do
|
63
|
+
it "should post the url to Instapaper" do
|
64
|
+
RestClient.should_receive(:post).once.with("https://www.instapaper.com/api/add", hash_including(:url => "http://kimjoar.net"))
|
65
|
+
@conn.add "http://kimjoar.net"
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should include additional parameters in the call to Instapaper" do
|
69
|
+
RestClient.should_receive(:post).once.with("https://www.instapaper.com/api/add", hash_including(:title=>"Kim Joar", :selection=>"description"))
|
70
|
+
@conn.add "http://kimjoar.net", :title => "Kim Joar", :selection => "description"
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should return a response code of 201 when successful" do
|
74
|
+
RestClient.should_receive(:post).once.with("https://www.instapaper.com/api/add", hash_including(:title=>"Kim Joar", :selection=>"description")).and_return("201")
|
75
|
+
@conn.add("http://kimjoar.net", :title => "Kim Joar", :selection => "description").should == "201"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "#method_missing" do
|
80
|
+
it "should return the extended api url if the input ends with _url" do
|
81
|
+
@conn.add_url.should == "https://www.instapaper.com/api/add"
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should raise a no method error if the method does not exist and the input does not end with _url" do
|
85
|
+
lambda { @conn.method_that_dont_exist }.should raise_error(NoMethodError)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: instapush
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Kim Joar Bekkelund
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-07-27 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rest_client
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 1
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
version: "1"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Ruby wrapper for the Instapaper API.
|
36
|
+
email: kjbekkelund@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README.md
|
43
|
+
files:
|
44
|
+
- README.md
|
45
|
+
- Rakefile
|
46
|
+
- VERSION
|
47
|
+
- instapush.gemspec
|
48
|
+
- lib/instapush.rb
|
49
|
+
- spec/instapush_spec.rb
|
50
|
+
- spec/spec_helper.rb
|
51
|
+
has_rdoc: true
|
52
|
+
homepage: http://github.com/kjbekkelund/instapush
|
53
|
+
licenses: []
|
54
|
+
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options:
|
57
|
+
- --charset=UTF-8
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.3.7
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Ruby wrapper for the Instapaper API.
|
85
|
+
test_files:
|
86
|
+
- spec/instapush_spec.rb
|
87
|
+
- spec/spec_helper.rb
|