Sha256: 3ecc6edf0e112ed2f76eae695bb36f004d2bd92f11e15f2019c9f03cc2a1ca0f

Contents?: true

Size: 1.25 KB

Versions: 6

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module ActionNetworkRest
  class Attendances < Base
    class CreateError < StandardError; end

    attr_accessor :event_campaign_id, :event_id

    def base_path
      if event_campaign_id.present?
        "event_campaigns/#{url_escape(event_campaign_id)}/events/#{url_escape(event_id)}/attendances/"
      else
        "events/#{url_escape(event_id)}/attendances/"
      end
    end

    def create(attendance_data)
      response = client.post_request base_path, attendance_data
      new_attendance = object_from_response(response)

      # Action Network treats the attendance create helper endpoint as an unauthenticated
      # "blind" POST (see https://actionnetwork.org/docs/v2/unauthenticated-post/). For this
      # reason they don't return a status code with error to avoid leaking private data. Instead
      # they return 200 OK with an empty body (vs. the newly created attendance's data for successful calls)
      raise CreateError if new_attendance.empty?

      new_attendance
    end

    def update(id, attendance_data)
      response = client.put_request "#{base_path}#{url_escape(id)}", attendance_data
      object_from_response(response)
    end

    private

    def osdi_key
      'osdi:attendance'
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
action_network_rest-0.12.0 lib/action_network_rest/attendances.rb
action_network_rest-1.0.1 lib/action_network_rest/attendances.rb
action_network_rest-1.0.0 lib/action_network_rest/attendances.rb
action_network_rest-0.11.0 lib/action_network_rest/attendances.rb
action_network_rest-0.10.0 lib/action_network_rest/attendances.rb
action_network_rest-0.9.0 lib/action_network_rest/attendances.rb