Sha256: 3cad3db7afccc0e90fe50dacfb150967fb330ed8d02fd661e737c422f1db083e

Contents?: true

Size: 1.07 KB

Versions: 10

Compression:

Stored size: 1.07 KB

Contents

module KindleManager
  class Client
    include AmazonAuth::CommonExtension

    attr_accessor :adapter, :options

    def initialize(options = {})
      @options = options
      @client = AmazonAuth::Client.new(@options)
      extend(AmazonAuth::SessionExtension)
    end

    def session
      @_session ||= @client.session
    end

    def fetch_kindle_list
      sign_in
      set_adapter(:books, @options.merge(session: session))
      adapter.fetch
    end

    def fetch_kindle_highlights
      sign_in KindleManager::HighlightsAdapter::KINDLE_HIGHLIGHT_URL
      set_adapter(:highlights, @options.merge(session: session))
      adapter.fetch
    end

    def load_kindle_books
      set_adapter(:books, @options.except(:create))
      adapter.load
    end

    def load_kindle_highlights
      set_adapter(:highlights, @options.except(:create))
      adapter.load
    end

    def quit
      session.driver.quit
    end

    def set_adapter(type, options)
      @adapter = "KindleManager::#{type.to_s.camelize}Adapter".constantize.new(options.merge(sub_dir: type))
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
kindle_manager-0.9.1 lib/kindle_manager/client.rb
kindle_manager-0.9.0 lib/kindle_manager/client.rb
kindle_manager-0.8.0 lib/kindle_manager/client.rb
kindle_manager-0.7.0 lib/kindle_manager/client.rb
kindle_manager-0.6.4 lib/kindle_manager/client.rb
kindle_manager-0.6.3 lib/kindle_manager/client.rb
kindle_manager-0.6.2 lib/kindle_manager/client.rb
kindle_manager-0.6.1 lib/kindle_manager/client.rb
kindle_manager-0.6.0 lib/kindle_manager/client.rb
kindle_manager-0.5.0 lib/kindle_manager/client.rb