Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
1532dc6
Add /users/:id/contacts_lists support to Chiketto::User
NullTerminator May 27, 2015
a7c8034
Add /users/:id/contact_lists/:contact_list_id support to Chiketto::User
NullTerminator May 27, 2015
2bfd424
Add POST /users/:id/contact_lists suppot to Chiketto::User
NullTerminator May 27, 2015
922f176
Extract contact list id to a constant
NullTerminator May 27, 2015
eb257ce
Add home and work phone access to AttendeeProfile
NullTerminator May 29, 2015
8398056
Introduce Contact object. ContactList can now retrive its Contacts
NullTerminator May 29, 2015
f299be6
Expose Event data of Attendee
NullTerminator May 29, 2015
51a494a
Add checked_in and costs to Attendee accessible data
NullTerminator Jun 3, 2015
a7fa517
Add ability to add and delete contacts to ContactList
NullTerminator Jun 4, 2015
5e36cb0
Add Webhook resource. Supports index, create and delete
NullTerminator Jun 9, 2015
808fae9
Order resource and find/show functionality
NullTerminator Jun 9, 2015
0e117a1
Allow Event.find to take params so expansion params can be provided
NullTerminator Jun 23, 2015
929be01
Allow .find to take params so expansions can be provided
NullTerminator Jun 25, 2015
449cacf
Instead of adding onto Hash, just build the query in Resource
NullTerminator Jul 22, 2015
02c3b5e
Allow access to if an attendee has cancelled
NullTerminator Jul 22, 2015
8186143
#events now loads all events. Provide #owned_events to get only owne…
NullTerminator Sep 15, 2015
53a278b
Force TLSv1.2 since EB is dropping support for 1.0 and 1.1 at the end of
m0dd3r Mar 20, 2018
31a6a41
Merge pull request #7 from batchblue/tlsv1_2
NullTerminator Mar 21, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/chiketto.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module Chiketto
ENDPOINT = 'https://www.eventbriteapi.com/v3/'

require 'hash_ext'

require 'chiketto/exception'
require 'chiketto/version'
require 'chiketto/attribute'
Expand All @@ -20,6 +18,10 @@ module Chiketto
require 'chiketto/ticket_class'
require 'chiketto/user'
require 'chiketto/venue'
require 'chiketto/contact_list'
require 'chiketto/contact'
require 'chiketto/webhook'
require 'chiketto/order'

class << self
attr_writer :api_key
Expand Down
9 changes: 8 additions & 1 deletion lib/chiketto/attendee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@ module Chiketto
class Attendee < Resource
attr_accessor :quantity,
:status,
:checked_in,
:costs,
:ticket_class_id,
:event_id,
:order_id,
:assigned_number,
:answers,
:barcodes
:barcodes,
:cancelled

attr_date :changed,
:created

def profile
AttendeeProfile.new @profile.to_h
end

def event
Event.new @event.to_h
end
end
end
2 changes: 2 additions & 0 deletions lib/chiketto/attendee_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class AttendeeProfile < Resource
:blog,
:gender,
:birth_date,
:home_phone,
:work_phone,
:cell_phone

def addresses
Expand Down
9 changes: 9 additions & 0 deletions lib/chiketto/contact.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Chiketto
class Contact < Resource
attr_reader :first_name,
:last_name,
:email

attr_date :created
end
end
32 changes: 32 additions & 0 deletions lib/chiketto/contact_list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Chiketto
class ContactList < Resource
attr_reader :name,
:user_id

def contacts
raise Exception.new("ContactList must have an id and user_id to get its Contacts") unless id && user_id

contacts = self.class.paginated(:contacts, id, { user_id: user_id })
contacts.map { |c| Contact.new c }
end

def add_contact(params)
raise Exception.new("ContactList must have an id and user_id to add a Contact") unless id && user_id
response = self.class.post("users/#{user_id}/contact_lists/#{id}/contacts", params)
response["created"]
end

def delete_contact(email)
raise Exception.new("ContactList must have an id and user_id to delete its Contacts") unless id && user_id
response = self.class.delete("users/#{user_id}/contact_lists/#{id}/contacts", { email: email })
response["deleted"]
end

private

def self.find_contacts(id, params)
user_id = params.delete(:user_id)
get "users/#{user_id}/contact_lists/#{id}/contacts", params
end
end
end
4 changes: 2 additions & 2 deletions lib/chiketto/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def self.create(params)
Event.new response
end

def self.find(id)
event = get "events/#{id}"
def self.find(id, params = {})
event = get "events/#{id}", params
Event.new event
end

Expand Down
27 changes: 27 additions & 0 deletions lib/chiketto/order.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Chiketto
class Order < Resource
attr_accessor :name,
:first_name,
:last_name,
:email,
:costs,
:status,
:event_id

attr_date :created,
:changed

def event
Event.new @event.to_h
end

def attendees
@attendees.map { |attendee| Attendee.new attendee }
end

def self.find(id, params = {})
order = get "orders/#{id}", params
Order.new order
end
end
end
45 changes: 34 additions & 11 deletions lib/chiketto/resource.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'json'
require 'open-uri'
require 'net/http'

