Skip to content
Permalink
Browse files

Merge pull request #514 from geeksforsocialchange/master

Merge Eventbrite support
  • Loading branch information
kimadactyl committed Feb 13, 2020
2 parents 767b9f5 + 8b030f5 commit 6e8651af42d4af1590bec463b455ef06a165ae1f
@@ -27,6 +27,7 @@ gem 'webpacker'
gem 'httparty'
gem 'icalendar'
gem 'icalendar-recurrence'
gem 'eventbrite_sdk'

# Uploads
gem 'carrierwave'
@@ -145,6 +145,8 @@ GEM
actionmailer (>= 5.0)
devise (>= 4.6)
docile (1.3.2)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.7.5)
dotenv-rails (2.7.5)
dotenv (= 2.7.5)
@@ -177,6 +179,8 @@ GEM
activesupport (>= 3.2)
equalizer (0.0.11)
erubi (1.9.0)
eventbrite_sdk (3.4.0)
rest-client (~> 2.0)
eventmachine (1.2.7)
execjs (2.7.0)
factory_bot (5.1.1)
@@ -233,6 +237,9 @@ GEM
minitest (>= 3.0)
hashdiff (1.0.0)
hashie (3.6.0)
http-accept (1.7.0)
http-cookie (1.0.3)
domain_name (~> 0.5)
http_parser.rb (0.6.0)
httparty (0.17.3)
mime-types (~> 3.0)
@@ -313,6 +320,7 @@ GEM
mustermann-grape (1.0.1)
mustermann (>= 1.0.0)
nenv (0.3.0)
netrc (0.11.0)
nio4r (2.5.2)
nokogiri (1.10.7)
mini_portile2 (~> 2.4.0)
@@ -408,6 +416,11 @@ GEM
responders (3.0.0)
actionpack (>= 5.0)
railties (>= 5.0)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rollbar (2.23.2)
rubocop (0.79.0)
jaro_winkler (~> 1.5.1)
@@ -478,6 +491,9 @@ GEM
thread_safe (~> 0.1)
uglifier (4.2.0)
execjs (>= 0.3.0, < 3)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.6)
unicode-display_width (1.6.1)
vcr (5.0.0)
virtus (1.0.5)
@@ -530,6 +546,7 @@ DEPENDENCIES
devise_invitable
dotenv-rails
enumerize
eventbrite_sdk
factory_bot_rails
font-awesome-rails
friendly_id (~> 5.3.0)
@@ -2,7 +2,7 @@ class CalendarParser
class UnsupportedFeed < StandardError; end
class InaccessibleFeed < StandardError; end

PARSERS = [Parsers::ManchesterUni, Parsers::Zarts, Parsers::Facebook, Parsers::Ics].freeze
PARSERS = [Parsers::ManchesterUni, Parsers::Zarts, Parsers::Facebook, Parsers::Ics, Parsers::Eventbrite].freeze

def initialize(calendar, options={})
@calendar = calendar
@@ -15,6 +15,7 @@ def rrule
end

def sanitize_invalid_char(input)
input = I18n.transliterate(input)
input.encode('utf-8', :invalid => :replace, :undef => :replace, :replace => '')
end

@@ -85,7 +86,7 @@ def ip_class
end

def private?
ip_class&.casecmp('private')&.zero? || (@event.description&.include?('#placecal-ignore'))
ip_class&.casecmp('private')&.zero? || (description&.include?('#placecal-ignore'))
end
end
end
@@ -0,0 +1,62 @@
# frozen_string_literal: true

module Events
class EventbriteEvent < Base
def initialize(event)
@event = event
end

def uid
@event['id']
end

def summary
@event['name']['text']
end

def description
@event['description']['text']
end

def place
@place ||= @event['venue']
end

def location
return if place.blank?
address = place['address']

if address.present?
[ place['name'],
address['address_1'],
address['address_2'],
address['city'],
address['region'],
address['postal_code']
].reject(&:blank?).join(', ')
else
place['name']
end
end

def dtstart
DateTime.parse(@event['start']['local'])
rescue StandardError
nil
end

def dtend
DateTime.parse(@event['end']['local'])
rescue StandardError
nil
end

def occurrences_between(*)
#TODO: Expand when multi-day events supported
@occurrences = []
@occurrences << Dates.new(dtstart, dtend)
@occurrences
end

end
end
@@ -0,0 +1,37 @@
# frozen_string_literal: true

# In order for a parser to be recognized, it must be added
# to the PARSERS constant list in app/models/calendar_parser.rb.
# Parent parser classes should not be added.

module Parsers
class Eventbrite < Base
def self.whitelist_pattern
/https:\/\/www.eventbrite\.(com|co.uk)\/o\/[A-Za-z0-9-]+/
end

def organizer_id
path = URI.parse(@url).path
path.split('/').last.split('-').last
end

def download_calendar
EventbriteSDK.token = ENV['EVENTBRITE_TOKEN']

@events = []
results = EventbriteSDK::Organizer.retrieve(id: organizer_id).events.with_expansion(:venue).page(1)

loop do
@events += results
results = results.next_page
break if results.blank?
end

@events
end

def import_events_from(data)
data.map { |d| Events::EventbriteEvent.new(d) }
end
end
end
@@ -119,6 +119,10 @@ def to_s
# errors.add(:_, "Select at least one Tag") if tag_ids.blank?
# end

def should_generate_new_friendly_id?
slug.blank?
end

def permalink
"https://placecal.org/partners/#{id}"
end
@@ -1,4 +1,5 @@
<%= simple_form_for [:admin, @site] do |f| %>
<%= render_component "error", object: @site %>
<%= f.input :name %>
<%= f.input :place_name %>
<%= f.input :tagline %>

Large diffs are not rendered by default.

@@ -118,6 +118,22 @@ class CalendarParserTest < ActiveSupport::TestCase
end
end

test 'imports eventbrite calendars' do
calendar = create(:calendar, name: 'Eventbrite - BAVS',
source: 'https://www.eventbrite.co.uk/o/berwickshire-association-for-voluntary-service-15751503063')

VCR.use_cassette('Eventbrite calendar') do
output = CalendarParser.new(calendar).parse
events = output.events
first_event = events.first
last_event = events.last

assert_equal 41, events.count
assert_equal 'BAVS Forum: Supporting Positive Pathways – Action Research Event', first_event.summary
assert_equal 'Vision 4 Eyemouth', last_event.summary
end
end

test 'does not import if checksum is the same' do
calendar = create(:calendar, name: 'Z-Arts',
last_checksum: 'd1a94a9869af91d0548a1faf0ded91d7',

0 comments on commit 6e8651a

Please sign in to comment.
You can’t perform that action at this time.