Class: KindleHighlight::Highlight
- Inherits:
-
Object
- Object
- KindleHighlight::Highlight
- Defined in:
- lib/kindle-highlights.rb
Constant Summary collapse
- @@amazon_items =
Hash.new
Instance Attribute Summary collapse
-
#annotation_id ⇒ Object
Returns the value of attribute annotation_id.
-
#asin ⇒ Object
Returns the value of attribute asin.
-
#author ⇒ Object
Returns the value of attribute author.
-
#content ⇒ Object
Returns the value of attribute content.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(highlight) ⇒ Highlight
constructor
A new instance of Highlight.
- #lookup_or_get_from_cache(asin) ⇒ Object
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. = amazon_item.item_attributes..to_s self.title = amazon_item.item_attributes.title.to_s end |
Instance Attribute Details
#annotation_id ⇒ Object
Returns the value of attribute annotation_id.
34 35 36 |
# File 'lib/kindle-highlights.rb', line 34 def annotation_id @annotation_id end |
#asin ⇒ Object
Returns the value of attribute asin.
34 35 36 |
# File 'lib/kindle-highlights.rb', line 34 def asin @asin end |
#author ⇒ Object
Returns the value of attribute author.
34 35 36 |
# File 'lib/kindle-highlights.rb', line 34 def @author end |
#content ⇒ Object
Returns the value of attribute content.
34 35 36 |
# File 'lib/kindle-highlights.rb', line 34 def content @content end |
#title ⇒ Object
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 |