kindle-highlights 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/kindle-highlights.rb +18 -7
  2. metadata +5 -5
@@ -33,16 +33,27 @@ class KindleHighlight::Highlight
33
33
 
34
34
  attr_accessor :annotation_id, :asin, :author, :title, :content
35
35
 
36
+ @@amazon_items = Hash.new
37
+
36
38
  def initialize(highlight)
37
39
  self.annotation_id = highlight.xpath("form/input[@id='annotation_id']").attribute("value").value
38
40
  self.asin = highlight.xpath("p/span[@class='hidden asin']").text
39
41
  self.content = highlight.xpath("span[@class='highlight']").text
40
- @request = Request.new
41
- @request.locale = 'us'
42
- @response = ResponseGroup.new('Medium')
43
- lookup = Amazon::AWS::ItemLookup.new('ASIN', {'ItemId' => self.asin, 'MerchantId' => 'Amazon'})
44
- item = @request.search(lookup, @response).item_lookup_response[0].items.item.first
45
- self.author = item.item_attributes.author.first.to_s
46
- self.title = item.item_attributes.title.first.to_s
42
+ amazon_item = lookup_or_get_from_cache(self.asin)
43
+ self.author = amazon_item.item_attributes.author.to_s
44
+ self.title = amazon_item.item_attributes.title.to_s
45
+ end
46
+
47
+ def lookup_or_get_from_cache(asin)
48
+ unless @@amazon_items.has_key? (asin)
49
+ request = Request.new
50
+ request.locale = 'us'
51
+ response = ResponseGroup.new('Medium')
52
+ lookup = Amazon::AWS::ItemLookup.new('ASIN', {'ItemId' => asin, 'MerchantId' => 'Amazon'})
53
+ puts amazon_item = request.search(lookup, response).item_lookup_response[0].items.inspect
54
+ amazon_item = request.search(lookup, response).item_lookup_response[0].items.item.first
55
+ @@amazon_items[asin] = amazon_item
56
+ end
57
+ @@amazon_items[asin]
47
58
  end
48
59
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kindle-highlights
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-12-20 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mechanize
16
- requirement: &9429540 !ruby/object:Gem::Requirement
16
+ requirement: &9614412 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.0.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *9429540
24
+ version_requirements: *9614412
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: ruby-aaws
27
- requirement: &9429240 !ruby/object:Gem::Requirement
27
+ requirement: &9614112 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 0.7.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *9429240
35
+ version_requirements: *9614112
36
36
  description: Until there is a Kindle API, this will suffice.
37
37
  email: eric@prudentiadigital.com
38
38
  executables: []