Class: EventbriteContacts::Client
- Inherits:
-
Object
- Object
- EventbriteContacts::Client
- Defined in:
- lib/eventbrite_contacts.rb,
lib/eventbrite_contacts/version.rb
Constant Summary collapse
- BASE_URL =
"https://www.eventbriteapi.com/v3/"
- VERSION =
"0.2.1"
Instance Method Summary collapse
- #add_contact(list_id, contact) ⇒ Object
- #add_list(list_name) ⇒ Object
- #add_webhook(event_id, endpoint_url) ⇒ Object
- #delete_contact(list_id, contact_email) ⇒ Object
- #delete_list(list_id) ⇒ Object
- #delete_webhook(webhook_id) ⇒ Object
- #get_all_contacts(list_id) ⇒ Object
- #get_contacts(list_id, options = {}) ⇒ Object
- #get_events(organizer_id, options = {}) ⇒ Object
- #get_list(list_id) ⇒ Object
- #get_lists(options = {}) ⇒ Object
- #get_order(order_id) ⇒ Object
- #get_organizers(user_id, options = {}) ⇒ Object
- #get_webhooks(options = {}) ⇒ Object
-
#initialize(auth_token, user_id) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(auth_token, user_id) ⇒ Client
Returns a new instance of Client.
10 11 12 13 |
# File 'lib/eventbrite_contacts.rb', line 10 def initialize(auth_token, user_id) @auth_token = auth_token @user_id = user_id end |
Instance Method Details
#add_contact(list_id, contact) ⇒ Object
67 68 69 70 71 72 73 |
# 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) ⇒ Object
30 31 32 33 34 35 |
# 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) ⇒ Object
106 107 108 109 110 111 |
# 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) ⇒ Object
75 76 77 78 79 80 |
# 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) ⇒ Object
37 38 39 40 41 42 |
# 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) ⇒ Object
113 114 115 116 117 118 |
# 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) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# 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 = {}) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/eventbrite_contacts.rb', line 59 def get_contacts(list_id, ={}) url = "#{BASE_URL}users/#{@user_id}/contact_lists/#{list_id}/contacts?" page = if [:page].nil? then 1 else [:page] end encoded = URI.encode("#{url}page=#{page}") response = make_request(encoded, "get") raise_limit_error(response) end |
#get_events(organizer_id, options = {}) ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/eventbrite_contacts.rb', line 90 def get_events(organizer_id, = {}) url = "#{BASE_URL}events/search?" page = [:page].nil? ? 1 : [: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) ⇒ Object
23 24 25 26 27 28 |
# 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 = {}) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/eventbrite_contacts.rb', line 15 def get_lists(={}) url = "#{BASE_URL}users/#{@user_id}/contact_lists/?" page = if [:page].nil? then 1 else [:page] end encoded = URI.encode("#{url}page=#{page}") response = make_request(encoded, "get") raise_limit_error(response) end |
#get_order(order_id) ⇒ Object
120 121 122 123 124 125 |
# 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 = {}) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/eventbrite_contacts.rb', line 82 def get_organizers(user_id, = {}) url = "#{BASE_URL}users/#{user_id}/organizers/?" page = [:page].nil? ? 1 : [:page] encoded = URI.encode("#{url}page=#{page}") response = make_request(encoded, 'get') raise_limit_error(response) end |
#get_webhooks(options = {}) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/eventbrite_contacts.rb', line 98 def get_webhooks( = {}) url = "#{BASE_URL}webhooks/?" page = [:page].nil? ? 1 : [:page] encoded = URI.encode("#{url}page=#{page}") response = make_request(encoded, 'get') raise_limit_error(response) end |