Class: KindleHighlights::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/kindle_highlights/client.rb

Defined Under Namespace

Classes: AuthenticationError, CaptchaError

Instance Attribute Summary collapse

Instance Method Summary collapse

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 = mechanize_options
end

Instance Attribute Details

#kindle_logged_in_pageObject

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

Parameters:

  • value

    the value to set the attribute mechanize_agent to.



6
7
8
# File 'lib/kindle_highlights/client.rb', line 6

def mechanize_agent=(value)
  @mechanize_agent = value
end

Instance Method Details

#booksObject



15
16
17
# File 'lib/kindle_highlights/client.rb', line 15

def books
  @books ||= 
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)
  

  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