Class: KindleHighlights::Client
- Inherits:
-
Object
- Object
- KindleHighlights::Client
- Defined in:
- lib/kindle_highlights/client.rb
Defined Under Namespace
Classes: AuthenticationError, CaptchaError
Instance Attribute Summary collapse
-
#kindle_logged_in_page ⇒ Object
Returns the value of attribute kindle_logged_in_page.
-
#mechanize_agent ⇒ Object
writeonly
Sets the attribute mechanize_agent.
Instance Method Summary collapse
- #books ⇒ Object
- #highlights_for(asin) ⇒ Object
-
#initialize(email_address:, password:, mechanize_options: {}) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(email_address:, password:, mechanize_options: {}) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 |
# File 'lib/kindle_highlights/client.rb', line 9 def initialize(email_address:, password:, mechanize_options: {}) @email_address = email_address @password = password @mechanize_options = end |
Instance Attribute Details
#kindle_logged_in_page ⇒ Object
Returns the value of attribute kindle_logged_in_page.
7 8 9 |
# File 'lib/kindle_highlights/client.rb', line 7 def kindle_logged_in_page @kindle_logged_in_page end |
#mechanize_agent=(value) ⇒ Object
Sets the attribute mechanize_agent
6 7 8 |
# File 'lib/kindle_highlights/client.rb', line 6 def mechanize_agent=(value) @mechanize_agent = value end |
Instance Method Details
#books ⇒ Object
15 16 17 |
# File 'lib/kindle_highlights/client.rb', line 15 def books @books ||= load_books_from_kindle_account end |
#highlights_for(asin) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/kindle_highlights/client.rb', line 19 def highlights_for(asin) conditionally_sign_in_to_amazon cursor = 0 highlights = [] loop do # This endpoint includes a `hasMore` field. Unfortunately at the time of this writing is always `false`. page = mechanize_agent.get("https://kindle.amazon.com/kcw/highlights?asin=#{asin}&cursor=#{cursor}&count=#{BATCH_SIZE}") items = JSON.parse(page.body).fetch("items", []) break unless items.any? highlights.concat(items) cursor += BATCH_SIZE end highlights end |