kindle-highlights 0.0.4 → 0.0.5

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 +43 -44
  2. metadata +7 -7
@@ -7,53 +7,52 @@ include Amazon::AWS
7
7
  include Amazon::AWS::Search
8
8
 
9
9
  class KindleHighlight
10
- attr_accessor :highlights
10
+ attr_accessor :highlights
11
11
 
12
- def initialize(email_address, password)
13
- @agent = Mechanize.new
14
- 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")
15
- @amazon_form = page.form('signIn')
16
- @amazon_form.email = email_address
17
- @amazon_form.password = password
18
- scrape_highlights
19
- end
20
-
21
- def scrape_highlights
22
- signin_submission = @agent.submit(@amazon_form)
23
- highlights_page = @agent.click(signin_submission.link_with(:text => /Your Highlights/))
24
- collected_highlights = Array.new
25
- highlights_page.search(".//div[@class='highlightRow yourHighlight']").each do |h|
26
- collected_highlights << Highlight.new(h)
27
- end
28
- self.highlights = collected_highlights
29
- end
12
+ def initialize(email_address, password)
13
+ @agent = Mechanize.new
14
+ 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")
15
+ @amazon_form = page.form('signIn')
16
+ @amazon_form.email = email_address
17
+ @amazon_form.password = password
18
+ scrape_highlights
19
+ end
20
+
21
+ def scrape_highlights
22
+ signin_submission = @agent.submit(@amazon_form)
23
+ highlights_page = @agent.click(signin_submission.link_with(:text => /Your Highlights/))
24
+ collected_highlights = Array.new
25
+ highlights_page.search(".//div[@class='highlightRow yourHighlight']").each do |h|
26
+ collected_highlights << Highlight.new(h)
27
+ end
28
+ self.highlights = collected_highlights
29
+ end
30
30
  end
31
31
 
32
32
  class KindleHighlight::Highlight
33
33
 
34
- attr_accessor :annotation_id, :asin, :author, :title, :content
35
-
36
- @@amazon_items = Hash.new
37
-
38
- def initialize(highlight)
39
- self.annotation_id = highlight.xpath("form/input[@id='annotation_id']").attribute("value").value
40
- self.asin = highlight.xpath("p/span[@class='hidden asin']").text
41
- self.content = highlight.xpath("span[@class='highlight']").text
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]
58
- end
34
+ attr_accessor :annotation_id, :asin, :author, :title, :content
35
+
36
+ @@amazon_items = Hash.new
37
+
38
+ def initialize(highlight)
39
+ self.annotation_id = highlight.xpath("form/input[@id='annotation_id']").attribute("value").value
40
+ self.asin = highlight.xpath("p/span[@class='hidden asin']").text
41
+ self.content = highlight.xpath("span[@class='highlight']").text
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('Small')
52
+ lookup = Amazon::AWS::ItemLookup.new('ASIN', {'ItemId' => asin, 'MerchantId' => 'Amazon'})
53
+ amazon_item = request.search(lookup, response).item_lookup_response[0].items.item.first
54
+ @@amazon_items[asin] = amazon_item
55
+ end
56
+ @@amazon_items[asin]
57
+ end
59
58
  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.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-20 00:00:00.000000000Z
12
+ date: 2011-12-21 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mechanize
16
- requirement: &9614412 !ruby/object:Gem::Requirement
16
+ requirement: &7488372 !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: *9614412
24
+ version_requirements: *7488372
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: ruby-aaws
27
- requirement: &9614112 !ruby/object:Gem::Requirement
27
+ requirement: &7487712 !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: *9614112
35
+ version_requirements: *7487712
36
36
  description: Until there is a Kindle API, this will suffice.
37
37
  email: eric@prudentiadigital.com
38
38
  executables: []
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  version: '0'
61
61
  requirements: []
62
62
  rubyforge_project:
63
- rubygems_version: 1.7.2
63
+ rubygems_version: 1.8.12
64
64
  signing_key:
65
65
  specification_version: 3
66
66
  summary: Kindle highlights