class EventbriteSDK::Media

This module implements media upload to Eventbrite based on: docs.evbhome.com/apidocs/reference/uploads/?highlight=logo

Constants

VALID_TYPES

Attributes

file[R]
image_type[R]

Public Instance Methods

upload!(image_type, file) click to toggle source
# File lib/eventbrite_sdk/media.rb, line 26
def upload!(image_type, file)
  # Media uploads through the API involve a multiple step process:

  # 1. Retrieve upload instructions + an upload token from the API
  instructions = get_instructions(image_type)

  # 2. Upload the file to the endpoint specified in the upload instructions
  eventbrite_upload(file, instructions)

  # 3. When the upload has finished, notify the API by re-sending the
  #    upload token from step 1
  notify(instructions['upload_token'])

  true
end

Private Instance Methods

eventbrite_upload(file, instructions) click to toggle source
# File lib/eventbrite_sdk/media.rb, line 54
def eventbrite_upload(file, instructions)
  RestClient.post(
    instructions['upload_url'],
    instructions['upload_data'].merge(file: file),
    multipart: true
  )
end
get_instructions(image_type, request = EventbriteSDK) click to toggle source
# File lib/eventbrite_sdk/media.rb, line 44
def get_instructions(image_type, request = EventbriteSDK)
  type = VALID_TYPES[image_type]

  unless type
    raise ArgumentError, "image_type needs to be one of #{VALID_TYPES.keys}"
  end

  request.get(url: path('upload'), query: { type: type })
end
notify(upload_token, request = EventbriteSDK) click to toggle source
# File lib/eventbrite_sdk/media.rb, line 62
def notify(upload_token, request = EventbriteSDK)
  response = request.post(
    url: path('upload'), payload: { upload_token: upload_token }
  )

  if payload['crop_mask']
    response = request.post(url: path(response['id']), payload: payload)
  end

  reload(response)
end