module Chiketto
Expand All @@ -15,35 +14,59 @@ def initialize(args = {})
end

def self.get(uri, params = {})
uri = endpoint(uri) + query(params)
resource = open uri
JSON.parse resource.read
http_call(Net::HTTP::Get, uri, params)
end

def self.post(uri, params = {})
uri = URI.parse endpoint(uri) + query(params)
resource = open_post uri
JSON.parse resource
http_call(Net::HTTP::Post, uri, params)
end

def self.delete(uri, params = {})
http_call(Net::HTTP::Delete, uri, params)
end

def self.endpoint(uri)
ENDPOINT + uri + token
end

def self.open_post(uri)
def self.http_call(type, uri, params)
uri = URI.parse endpoint(uri) + query(params)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
http.ssl_version = :TLSv1_2
request = type.new(uri.request_uri)
request.add_field 'Authorization', "Bearer #{Chiketto.api_key}"
response = http.request(request)
if response.code !~ /20\d/
raise Chiketto::Exception, JSON.parse(response.body)
end
response.body
JSON.parse response.body
end

def self.query(params)
params.to_params
query_params = ''
stack = []

params.each do |k, v|
if v.is_a?(Hash)
stack << [k, v]
else
query_params << "#{k}=#{CGI::escape(v || "")}&"
end
end

stack.each do |parent, hash|
hash.each do |k, v|
if v.is_a?(Hash)
stack << ["#{parent}[#{k}]", v]
else
query_params << "#{parent}[#{k}]=#{CGI::escape(v || "")}&"
end
end
end

query_params.chop!
"&#{query_params}"
end

def self.token
Expand Down
28 changes: 28 additions & 0 deletions lib/chiketto/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ def events(params = {})
events.map { |e| Event.new e }
end

def owned_events(params ={})
events = User.paginated_owned_events @id, params
events.map { |e| Event.new e }
end

def event_attendees(params = {})
attendees = User.paginated_attendees @id, params
attendees.map { |e| Attendee.new e }
Expand All @@ -32,20 +37,43 @@ def organizers
organizers['organizers'].map { |o| Organizer.new o }
end

def contact_lists(params = {})
contact_lists = User.paginated(:contact_lists, @id, params)
contact_lists.map { |cl| ContactList.new cl }
end

def find_contact_list(contact_list_id)
contact_list = User.get "users/#{@id}/contact_lists/#{contact_list_id}"
ContactList.new contact_list
end

def create_contact_list(params)
response = User.post "users/#{@id}/contact_lists/", params
ContactList.new response
end

private

def self.find_attendees(id, params)
get "users/#{id}/owned_event_attendees", params
end

def self.find_events(id, params)
get "users/#{id}/events", params
end

def self.find_owned_events(id, params)
get "users/#{id}/owned_events", params
end

def self.find_organizers(id)
get "users/#{id}/organizers"
end

def self.find_contact_lists(id, params)
get "users/#{id}/contact_lists", params
end

def self.paginated_events(id, params)
paginated(:events, id, params)
end
Expand Down
31 changes: 31 additions & 0 deletions lib/chiketto/webhook.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Chiketto
class Webhook < Resource
attr_accessor :endpoint_url,
:actions,
:user_id,
:event_id

attr_date :created

def delete
response = Webhook.delete "webhooks/#{id}"
response["success"]
end

def self.all(params = {})
hooks = paginated(:webhooks, nil, params)
hooks.map { |wh| Webhook.new wh }
end

def self.create(params)
webhook = post 'webhooks', params
Webhook.new webhook
end

private

def self.find_webhooks(id, params)
get 'webhooks', params
end
end
end
27 changes: 0 additions & 27 deletions lib/hash_ext.rb

This file was deleted.

2 changes: 2 additions & 0 deletions test/attendee_profile_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def test_exposes_data
assert_respond_to attendee_profile, :blog
assert_respond_to attendee_profile, :gender
assert_respond_to attendee_profile, :birth_date
assert_respond_to attendee_profile, :home_phone
assert_respond_to attendee_profile, :work_phone
assert_respond_to attendee_profile, :cell_phone
assert_respond_to attendee_profile, :addresses
end
Expand Down
8 changes: 8 additions & 0 deletions test/attendee_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ def test_exposes_data
assert_respond_to attendee, :ticket_class_id
assert_respond_to attendee, :quantity
assert_respond_to attendee, :status
assert_respond_to attendee, :checked_in
assert_respond_to attendee, :costs
assert_respond_to attendee, :profile
assert_respond_to attendee, :event_id
assert_respond_to attendee, :order_id
assert_respond_to attendee, :assigned_number
assert_respond_to attendee, :answers
assert_respond_to attendee, :barcodes
assert_respond_to attendee, :cancelled
end

def test_attr_date_types
Expand All @@ -26,6 +29,11 @@ def test_attendee_returns_profile
assert_kind_of Chiketto::AttendeeProfile, attendee.profile
end

def test_attendee_returns_event
attendee = Chiketto::Attendee.new
assert_kind_of Chiketto::Event, attendee.event
end

def test_assigned_number_is_handled
attendee = Chiketto::Attendee.new assigned_number: 1
assert_equal attendee.assigned_number, 1
Expand Down
Loading