Module: Eventbrite

Defined in:
lib/eventbrite.rb,
lib/eventbrite/util.rb,
lib/eventbrite/version.rb,
lib/eventbrite/api_resource.rb,
lib/eventbrite/resources/team.rb,
lib/eventbrite/resources/user.rb,
lib/eventbrite/resources/event.rb,
lib/eventbrite/resources/order.rb,
lib/eventbrite/resources/venue.rb,
lib/eventbrite/errors/api_error.rb,
lib/eventbrite/resources/format.rb,
lib/eventbrite/eventbrite_object.rb,
lib/eventbrite/resources/webhook.rb,
lib/eventbrite/api_array_resource.rb,
lib/eventbrite/resources/attendee.rb,
lib/eventbrite/resources/category.rb,
lib/eventbrite/resources/discount.rb,
lib/eventbrite/resources/transfer.rb,
lib/eventbrite/resources/organizer.rb,
lib/eventbrite/resources/access_code.rb,
lib/eventbrite/resources/subcategory.rb,
lib/eventbrite/resources/contact_list.rb,
lib/eventbrite/resources/ticket_class.rb,
lib/eventbrite/errors/eventbrite_error.rb,
lib/eventbrite/errors/authentication_error.rb,
lib/eventbrite/errors/invalid_request_error.rb

Defined Under Namespace

Modules: Util Classes: APIArrayResource, APIError, APIResource, AccessCode, Attendee, AuthenticationError, Category, ContactList, Discount, Event, EventbriteError, EventbriteObject, Format, InvalidRequestError, Order, Organizer, Subcategory, Team, TicketClass, Transfer, User, Venue, Webhook

Constant Summary collapse

DEFAULTS =
{
  api_base: 'https://www.eventbriteapi.com',
  api_version: 'v3'
}
VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.api_url(url = '') ⇒ Object



55
56
57
# File 'lib/eventbrite.rb', line 55

def self.api_url(url='')
  "#{api_base}/#{api_version}#{url}"
end

.request(method, url, token, params = {}) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/eventbrite.rb', line 59

def self.request(method, url, token, params={})
  unless token ||= self.token
    raise AuthenticationError.new('No access token provided. Set your token using "Eventbrite.token = <access-token>"."')
  end

  url = api_url(url)

  case method.to_s.downcase.to_sym
  when :get
    # Make params into GET parameters
    url += "#{URI.parse(url).query ? '&' : '?'}#{uri_encode(params)}" if params && params.any?
    payload = nil
  else
    payload = uri_encode(params)
  end

  request_opts = {
    headers: request_headers(token),
    method: method,
    open_timeout: 30,
    payload: payload,
    url: url,
    timeout: 120
  }

  begin
    response = execute_request(request_opts)
  rescue RestClient::ExceptionWithResponse => e
    if rcode = e.http_code and rbody = e.http_body
      handle_api_error(rcode, rbody)
    else
      raise
    end
  end

  [parse(response), token]
end