Class: Instapi
- Inherits:
-
Object
- Object
- Instapi
- Defined in:
- lib/instapi.rb,
lib/instapi/version.rb
Constant Summary collapse
- BASE_URL =
"https://www.instapaper.com"- VERSION =
"1.3.0"
Instance Attribute Summary collapse
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
- #add(url, options = {}) ⇒ Object
- #archive(id) ⇒ Object
- #client ⇒ Object
- #delete(id) ⇒ Object
- #get(path, params = {}) ⇒ Object
-
#initialize(username, password) ⇒ Instapi
constructor
A new instance of Instapi.
- #unread ⇒ Object
Constructor Details
#initialize(username, password) ⇒ Instapi
Returns a new instance of Instapi.
9 10 11 |
# File 'lib/instapi.rb', line 9 def initialize(username, password) @username, @password = username, password end |
Instance Attribute Details
#password ⇒ Object (readonly)
Returns the value of attribute password.
7 8 9 |
# File 'lib/instapi.rb', line 7 def password @password end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
7 8 9 |
# File 'lib/instapi.rb', line 7 def username @username end |
Class Method Details
.text(url) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/instapi.rb', line 44 def self.text(url) doc = Nokogiri::HTML(get("/text?u=#{url}")) { :title => doc.css('title').first.text, :text => doc.css('#story').first.inner_html } end |
Instance Method Details
#add(url, options = {}) ⇒ Object
20 21 22 |
# File 'lib/instapi.rb', line 20 def add(url, = {}) get('/api/add', {:url => url, :username => username, :password => password}.merge()) end |
#archive(id) ⇒ Object
32 33 34 |
# File 'lib/instapi.rb', line 32 def archive(id) get("/skip/#{id}") end |
#client ⇒ Object
13 14 15 16 17 18 |
# File 'lib/instapi.rb', line 13 def client return @client if @client @client = HTTPClient.new @client.post("#{BASE_URL}/user/login", :username => username, :password => password) @client end |
#delete(id) ⇒ Object
36 37 38 |
# File 'lib/instapi.rb', line 36 def delete(id) get("/delete/#{id}") end |
#get(path, params = {}) ⇒ Object
40 41 42 |
# File 'lib/instapi.rb', line 40 def get(path, params = {}) client.get_content(BASE_URL + path, params) end |
#unread ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/instapi.rb', line 24 def unread Nokogiri::HTML(get("/u")).css('.tableViewCell').map do |elem| id = elem[:id].scan(/tableViewCell(\d+)/)[0][0] link = elem.css('.tableViewCellTitleLink').first {:id => id, :title => link.text, :url => link[:href]} end end |