class Url2Event::Eventbrite

Public Class Methods

is_parser_for?(uri) click to toggle source
# File lib/url_2_event/adapters/eventbrite.rb, line 6
def is_parser_for?(uri)
  !uri.hostname.match(%r{(?:www\.)?eventbrite\.(com|co\.uk)}).nil?
end

Public Instance Methods

options() click to toggle source
# File lib/url_2_event/adapters/eventbrite.rb, line 11
def options
  @options = {
    headers: {
      "Authorization" => "Bearer #{ENV['EVENTBRITE_TOKEN']}"
    }
  }
end

Protected Instance Methods

event_endpoint() click to toggle source
# File lib/url_2_event/adapters/eventbrite.rb, line 21
def event_endpoint
  "/v3/events/#{get_id}"
end
get_id() click to toggle source
# File lib/url_2_event/adapters/eventbrite.rb, line 25
def get_id
  matcher = %r{/e/[^\b]+-(\d+)}
  matches = matcher.match(@uri.path)
  if !matches.nil?
    matches.captures[0]
  else
    raise Url2Event::UnparsableSourceError
  end
end
to_event(response) click to toggle source
# File lib/url_2_event/adapters/eventbrite.rb, line 35
def to_event(response)
  title = response['name']['text'] if response['name']
  link = response['url']

  if desc = response['description']
    description = sanitize(desc['text'])
  end

  if venue = response['venue']
    location = venue['name']
    location += ", " + venue['address_1'] if venue['address_1']
    location += " " + venue['address_2'] if venue['address_2']
    location += ", " + venue['city'] if venue['city']
  end

  if start = response['start']
    begin_at = Time.parse(start['local'] + " +0000")
  end

  if eend = response['end'] # keywords lol
    end_at = Time.parse(eend['local'] + " +0000")
  end

  Event.new(
    title: title,
    description: description,
    location: location,
    begin_at: begin_at,
    end_at: end_at,
    link: link
  )
end