Class: KindleHighlight
- Inherits:
-
Object
- Object
- KindleHighlight
- Defined in:
- lib/kindle-highlights.rb
Defined Under Namespace
Classes: Highlight
Instance Attribute Summary collapse
-
#fetched ⇒ Object
Returns the value of attribute fetched.
-
#highlights ⇒ Object
Returns the value of attribute highlights.
-
#next_url ⇒ Object
Returns the value of attribute next_url.
Instance Method Summary collapse
- #has_more? ⇒ Boolean
-
#initialize(email_address, password) ⇒ KindleHighlight
constructor
A new instance of KindleHighlight.
- #scrape_highlights(should_lookup_book = true) ⇒ Object
Constructor Details
#initialize(email_address, password) ⇒ KindleHighlight
Returns a new instance of KindleHighlight.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/kindle-highlights.rb', line 9 def initialize(email_address, password) @highlights = Array.new @agent = Mechanize.new @agent..clear! @fetched = false page = @agent.get("https://www.amazon.com/ap/signin?openid.return_to=https%3A%2F%2Fkindle.amazon.com%3A443%2Fauthenticate%2Flogin_callback%3Fwctx%3D%252F&pageId=amzn_kindle&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.pape.max_auth_age=0&openid.assoc_handle=amzn_kindle&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select") @amazon_form = page.form('signIn') @amazon_form.email = email_address @amazon_form.password = password end |
Instance Attribute Details
#fetched ⇒ Object
Returns the value of attribute fetched.
7 8 9 |
# File 'lib/kindle-highlights.rb', line 7 def fetched @fetched end |
#highlights ⇒ Object
Returns the value of attribute highlights.
6 7 8 |
# File 'lib/kindle-highlights.rb', line 6 def highlights @highlights end |
#next_url ⇒ Object
Returns the value of attribute next_url.
7 8 9 |
# File 'lib/kindle-highlights.rb', line 7 def next_url @next_url end |
Instance Method Details
#has_more? ⇒ Boolean
39 40 41 |
# File 'lib/kindle-highlights.rb', line 39 def has_more? !self.fetched || (self.fetched && !self.next_url.nil?) end |
#scrape_highlights(should_lookup_book = true) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/kindle-highlights.rb', line 21 def scrape_highlights(should_lookup_book=true) if self.next_url.nil? signin_submission = @agent.submit(@amazon_form) highlights_page = @agent.click(signin_submission.link_with(:text => /Your Highlights/)) self.fetched = true else highlights_page = @agent.get(self.next_url) end new_highlights = Array.new highlights_page.search(".//div[@class='highlightRow yourHighlight']").each do |highlight| new_highlights << Highlight.new(highlight, should_lookup_book) end self.highlights = self.highlights + new_highlights self.next_url = highlights_page.search("a#nextBookLink").attribute('href') rescue nil new_highlights end |