class EventbriteContacts::Client
Constants
- BASE_URL
- VERSION
Public Class Methods
new(auth_token, user_id)
click to toggle source
# File lib/eventbrite_contacts.rb, line 10 def initialize(auth_token, user_id) @auth_token = auth_token @user_id = user_id end
Public Instance Methods
add_contact(list_id, contact)
click to toggle source
# File lib/eventbrite_contacts.rb, line 67 def add_contact(list_id, contact) url = "#{BASE_URL}users/#{@user_id}/contact_lists/#{list_id}/contacts/?" param_url = "contact.email=#{contact[:email]}&contact.first_name=#{contact[:first_name]}&contact.last_name=#{contact[:last_name]}" encoded = URI.encode("#{url}#{param_url}") response = make_request(encoded, "post") raise_limit_error(response) end
add_list(list_name)
click to toggle source
# File lib/eventbrite_contacts.rb, line 30 def add_list(list_name) url = "#{BASE_URL}users/#{@user_id}/contact_lists/?" encoded = URI.encode("#{url}contact_list.name=#{list_name}") response = make_request(encoded, "post") raise_limit_error(response) end
add_webhook(event_id, endpoint_url)
click to toggle source
# File lib/eventbrite_contacts.rb, line 106 def add_webhook(event_id, endpoint_url) url = "#{BASE_URL}webhooks/?" encoded = URI.encode("#{url}endpoint_url=#{endpoint_url}&event_id=#{event_id}&actions=order.placed") response = make_request(encoded, 'post') raise_limit_error(response) end
delete_contact(list_id, contact_email)
click to toggle source
# File lib/eventbrite_contacts.rb, line 75 def delete_contact(list_id, contact_email) url = "#{BASE_URL}users/#{@user_id}/contact_lists/#{list_id}/contacts/?" encoded = URI.encode("#{url}email=#{contact_email}") response = make_request(encoded, "delete") raise_limit_error(response) end
delete_list(list_id)
click to toggle source
# File lib/eventbrite_contacts.rb, line 37 def delete_list(list_id) url = "#{BASE_URL}users/#{@user_id}/contact_lists/#{list_id}" encoded = URI.encode(url) response = make_request(encoded, "delete") raise_limit_error(response) end
delete_webhook(webhook_id)
click to toggle source
# File lib/eventbrite_contacts.rb, line 113 def delete_webhook(webhook_id) url = "#{BASE_URL}webhooks/#{webhook_id}" encoded = URI.encode("#{url}") response = make_request(encoded, 'delete') raise_limit_error(response) end
get_all_contacts(list_id)
click to toggle source
# File lib/eventbrite_contacts.rb, line 44 def get_all_contacts(list_id) url = "#{BASE_URL}users/#{@user_id}/contact_lists/#{list_id}/contacts" page = 1 contacts = [] loop do encoded = URI.encode("#{url}?page=#{page}") response = make_request(encoded, "get") raise_limit_error(response) contacts << response["contacts"] unless response["contacts"].nil? page += 1 break if response["error"] == "BAD_PAGE" end contacts.flatten end
get_contacts(list_id, options={})
click to toggle source
# File lib/eventbrite_contacts.rb, line 59 def get_contacts(list_id, options={}) url = "#{BASE_URL}users/#{@user_id}/contact_lists/#{list_id}/contacts?" page = if options[:page].nil? then 1 else options[:page] end encoded = URI.encode("#{url}page=#{page}") response = make_request(encoded, "get") raise_limit_error(response) end
get_events(organizer_id, options = {})
click to toggle source
# File lib/eventbrite_contacts.rb, line 90 def get_events(organizer_id, options = {}) url = "#{BASE_URL}events/search?" page = options[:page].nil? ? 1 : options[:page] encoded = URI.encode("#{url}organizer.id=#{organizer_id}&page=#{page}") response = make_request(encoded, 'get') raise_limit_error(response) end
get_list(list_id)
click to toggle source
# File lib/eventbrite_contacts.rb, line 23 def get_list(list_id) url = "#{BASE_URL}users/#{@user_id}/contact_lists/#{list_id}" encoded = URI.encode(url) response = make_request(encoded, "get") raise_limit_error(response) end
get_lists(options={})
click to toggle source
# File lib/eventbrite_contacts.rb, line 15 def get_lists(options={}) url = "#{BASE_URL}users/#{@user_id}/contact_lists/?" page = if options[:page].nil? then 1 else options[:page] end encoded = URI.encode("#{url}page=#{page}") response = make_request(encoded, "get") raise_limit_error(response) end
get_order(order_id)
click to toggle source
# File lib/eventbrite_contacts.rb, line 120 def get_order(order_id) url = "#{BASE_URL}orders/#{order_id}" encoded = URI.encode("#{url}") response = make_request(encoded, 'get') raise_limit_error(response) end
get_organizers(user_id, options = {})
click to toggle source
# File lib/eventbrite_contacts.rb, line 82 def get_organizers(user_id, options = {}) url = "#{BASE_URL}users/#{user_id}/organizers/?" page = options[:page].nil? ? 1 : options[:page] encoded = URI.encode("#{url}page=#{page}") response = make_request(encoded, 'get') raise_limit_error(response) end
get_webhooks(options = {})
click to toggle source
# File lib/eventbrite_contacts.rb, line 98 def get_webhooks(options = {}) url = "#{BASE_URL}webhooks/?" page = options[:page].nil? ? 1 : options[:page] encoded = URI.encode("#{url}page=#{page}") response = make_request(encoded, 'get') raise_limit_error(response) end
Private Instance Methods
make_request(url, verb)
click to toggle source
# File lib/eventbrite_contacts.rb, line 129 def make_request(url, verb) case verb when "get" HTTParty.get(url, :headers => { "Authorization" => "Bearer #{@auth_token}" }) when "post" HTTParty.post(url, :headers => { "Authorization" => "Bearer #{@auth_token}" }) when "delete" HTTParty.delete(url, :headers => { "Authorization" => "Bearer #{@auth_token}" }) end end
raise_limit_error(response)
click to toggle source
# File lib/eventbrite_contacts.rb, line 140 def raise_limit_error(response) if response["error"] == "HIT_RATE_LIMIT" raise RateLimitExceeded, "rate_limit_exceeded" else response end end