Sha256: 7e50eb3e92781f49a4b0302e0a51e23d756b06d2c40614bf8384f7380b688637

Contents?: true

Size: 877 Bytes

Versions: 10

Compression:

Stored size: 877 Bytes

Contents

module EventbriteSDK
  class Report
    STRING_KEYS = %i[
      start_date
      end_date
      date_facet
      event_status
      timezone
      group_by
    ].freeze
    VALID_REPORTS = %i[attendees sales].freeze

    def initialize
      @query = {}
    end

    def event_ids(*ids)
      @query[:event_ids] = ids.join(',')

      self
    end

    def filter_by(filters)
      @query[:filter_by] = filters.to_json

      self
    end

    STRING_KEYS.each do |method|
      define_method(method) do |value|
        @query[method] = value
        self
      end
    end

    def query
      @query.dup # Don't allow mutation
    end

    def retrieve(type = nil, sdk = EventbriteSDK)
      unless VALID_REPORTS.include?(type)
        raise ArgumentError, "`:type` is not of #{VALID_REPORTS}"
      end

      sdk.get(url: "reports/#{type}", query: query)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
eventbrite_sdk-3.6.0 lib/eventbrite_sdk/report.rb
eventbrite_sdk-3.4.0 lib/eventbrite_sdk/report.rb
eventbrite_sdk-3.3.1 lib/eventbrite_sdk/report.rb
eventbrite_sdk-3.3.0 lib/eventbrite_sdk/report.rb
eventbrite_sdk-3.2.0 lib/eventbrite_sdk/report.rb
eventbrite_sdk-3.1.6 lib/eventbrite_sdk/report.rb
eventbrite_sdk-3.1.5 lib/eventbrite_sdk/report.rb
eventbrite_sdk-3.1.4 lib/eventbrite_sdk/report.rb
eventbrite_sdk-3.1.3 lib/eventbrite_sdk/report.rb
eventbrite_sdk-3.1.2 lib/eventbrite_sdk/report.rb