instapaper_full 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ .*.sw*
5
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in instapaper_full.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2011 Matt Biddulph
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions
6
+ are met:
7
+ 1. Redistributions of source code must retain the above copyright
8
+ notice, this list of conditions and the following disclaimer.
9
+ 2. Redistributions in binary form must reproduce the above copyright
10
+ notice, this list of conditions and the following disclaimer in the
11
+ documentation and/or other materials provided with the distribution.
12
+ 3. The name of the author may not be used to endorse or promote products
13
+ derived from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # instapaper_full
2
+
3
+ Ruby wrapper for the [Instapaper Full API](http://www.instapaper.com/api/full)
4
+
5
+ Draft version.
6
+
7
+ Note that you need to [request OAuth Application tokens manually](http://www.instapaper.com/main/request_oauth_consumer_token) and that most methods only work for Instapaper subscribers.
8
+
9
+ # Examples
10
+
11
+ ip = InstapaperFull::API.new :consumer_key => "my key", :consumer_secret => "my secret"
12
+ ip.authenticate "someone@example.com", "password"
13
+ puts ip.options.user_id
14
+ puts ip.bookmarks_list(:limit => 1)[0]['url']
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "instapaper_full/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "instapaper_full"
7
+ s.version = InstapaperFull::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Matt Biddulph"]
10
+ s.email = ["mb@hackdiary.com"]
11
+ s.homepage = "https://github.com/mattb/instapaper_full"
12
+ s.summary = %q{Wrapper for the Instapaper Full Developer API}
13
+ s.description = %q{See http://www.instapaper.com/api/full}
14
+
15
+ s.rubyforge_project = "instapaper_full"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency("faraday", ">=0.5.5")
23
+ s.add_dependency("simple_oauth", ">=0.1.4")
24
+ s.add_dependency("yajl-ruby",">=0.8.1")
25
+ end
@@ -0,0 +1,22 @@
1
+ require 'faraday'
2
+ require 'simple_oauth'
3
+
4
+ # @private
5
+ module Faraday
6
+ # @private
7
+ class Request::OAuth < Faraday::Middleware
8
+ def call(env)
9
+ params = env[:body].is_a?(Hash) ? env[:body] : {}
10
+ signature_params = params.reject{|k,v| v.respond_to?(:content_type) }
11
+ header = SimpleOAuth::Header.new(env[:method], env[:url], signature_params, @options)
12
+
13
+ env[:request_headers]['Authorization'] = header.to_s
14
+
15
+ @app.call(env)
16
+ end
17
+
18
+ def initialize(app, options)
19
+ @app, @options = app, options
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,131 @@
1
+ require 'faraday/oauth'
2
+
3
+ module InstapaperFull
4
+ class API
5
+ attr_accessor :options
6
+ def initialize(options={})
7
+ @options = options
8
+ end
9
+
10
+ def connection
11
+ options = {
12
+ :proxy => @options[:proxy],
13
+ :ssl => {:verify => false},
14
+ :url => "https://www.instapaper.com/api/1/"
15
+ }
16
+ oauth_options = {
17
+ :consumer_key => @options[:consumer_key],
18
+ :consumer_secret => @options[:consumer_secret]
19
+ }
20
+ if authenticated?
21
+ oauth_options[:token] = @options[:oauth_token]
22
+ oauth_options[:token_secret] = @options[:oauth_token_secret]
23
+ end
24
+
25
+ Faraday::Connection.new(options) do |builder|
26
+ builder.use Faraday::Request::OAuth, oauth_options
27
+ builder.adapter Faraday.default_adapter
28
+ if authenticated?
29
+ builder.response :yajl
30
+ end
31
+ end
32
+ end
33
+
34
+ def authenticated?
35
+ @options.has_key? :oauth_token and @options.has_key? :oauth_token_secret
36
+ end
37
+
38
+ def authenticate(username,password)
39
+ @options.delete(:oauth_token)
40
+ @options.delete(:oauth_token_secret)
41
+ result = connection.post 'oauth/access_token' do |r|
42
+ r.body = { :x_auth_username => username, :x_auth_password => password, :x_auth_mode => "client_auth" }
43
+ end
44
+ if result.status == 200
45
+ data = CGI.parse(result.body)
46
+ if data.has_key? 'oauth_token_secret'
47
+ @options[:oauth_token] = data['oauth_token'][0]
48
+ @options[:oauth_token_secret] = data['oauth_token_secret'][0]
49
+ verify_credentials.each { |k,v|
50
+ @options[k.to_sym] = v if k != 'type'
51
+ }
52
+ end
53
+ return true
54
+ else
55
+ return false
56
+ end
57
+ end
58
+
59
+ def call(method, body = nil)
60
+ result = connection.post(method) do |r|
61
+ if body
62
+ r.body = body
63
+ end
64
+ end
65
+ if result.status == 200
66
+ return result.body
67
+ end
68
+ return nil
69
+ end
70
+
71
+ def verify_credentials
72
+ call('account/verify_credentials')[0]
73
+ end
74
+
75
+ def bookmarks_list(options=nil)
76
+ call('bookmarks/list', options)[2..-1] # slice off the 'meta' and 'user' from the front of the array
77
+ end
78
+
79
+ def bookmarks_update_read_progress(options=nil)
80
+ call('bookmarks/update_read_progress', options)
81
+ end
82
+
83
+ def bookmarks_add(options=nil)
84
+ call('bookmarks/add')
85
+ end
86
+
87
+ def bookmarks_delete(options=nil)
88
+ call('bookmarks/delete', options)
89
+ end
90
+
91
+ def bookmarks_star(options=nil)
92
+ call('bookmarks/star', options)
93
+ end
94
+
95
+ def bookmarks_unstar(options=nil)
96
+ call('bookmarks/unstar', options)
97
+ end
98
+
99
+ def bookmarks_archive(options=nil)
100
+ call('bookmarks/archive', options)
101
+ end
102
+
103
+ def bookmarks_unarchive(options=nil)
104
+ call('bookmarks/unarchive', options)
105
+ end
106
+
107
+ def bookmarks_move(options=nil)
108
+ call('bookmarks/move', options)
109
+ end
110
+
111
+ def bookmarks_get_text(options=nil)
112
+ call('bookmarks/get_text', options)
113
+ end
114
+
115
+ def folders_list
116
+ call('folders/list')
117
+ end
118
+
119
+ def folders_add(options=nil)
120
+ call('folders/add', options)
121
+ end
122
+
123
+ def folders_delete(options=nil)
124
+ call('folders/delete', options)
125
+ end
126
+
127
+ def folders_set_order(options=nil)
128
+ call('folders/set_order', options)
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,3 @@
1
+ module InstapaperFull
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: instapaper_full
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Matt Biddulph
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-15 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: faraday
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
+ - 0
32
+ - 5
33
+ - 5
34
+ version: 0.5.5
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: simple_oauth
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 19
46
+ segments:
47
+ - 0
48
+ - 1
49
+ - 4
50
+ version: 0.1.4
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: yajl-ruby
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 61
62
+ segments:
63
+ - 0
64
+ - 8
65
+ - 1
66
+ version: 0.8.1
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ description: See http://www.instapaper.com/api/full
70
+ email:
71
+ - mb@hackdiary.com
72
+ executables: []
73
+
74
+ extensions: []
75
+
76
+ extra_rdoc_files: []
77
+
78
+ files:
79
+ - .gitignore
80
+ - Gemfile
81
+ - LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - instapaper_full.gemspec
85
+ - lib/faraday/oauth.rb
86
+ - lib/instapaper_full.rb
87
+ - lib/instapaper_full/version.rb
88
+ has_rdoc: true
89
+ homepage: https://github.com/mattb/instapaper_full
90
+ licenses: []
91
+
92
+ post_install_message:
93
+ rdoc_options: []
94
+
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
114
+ version: "0"
115
+ requirements: []
116
+
117
+ rubyforge_project: instapaper_full
118
+ rubygems_version: 1.5.2
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: Wrapper for the Instapaper Full Developer API
122
+ test_files: []
123
+