Skip to content

Commit

Permalink
Initial Booset integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Mlodgenski committed Jan 29, 2019
1 parent dc28c07 commit 1e1ef1a
Show file tree
Hide file tree
Showing 23 changed files with 604 additions and 11 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ gem 'icalendar'
gem 'humanize'

#for REST calls to external sources
gem 'zapier_ruby'
gem 'rest-client'

#To make SOAP calls to the PayU API
Expand Down
24 changes: 16 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ GEM
actionmailer (>= 3.2)
letter_opener (~> 1.0)
railties (>= 3.2)
libv8 (6.7.288.46.1)
libv8 (6.7.288.46.1-x86_64-linux)
listen (2.7.2)
celluloid (>= 0.15.2)
celluloid-io (>= 0.15.0)
Expand All @@ -374,6 +376,8 @@ GEM
mini_magick (4.5.1)
mini_mime (1.0.1)
mini_portile2 (2.3.0)
mini_racer (0.2.4)
libv8 (>= 6.3)
minitest (5.11.3)
momentjs-rails (2.8.1)
railties (>= 3.1)
Expand Down Expand Up @@ -579,10 +583,10 @@ GEM
responders (2.4.0)
actionpack (>= 4.2.0, < 5.3)
railties (>= 4.2.0, < 5.3)
rest-client (1.8.0)
rest-client (2.0.2)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rolify (5.0.0)
routing-filter (0.6.1)
actionpack (>= 4.2, < 5.2)
Expand Down Expand Up @@ -666,12 +670,12 @@ GEM
activesupport (>= 4.0)
sprockets (>= 3.0.0)
stringex (2.5.2)
stripe (1.43.0)
rest-client (~> 1.4)
stripe-ruby-mock (2.3.0)
stripe (2.12.0)
faraday (~> 0.9)
stripe-ruby-mock (2.5.6)
dante (>= 0.2.0)
multi_json (>= 1.0.0)
stripe (>= 1.31.0, <= 1.43)
multi_json (~> 1.0)
stripe (>= 2.0.3)
survey (0.2)
rails (>= 3.2.6, < 5)
railties (>= 3.2.6, < 5)
Expand Down Expand Up @@ -723,6 +727,8 @@ GEM
xpath (2.0.0)
nokogiri (~> 1.3)
yajl-ruby (1.4.1)
zapier_ruby (0.1.1)
rest-client
zilch-authorisation (0.0.1)

PLATFORMS
Expand Down Expand Up @@ -789,6 +795,7 @@ DEPENDENCIES
lolsoap (~> 0.9.0)
mina
mini_magick
mini_racer
money-rails
omniauth
omniauth-facebook
Expand Down Expand Up @@ -856,6 +863,7 @@ DEPENDENCIES
whenever
will_paginate-bootstrap
yajl-ruby (~> 1.2, >= 1.2.1)
zapier_ruby

BUNDLED WITH
1.17.1
49 changes: 49 additions & 0 deletions app/classes/attendee.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
class Attendee
require 'json'

attr_accessor :type
attr_accessor :data

class Data < Attendee
attr_accessor :id
attr_accessor :type
attr_accessor :event
attr_accessor :registrant

class Type < Data
attr_accessor :id
attr_accessor :name
end

class Event < Data
attr_accessor :url
attr_accessor :name
end

class Registrant < Data
attr_accessor :first_name
attr_accessor :last_name
attr_accessor :job_title
attr_accessor :company
attr_accessor :phone
attr_accessor :email
attr_accessor :address

class Address < Registrant
attr_accessor :street_address
attr_accessor :extended_address
attr_accessor :locality
attr_accessor :region
attr_accessor :postal_code
attr_accessor :country
end

class Ticket < Registrant
attr_accessor :ticket_type
attr_accessor :paid
attr_accessor :cost
attr_accessor :token
end
end
end
end
62 changes: 62 additions & 0 deletions app/classes/boomset.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
class Boomset
require 'rest-client'
require 'json'

def self.get_attendee_request(token, event_id)
ret = {}
auth = "Token " + token
content_type = "application/json"

url = "https://api.boomset.com/events/" + event_id.to_s + "/registration_types/"

response = RestClient.get url, {content_type: content_type, authorization: auth}

if response.code == 200
json = JSON.parse response.body
json["results"].each do |result|
ret[result["name"]] = result["id"]
end
end

ret

rescue RestClient::Exception
ret
end

def self.add_guest(token, event_id, guest)
auth = "Token " + token
content_type = "application/json"

url = "https://api.boomset.com/events/" + event_id.to_s + "/guests"

response = RestClient.post url, guest, {content_type: content_type, authorization: auth}

if response.code == 201
json = JSON.parse response.body
json["id"]
end

rescue RestClient::Exception
-1
end

def self.update_guest(token, event_id, guest_id, guest)
auth = "Token " + token
content_type = "application/json"

url = "https://api.boomset.com/events/" + event_id.to_s + "/guests/" + guest_id.to_s

RestClient.put url, guest, {content_type: content_type, authorization: auth}

if response.code == 200
json = JSON.parse response.body
json["id"]
end

rescue RestClient::BadRequest => e
puts e.response
-1
end

end
20 changes: 20 additions & 0 deletions app/classes/boomset_attendee.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class BoomsetAttendee
require 'json'

attr_accessor :registration_type
attr_accessor :first_name
attr_accessor :last_name
attr_accessor :email
attr_accessor :prefix
attr_accessor :suffix
attr_accessor :phone
attr_accessor :cell_phone
attr_accessor :company
attr_accessor :job_title
attr_accessor :work_phone
attr_accessor :blog
attr_accessor :website
attr_accessor :barcode
attr_accessor :nfc_tag

end
61 changes: 61 additions & 0 deletions app/controllers/admin/boomset_ticket_configs_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
module Admin
class BoomsetTicketConfigsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :boomset_ticket_config, through: :conference

def index
end

def new
@boomset_ticket_config = @conference.boomset_ticket_configs.new
@integration = BoomsetTicketConfig.get_boomset_integration(@conference)
@reg_types = BoomsetTicketConfig.get_registration_types(@integration)
end

def create
@boomset_ticket_config = @conference.boomset_ticket_configs.new(boomset_ticket_config_params)
@integration = BoomsetTicketConfig.get_boomset_integration(@conference)
@boomset_ticket_config.integration = @integration

if @boomset_ticket_config.save
redirect_to admin_conference_boomset_ticket_configs_path(conference_id: @conference.short_title),
notice: 'Boomset ticket successfully created.'
else
flash[:error] = "Creating Boomset ticket failed: #{@integration.errors.full_messages.join('. ')}."
render :new
end
end

def edit
@integration = BoomsetTicketConfig.get_boomset_integration(@conference)
@reg_types = BoomsetTicketConfig.get_registration_types(@integration)
end

def update
if @boomset_ticket_config.update_attributes(boomset_ticket_config_params)
redirect_to admin_conference_boomset_ticket_configs_path(conference_id: @conference.short_title),
notice: 'Boomset ticket successfully updated.'
else
flash[:error] = "Update Boomset ticket failed: #{@boomset_ticket_config.errors.full_messages.join('. ')}."
render :edit
end
end

def destroy
if @boomset_ticket_config.destroy
redirect_to admin_conference_boomset_ticket_configs_path(conference_id: @conference.short_title),
notice: 'Boomset ticket successfully deleted.'
else
redirect_to admin_conference_boomset_ticket_configs_path(conference_id: @conference.short_title),
error: 'Deleting Boomset ticket failed.' \
"#{@boomset_ticket_config.errors.full_messages.join('. ')}."
end
end

private

def boomset_ticket_config_params
params.require(:boomset_ticket_config).permit(:boomset_registration_type, :ticket_id, :integration_id, :conference_id)
end
end
end
53 changes: 53 additions & 0 deletions app/controllers/admin/integrations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module Admin
class IntegrationsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :integration, through: :conference

def index
end

def new
@integration = @conference.integrations.new
end

def create
@integration = @conference.integrations.new(integration_params)
if @integration.save
redirect_to admin_conference_integrations_path(conference_id: @conference.short_title),
notice: 'Integration successfully created.'
else
flash[:error] = "Creating Integration failed: #{@integration.errors.full_messages.join('. ')}."
render :new
end
end

def edit; end

def update
if @integration.update_attributes(integration_params)
redirect_to admin_conference_integrations_path(conference_id: @conference.short_title),
notice: 'Integration successfully updated.'
else
flash[:error] = "Update Integration failed: #{@integration.errors.full_messages.join('. ')}."
render :edit
end
end

def destroy
if @integration.destroy
redirect_to admin_conference_integrations_path(conference_id: @conference.short_title),
notice: 'Integration successfully deleted.'
else
redirect_to admin_conference_integrations_path(conference_id: @conference.short_title),
error: 'Deleting integration failed.' \
"#{@integration.errors.full_messages.join('. ')}."
end
end

private

def integration_params
params.require(:integration).permit(:integration_type, :key, :url, :integration_config_key, :conference_id)
end
end
end
47 changes: 47 additions & 0 deletions app/jobs/boomset_attendee_register_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
class BoomsetAttendeeRegisterJob < ActiveJob::Base
require 'rest-client'
require 'json'

def self.perform(registration)
guest = BoomsetGuest.get_guest(registration)

integration = BoomsetTicketConfig.get_boomset_integration(registration.conference)
if integration.integration_type == "boomset"
guest_exists = false

boomset_guest = BoomsetGuest.where(conference_id: registration.conference.id, token: guest.barcode).first
if boomset_guest.blank?
boomset_guest = BoomsetGuest.where(conference_id: registration.conference.id, registration_id: registration.id).first
if boomset_guest.present?
guest_exists = true
end
else
guest_exists = true
end

if guest_exists
id = Boomset.update_guest(integration.key, integration.integration_config_key, boomset_guest.boomset_guest, guest.to_json)
if id > 0
boomset_guest.registration_id = registration.id
boomset_guest.boomset_guest = id
boomset_guest.update
end
else
id = Boomset.add_guest(integration.key, integration.integration_config_key, guest.to_json)
if id > 0
token = guest.barcode
bg = BoomsetGuest.new
bg.conference_id = registration.conference.id
bg.registration_id = registration.id
bg.integration_id = integration.id
bg.boomset_guest = id
bg.token = token
bg.save
end
end
end


end

end
Loading

0 comments on commit 1e1ef1a

Please sign in to comment.