Sha256: 736c13ecb321de0200bf726536faedfaa003874884e6a6a03f69ce134eb59e6b

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

require "forwardable"
require "mechanize"

require_relative "auth"
require_relative "game"
require_relative "game_map"
require_relative "purchases"
require_relative "simple_inspect"

module Itch
  # The primary client interface
  #
  # The top level client delegates to child modules for specific app areas
  # like game and purchases pages
  class Client
    extend Forwardable
    include SimpleInspect

    def_delegators :@auth, :logged_in?, :login, :totp=, :username=, :password=

    def initialize(username: nil, password: nil, cookie_path: nil)
      @agent = Mechanize.new
      @auth = Auth.new(@agent, username: username, password: password, cookie_path: cookie_path)

      @agent.cookie_jar.load(cookie_path) if cookie_path && File.readable?(cookie_path)
    end

    def game(id = nil, name: nil)
      Game.new(@agent, game_map, id, name: name)
    end

    def purchases
      @purchases ||= Purchases.new(@agent)
    end

    def game_map
      @game_map ||= GameMap.new(@agent)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
itch_client-0.2.0 lib/itch/client.rb