Skip to content

Commit

Permalink
Merge pull request #514 from geeksforsocialchange/master
Browse files Browse the repository at this point in the history
Merge Eventbrite support
  • Loading branch information
kimadactyl committed Feb 13, 2020
2 parents 767b9f5 + 8b030f5 commit 6e8651a
Show file tree
Hide file tree
Showing 10 changed files with 2,079 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ gem 'webpacker'
gem 'httparty' gem 'httparty'
gem 'icalendar' gem 'icalendar'
gem 'icalendar-recurrence' gem 'icalendar-recurrence'
gem 'eventbrite_sdk'


# Uploads # Uploads
gem 'carrierwave' gem 'carrierwave'
Expand Down
17 changes: 17 additions & 0 deletions Gemfile.lock
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ GEM
actionmailer (>= 5.0) actionmailer (>= 5.0)
devise (>= 4.6) devise (>= 4.6)
docile (1.3.2) docile (1.3.2)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.7.5) dotenv (2.7.5)
dotenv-rails (2.7.5) dotenv-rails (2.7.5)
dotenv (= 2.7.5) dotenv (= 2.7.5)
Expand Down Expand Up @@ -177,6 +179,8 @@ GEM
activesupport (>= 3.2) activesupport (>= 3.2)
equalizer (0.0.11) equalizer (0.0.11)
erubi (1.9.0) erubi (1.9.0)
eventbrite_sdk (3.4.0)
rest-client (~> 2.0)
eventmachine (1.2.7) eventmachine (1.2.7)
execjs (2.7.0) execjs (2.7.0)
factory_bot (5.1.1) factory_bot (5.1.1)
Expand Down Expand Up @@ -233,6 +237,9 @@ GEM
minitest (>= 3.0) minitest (>= 3.0)
hashdiff (1.0.0) hashdiff (1.0.0)
hashie (3.6.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) http_parser.rb (0.6.0)
httparty (0.17.3) httparty (0.17.3)
mime-types (~> 3.0) mime-types (~> 3.0)
Expand Down Expand Up @@ -313,6 +320,7 @@ GEM
mustermann-grape (1.0.1) mustermann-grape (1.0.1)
mustermann (>= 1.0.0) mustermann (>= 1.0.0)
nenv (0.3.0) nenv (0.3.0)
netrc (0.11.0)
nio4r (2.5.2) nio4r (2.5.2)
nokogiri (1.10.7) nokogiri (1.10.7)
mini_portile2 (~> 2.4.0) mini_portile2 (~> 2.4.0)
Expand Down Expand Up @@ -408,6 +416,11 @@ GEM
responders (3.0.0) responders (3.0.0)
actionpack (>= 5.0) actionpack (>= 5.0)
railties (>= 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) rollbar (2.23.2)
rubocop (0.79.0) rubocop (0.79.0)
jaro_winkler (~> 1.5.1) jaro_winkler (~> 1.5.1)
Expand Down Expand Up @@ -478,6 +491,9 @@ GEM
thread_safe (~> 0.1) thread_safe (~> 0.1)
uglifier (4.2.0) uglifier (4.2.0)
execjs (>= 0.3.0, < 3) execjs (>= 0.3.0, < 3)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.6)
unicode-display_width (1.6.1) unicode-display_width (1.6.1)
vcr (5.0.0) vcr (5.0.0)
virtus (1.0.5) virtus (1.0.5)
Expand Down Expand Up @@ -530,6 +546,7 @@ DEPENDENCIES
devise_invitable devise_invitable
dotenv-rails dotenv-rails
enumerize enumerize
eventbrite_sdk
factory_bot_rails factory_bot_rails
font-awesome-rails font-awesome-rails
friendly_id (~> 5.3.0) friendly_id (~> 5.3.0)
Expand Down
2 changes: 1 addition & 1 deletion app/models/calendar_parser.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class CalendarParser
class UnsupportedFeed < StandardError; end class UnsupportedFeed < StandardError; end
class InaccessibleFeed < 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={}) def initialize(calendar, options={})
@calendar = calendar @calendar = calendar
Expand Down
3 changes: 2 additions & 1 deletion app/models/events/base.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def rrule
end end


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


Expand Down Expand Up @@ -85,7 +86,7 @@ def ip_class
end end


def private? def private?
ip_class&.casecmp('private')&.zero? || (@event.description&.include?('#placecal-ignore')) ip_class&.casecmp('private')&.zero? || (description&.include?('#placecal-ignore'))
end end
end end
end end
62 changes: 62 additions & 0 deletions app/models/events/eventbrite_event.rb
Original file line number Original file line Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions app/models/parsers/eventbrite.rb
Original file line number Original file line Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions app/models/partner.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ def to_s
# errors.add(:_, "Select at least one Tag") if tag_ids.blank? # errors.add(:_, "Select at least one Tag") if tag_ids.blank?
# end # end


def should_generate_new_friendly_id?
slug.blank?
end

def permalink def permalink
"https://placecal.org/partners/#{id}" "https://placecal.org/partners/#{id}"
end end
Expand Down
1 change: 1 addition & 0 deletions app/views/admin/sites/_form.html.erb
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,5 @@
<%= simple_form_for [:admin, @site] do |f| %> <%= simple_form_for [:admin, @site] do |f| %>
<%= render_component "error", object: @site %>
<%= f.input :name %> <%= f.input :name %>
<%= f.input :place_name %> <%= f.input :place_name %>
<%= f.input :tagline %> <%= f.input :tagline %>
Expand Down
1,938 changes: 1,938 additions & 0 deletions test/fixtures/vcr_cassettes/Eventbrite_calendar.yml

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions test/models/calendar_parser_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ class CalendarParserTest < ActiveSupport::TestCase
end end
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 test 'does not import if checksum is the same' do
calendar = create(:calendar, name: 'Z-Arts', calendar = create(:calendar, name: 'Z-Arts',
last_checksum: 'd1a94a9869af91d0548a1faf0ded91d7', last_checksum: 'd1a94a9869af91d0548a1faf0ded91d7',
Expand Down

0 comments on commit 6e8651a

Please sign in to comment.