Skip to content

Instantly share code, notes, and snippets.

@damienh
Last active August 29, 2015 14:22
Show Gist options
  • Save damienh/16d249c5ea686abb21ae to your computer and use it in GitHub Desktop.
Save damienh/16d249c5ea686abb21ae to your computer and use it in GitHub Desktop.
EB v3 params
def event_params
event_params = ({:event => {
:name => {
:html => event.name # this will be a string e.g "Public Event with Damien Hogan"
},
:description => {
:html => event.description # this will be a string e.g "This event is going to cover the following modules..."
},
:organizer_id => ORGANIZER_ID, # ENV variable stored in a Constant.
:start => {
:timezone => "Europe/London",
:utc => set_time(event.start_date) # This is worked out by the set_time method below
},
:end => {
:timezone => "Europe/London",
:utc => set_time(event.end_date)
},
:venue_id => venue_id, # returned from a venue lookup call
:currency => "GBP",
:capacity => event.capacity, # A string e.g. 10
:listed => privacy } # a method we have to set either true or false
}.to_json)
end
def set_time(time)
if time.dst? == true
formatted_time = time.getutc - 1.hour
end
return formatted_time.iso8601
end
# here we have to types of tickets. This is to use the ticket_class. We want the primary ticket to be sold first and then
# the secondary ticket to go on sale. This works fine.
def primary_ticket_params ticket
ticket_params = ({:ticket_class => {
:name => ticket.ticket_type.name, # string e.g. Public Host Teacher Ticket
:description => ticket.ticket_type.description, # string e.g. Public Host Teacher Ticket
:quantity_total => ticket.quantity, # String e.g. 12
:free => free_ticket(ticket), # worked out by method below
:cost => {
:currency => "GBP", # currency as expected
:value => ticket.price.to_i * 100 # converts our price in DB to pence.
},
:include_fee => absorb_cost(ticket), # worked out from method below
:sales_start => "",
:sales_end => set_time(event.end_date),
:minimum_quantity => "1",
:maximum_quantity => ticket.quantity } # string e.g. 12
}.to_json)
end
# same data structure as the above ticket just different values.
def secondary_ticket_params ticket
ticket_params = ({:ticket_class => {
:name => ticket.ticket_type.name,
:description => ticket.ticket_type.description,
:quantity_total => ticket.quantity,
:free => free_ticket(ticket),
:cost => {
:currency => "GBP",
:value => ticket.price.to_i * 100
},
:include_fee => absorb_cost(ticket),
:sales_start => "",
:sales_end => set_time(event.end_date),
:sales_start_after => returned_ticket_class['id'], # this is returned after the first ticket is created and passed into this call.
:minimum_quantity => "1",
:maximum_quantity => ticket.quantity }
}.to_json)
end
def venue_params
venue_params = ({:venue => {
:name => event.venue, # string e.g. The Main Hall
:address => {
:address_1 => event.address, # string again like 57 Selwood Road
:address_2 => "",
:city => event.city, # String e.g Greater Manchester
:postal_code => event.postal_code, # string M16 0EX
:country => "GB" # GB as requested in your docs. I tried ENG but it fails.
}}
}.to_json)
end
def free_ticket(ticket)
if ticket.price.to_i == 0
return true
else
return false
end
end
def absorb_cost(ticket)
if ticket.price.to_i == 0
return false
else
return true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment