Class: KindleHighlight

Inherits:
Object
  • Object
show all
Defined in:
lib/kindle-highlights.rb

Defined Under Namespace

Classes: Highlight

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email_address, password) ⇒ KindleHighlight

Returns a new instance of KindleHighlight.



12
13
14
15
16
17
18
19
# File 'lib/kindle-highlights.rb', line 12

def initialize(email_address, password)
	@agent = Mechanize.new
	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
	scrape_highlights
end

Instance Attribute Details

#highlightsObject

Returns the value of attribute highlights.



10
11
12
# File 'lib/kindle-highlights.rb', line 10

def highlights
  @highlights
end

Instance Method Details

#scrape_highlightsObject



21
22
23
24
25
26
27
28
29
# File 'lib/kindle-highlights.rb', line 21

def scrape_highlights
	 = @agent.submit(@amazon_form)
	highlights_page = @agent.click(.link_with(:text => /Your Highlights/))
	collected_highlights = Array.new
	highlights_page.search(".//div[@class='highlightRow yourHighlight']").each do |h|
		collected_highlights << Highlight.new(h)
	end
	self.highlights = collected_highlights
end