instapush 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -11,17 +11,22 @@ Installation
11
11
  Usage
12
12
  -----
13
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.
14
+ Connect to Instapaper and add "http://kimjoar.net" to the user "kjbekkelund@gmail.com". The password is optional and can be omitted when you don't have a password on Instapaper.
15
+
17
16
  InstaPush.connect "kjbekkelund@gmail.com", "password" do
18
17
  add "http://kimjoar.net"
19
18
  end
20
-
21
- # Similarly you can use:
19
+
20
+ Similarly you can use:
21
+
22
22
  conn = InstaPush.connect "kjbekkelund@gmail.com", "password"
23
23
  conn.add "http://kimjoar.net"
24
-
25
- # Just authenticate with Instapaper. Calling this before adding pages is
26
- # not necessary.
24
+
25
+ Just authenticate with Instapaper. Calling this before adding pages is not necessary.
26
+
27
27
  InstaPush.authenticate "kjbekkelund@gmail.com", "password"
28
+
29
+ In the wild
30
+ -----------
31
+
32
+ * [Merging from Pinboard to Instapaper](http://kimjoar.net/merging-from-pinboard-to-instapaper.html)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{instapush}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kim Joar Bekkelund"]
12
- s.date = %q{2010-07-27}
12
+ s.date = %q{2010-08-06}
13
13
  s.description = %q{Ruby wrapper for the Instapaper API.}
14
14
  s.email = %q{kjbekkelund@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -4,32 +4,36 @@ require 'rest_client'
4
4
 
5
5
  class InstaPush
6
6
  class AuthFailedError < StandardError; end
7
-
7
+
8
8
  class << self
9
9
  def connect(username, password = nil, &block)
10
10
  conn = new username, password
11
-
11
+
12
12
  if block_given?
13
- conn.instance_eval(&block)
13
+ if block.arity == 1
14
+ block.call(conn)
15
+ else
16
+ conn.instance_eval(&block)
17
+ end
14
18
  else
15
19
  conn
16
20
  end
17
21
  end
18
-
22
+
19
23
  def authenticate(username, password = nil)
20
24
  conn = connect(username, password)
21
25
  raise AuthFailedError unless conn.authenticate
22
26
  end
23
27
  end
24
-
28
+
25
29
  attr_reader :username, :password, :api_url
26
-
30
+
27
31
  def initialize(username, password)
28
32
  @username = username
29
33
  @password = password
30
34
  @api_url = "https://www.instapaper.com/api/"
31
35
  end
32
-
36
+
33
37
  def authenticate
34
38
  RestClient.post authenticate_url,
35
39
  :username => username,
@@ -38,24 +42,24 @@ class InstaPush
38
42
  errors << $!
39
43
  false
40
44
  end
41
-
45
+
42
46
  def add(url, opts = {})
43
47
  opts.merge! :url => url,
44
- :username => username,
48
+ :username => username,
45
49
  :password => password
46
-
50
+
47
51
  RestClient.post add_url, opts
48
52
  rescue RestClient::RequestFailed
49
53
  errors << $!
50
54
  false
51
55
  end
52
-
56
+
53
57
  def errors
54
58
  @errors ||= []
55
59
  end
56
-
60
+
57
61
  def method_missing(sym)
58
62
  raise NoMethodError unless sym.to_s.include? '_url'
59
63
  api_url + sym.to_s.chomp('_url')
60
64
  end
61
- end
65
+ end
@@ -7,26 +7,26 @@ describe InstaPush do
7
7
  RestClient.stub!(:post).with("https://www.instapaper.com/api/authenticate", hash_including(:username => 'not_working@gmail.com')).and_raise(RestClient::Forbidden)
8
8
  RestClient.stub!(:post).with("https://www.instapaper.com/api/authenticate", hash_including(:username => 'kjbekkelund@gmail.com')).and_return("200")
9
9
  end
10
-
10
+
11
11
  describe ".connect" do
12
12
  it "should yield an instance of InstaPush if a block is given" do
13
13
  yielded = nil
14
14
  InstaPush.connect("kjbekkelund@gmail.com") { yielded = self }
15
15
  yielded.should be_kind_of(InstaPush)
16
16
  end
17
-
17
+
18
18
  it "should return an instance of InstaPush if a block is not given" do
19
19
  conn = InstaPush.connect "kjbekkelund@gmail.com"
20
20
  conn.should be_kind_of(InstaPush)
21
21
  end
22
22
  end
23
-
23
+
24
24
  describe ".authenticate" do
25
25
  it "should raise an exception when it fails" do
26
26
  lambda { InstaPush.authenticate("not_working@gmail.com") }.should raise_error(InstaPush::AuthFailedError)
27
27
  end
28
28
  end
29
-
29
+
30
30
  describe "#errors" do
31
31
  it "should include an error when an api method has failed" do
32
32
  InstaPush.connect "not_working@gmail.com" do
@@ -34,15 +34,15 @@ describe InstaPush do
34
34
  errors.length.should == 1
35
35
  end
36
36
  end
37
-
37
+
38
38
  it "should include the exception raised" do
39
39
  InstaPush.connect "not_working@gmail.com" do
40
40
  authenticate
41
41
  errors.first.to_s.should == "Forbidden"
42
42
  end
43
- end
43
+ end
44
44
  end
45
-
45
+
46
46
  context "a connected user" do
47
47
  before do
48
48
  @conn = InstaPush.connect "kjbekkelund@gmail.com"
@@ -52,38 +52,38 @@ describe InstaPush do
52
52
  it "should return a status code of 200 if the authentication is successful" do
53
53
  @conn.authenticate.should == "200"
54
54
  end
55
-
55
+
56
56
  it "should return false if the authentication was unsuccessful" do
57
57
  @conn = InstaPush.connect "not_working@gmail.com"
58
58
  @conn.authenticate.should be_false
59
59
  end
60
60
  end
61
-
61
+
62
62
  describe "#add" do
63
63
  it "should post the url to Instapaper" do
64
64
  RestClient.should_receive(:post).once.with("https://www.instapaper.com/api/add", hash_including(:url => "http://kimjoar.net"))
65
65
  @conn.add "http://kimjoar.net"
66
66
  end
67
-
67
+
68
68
  it "should include additional parameters in the call to Instapaper" do
69
69
  RestClient.should_receive(:post).once.with("https://www.instapaper.com/api/add", hash_including(:title=>"Kim Joar", :selection=>"description"))
70
70
  @conn.add "http://kimjoar.net", :title => "Kim Joar", :selection => "description"
71
71
  end
72
-
72
+
73
73
  it "should return a response code of 201 when successful" do
74
74
  RestClient.should_receive(:post).once.with("https://www.instapaper.com/api/add", hash_including(:title=>"Kim Joar", :selection=>"description")).and_return("201")
75
75
  @conn.add("http://kimjoar.net", :title => "Kim Joar", :selection => "description").should == "201"
76
76
  end
77
77
  end
78
-
79
- describe "#method_missing" do
78
+
79
+ describe "#method_missing" do
80
80
  it "should return the extended api url if the input ends with _url" do
81
81
  @conn.add_url.should == "https://www.instapaper.com/api/add"
82
82
  end
83
-
83
+
84
84
  it "should raise a no method error if the method does not exist and the input does not end with _url" do
85
85
  lambda { @conn.method_that_dont_exist }.should raise_error(NoMethodError)
86
86
  end
87
87
  end
88
88
  end
89
- end
89
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instapush
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kim Joar Bekkelund
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-27 00:00:00 +02:00
18
+ date: 2010-08-06 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency