Sha256: 0da8b982edac04bf92b3577a8fef50ed78724ca3bca60e91ef01de475d2948e5

Contents?: true

Size: 894 Bytes

Versions: 6

Compression:

Stored size: 894 Bytes

Contents

# frozen_string_literal: true

require "csv"
require_relative "require_auth"
require_relative "simple_inspect"
require_relative "request"

module Itch
  # Return purchase history and history by date
  class Purchases
    include RequireAuth
    include SimpleInspect
    include Request

    def initialize(agent)
      @agent = agent
    end

    def history_by_month(month, year)
      fetch_csv format(Itch::URL::MONTH_PURCHASES_CSV, month: month, year: year)
    end

    def history_by_year(year)
      fetch_csv format(Itch::URL::YEAR_PURCHASES_CSV, year: year)
    end

    def history
      fetch_csv Itch::URL::PURCHASES_CSV
    end

    protected

    def fetch_csv(url)
      page = with_login do
        @agent.get(url)
      end

      validate_response(page, action: "fetching purchase CSV", content_type: "text/csv")

      CSV.new(page.content, headers: true)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
itch_client-0.4.3 lib/itch/purchases.rb
itch_client-0.4.2 lib/itch/purchases.rb
itch_client-0.4.1 lib/itch/purchases.rb
itch_client-0.4.0 lib/itch/purchases.rb
itch_client-0.3.0 lib/itch/purchases.rb
itch_client-0.2.0 lib/itch/purchases.rb