Sha256: 5c53ebe2725d86e425d6838f748dabf62a219c9c1bc7309bce739c46a9f349c3

Contents?: true

Size: 878 Bytes

Versions: 12

Compression:

Stored size: 878 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

12 entries across 12 versions & 1 rubygems

Version Path
eventbrite_sdk-3.1.1 lib/eventbrite_sdk/report.rb
eventbrite_sdk-3.1.0 lib/eventbrite_sdk/report.rb
eventbrite_sdk-3.0.11 lib/eventbrite_sdk/report.rb
eventbrite_sdk-3.0.10 lib/eventbrite_sdk/report.rb
eventbrite_sdk-3.0.9 lib/eventbrite_sdk/report.rb
eventbrite_sdk-3.0.8 lib/eventbrite_sdk/report.rb
eventbrite_sdk-3.0.7 lib/eventbrite_sdk/report.rb
eventbrite_sdk-3.0.6 lib/eventbrite_sdk/report.rb
eventbrite_sdk-3.0.5 lib/eventbrite_sdk/report.rb
eventbrite_sdk-3.0.4 lib/eventbrite_sdk/report.rb
eventbrite_sdk-3.0.3 lib/eventbrite_sdk/report.rb
eventbrite_sdk-3.0.2 lib/eventbrite_sdk/report.rb