Class: InstapaperFull::API
- Inherits:
-
Object
- Object
- InstapaperFull::API
- Defined in:
- lib/instapaper_full.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #authenticate(username, password) ⇒ Object
- #authenticated? ⇒ Boolean
- #bookmarks_add(options = nil) ⇒ Object
- #bookmarks_archive(options = nil) ⇒ Object
- #bookmarks_delete(options = nil) ⇒ Object
- #bookmarks_get_text(options = nil) ⇒ Object
- #bookmarks_list(options = nil) ⇒ Object
- #bookmarks_move(options = nil) ⇒ Object
- #bookmarks_star(options = nil) ⇒ Object
- #bookmarks_unarchive(options = nil) ⇒ Object
- #bookmarks_unstar(options = nil) ⇒ Object
- #bookmarks_update_read_progress(options = nil) ⇒ Object
- #call(method, body = nil) ⇒ Object
- #connection ⇒ Object
- #folders_add(options = nil) ⇒ Object
- #folders_delete(options = nil) ⇒ Object
- #folders_list ⇒ Object
- #folders_set_order(options = nil) ⇒ Object
-
#initialize(options = {}) ⇒ API
constructor
A new instance of API.
- #verify_credentials ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ API
Returns a new instance of API.
8 9 10 |
# File 'lib/instapaper_full.rb', line 8 def initialize(={}) @options = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/instapaper_full.rb', line 7 def @options end |
Instance Method Details
#authenticate(username, password) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/instapaper_full.rb', line 43 def authenticate(username,password) @options.delete(:oauth_token) @options.delete(:oauth_token_secret) result = connection.post 'oauth/access_token' do |r| r.body = { :x_auth_username => username, :x_auth_password => password, :x_auth_mode => "client_auth" } end if result.status == 200 data = CGI.parse(result.body) if data.has_key? 'oauth_token_secret' @options[:oauth_token] = data['oauth_token'][0] @options[:oauth_token_secret] = data['oauth_token_secret'][0] verify_credentials.each { |k,v| @options[k.to_sym] = v if k != 'type' } end return true else return false end end |
#authenticated? ⇒ Boolean
39 40 41 |
# File 'lib/instapaper_full.rb', line 39 def authenticated? @options.has_key? :oauth_token and @options.has_key? :oauth_token_secret end |
#bookmarks_add(options = nil) ⇒ Object
85 86 87 |
# File 'lib/instapaper_full.rb', line 85 def bookmarks_add(=nil) call('bookmarks/add',) end |
#bookmarks_archive(options = nil) ⇒ Object
101 102 103 |
# File 'lib/instapaper_full.rb', line 101 def bookmarks_archive(=nil) call('bookmarks/archive', ) end |
#bookmarks_delete(options = nil) ⇒ Object
89 90 91 |
# File 'lib/instapaper_full.rb', line 89 def bookmarks_delete(=nil) call('bookmarks/delete', ) end |
#bookmarks_get_text(options = nil) ⇒ Object
113 114 115 |
# File 'lib/instapaper_full.rb', line 113 def bookmarks_get_text(=nil) call('bookmarks/get_text', ) end |
#bookmarks_list(options = nil) ⇒ Object
77 78 79 |
# File 'lib/instapaper_full.rb', line 77 def bookmarks_list(=nil) call('bookmarks/list', )[2..-1] # slice off the 'meta' and 'user' from the front of the array end |
#bookmarks_move(options = nil) ⇒ Object
109 110 111 |
# File 'lib/instapaper_full.rb', line 109 def bookmarks_move(=nil) call('bookmarks/move', ) end |
#bookmarks_star(options = nil) ⇒ Object
93 94 95 |
# File 'lib/instapaper_full.rb', line 93 def bookmarks_star(=nil) call('bookmarks/star', ) end |
#bookmarks_unarchive(options = nil) ⇒ Object
105 106 107 |
# File 'lib/instapaper_full.rb', line 105 def bookmarks_unarchive(=nil) call('bookmarks/unarchive', ) end |
#bookmarks_unstar(options = nil) ⇒ Object
97 98 99 |
# File 'lib/instapaper_full.rb', line 97 def bookmarks_unstar(=nil) call('bookmarks/unstar', ) end |
#bookmarks_update_read_progress(options = nil) ⇒ Object
81 82 83 |
# File 'lib/instapaper_full.rb', line 81 def bookmarks_update_read_progress(=nil) call('bookmarks/update_read_progress', ) end |
#call(method, body = nil) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/instapaper_full.rb', line 64 def call(method, body = nil) result = connection.post(method) do |r| if body r.body = body end end return result.body end |
#connection ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/instapaper_full.rb', line 12 def connection = { :proxy => @options[:proxy], :ssl => {:verify => false}, :url => "https://www.instapaper.com/api/1/" } = { :consumer_key => @options[:consumer_key], :consumer_secret => @options[:consumer_secret] } if authenticated? [:token] = @options[:oauth_token] [:token_secret] = @options[:oauth_token_secret] end Faraday.new() do |builder| builder.use Faraday::Request::OAuth, builder.use Faraday::Request::UrlEncoded builder.use Faraday::Response::Logger builder.adapter Faraday.default_adapter if authenticated? builder.use Faraday::Response::ParseJson end end end |
#folders_add(options = nil) ⇒ Object
121 122 123 |
# File 'lib/instapaper_full.rb', line 121 def folders_add(=nil) call('folders/add', ) end |
#folders_delete(options = nil) ⇒ Object
125 126 127 |
# File 'lib/instapaper_full.rb', line 125 def folders_delete(=nil) call('folders/delete', ) end |
#folders_list ⇒ Object
117 118 119 |
# File 'lib/instapaper_full.rb', line 117 def folders_list call('folders/list') end |
#folders_set_order(options = nil) ⇒ Object
129 130 131 |
# File 'lib/instapaper_full.rb', line 129 def folders_set_order(=nil) call('folders/set_order', ) end |
#verify_credentials ⇒ Object
73 74 75 |
# File 'lib/instapaper_full.rb', line 73 def verify_credentials call('account/verify_credentials')[0] end |