Class: KindleHighlight::Highlight

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

Constant Summary collapse

@@amazon_items =
Hash.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(highlight) ⇒ Highlight

Returns a new instance of Highlight.



38
39
40
41
42
43
44
45
# File 'lib/kindle-highlights.rb', line 38

def initialize(highlight)
	self.annotation_id = highlight.xpath("form/input[@id='annotation_id']").attribute("value").value 
	self.asin = highlight.xpath("p/span[@class='hidden asin']").text
	self.content = highlight.xpath("span[@class='highlight']").text
	amazon_item = lookup_or_get_from_cache(self.asin)
	self.author = amazon_item.item_attributes.author.to_s
	self.title = amazon_item.item_attributes.title.to_s
end

Instance Attribute Details

#annotation_idObject

Returns the value of attribute annotation_id.



34
35
36
# File 'lib/kindle-highlights.rb', line 34

def annotation_id
  @annotation_id
end

#asinObject

Returns the value of attribute asin.



34
35
36
# File 'lib/kindle-highlights.rb', line 34

def asin
  @asin
end

#authorObject

Returns the value of attribute author.



34
35
36
# File 'lib/kindle-highlights.rb', line 34

def author
  @author
end

#contentObject

Returns the value of attribute content.



34
35
36
# File 'lib/kindle-highlights.rb', line 34

def content
  @content
end

#titleObject

Returns the value of attribute title.



34
35
36
# File 'lib/kindle-highlights.rb', line 34

def title
  @title
end

Instance Method Details

#lookup_or_get_from_cache(asin) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/kindle-highlights.rb', line 47

def lookup_or_get_from_cache(asin)
	unless @@amazon_items.has_key? (asin)
		request = Request.new
		request.locale = 'us'
		response = ResponseGroup.new('Medium')
		lookup = Amazon::AWS::ItemLookup.new('ASIN', {'ItemId' => asin, 'MerchantId' => 'Amazon'})
		puts amazon_item = request.search(lookup, response).item_lookup_response[0].items.inspect
		amazon_item = request.search(lookup, response).item_lookup_response[0].items.item.first
		@@amazon_items[asin] = amazon_item
	end
	@@amazon_items[asin]
end