Sha256: e88bdc64b213c126fe47ba065fa38cca58a8dba1ffc609ba5d2a58856bb8be87

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

module KindleManager
  class Client
    include AmazonAuth::CommonExtension

    attr_accessor :adapter

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

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

    def sign_in
      @client.sign_in
    end

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

    def fetch_kindle_highlights
      sign_in
      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

1 entries across 1 versions & 1 rubygems

Version Path
kindle_manager-0.3.0 lib/kindle_manager/client.rb