class EventbriteRuby::Client

Attributes

personal_key[RW]

Public Class Methods

new(personal_key: nil) click to toggle source
# File lib/eventbrite_ruby/Client.rb, line 5
def initialize(personal_key: nil)
  @personal_key = personal_key || EventbriteRuby.personal_key
end

Public Instance Methods

connection() click to toggle source
# File lib/eventbrite_ruby/Client.rb, line 9
def connection
  @connection ||= begin
    Faraday.new(:url => 'https://www.eventbriteapi.com/') do |faraday|
      faraday.authorization :Bearer, @personal_key
      faraday.response :json, :content_type => /\bjson$/
      faraday.adapter  Faraday.default_adapter  # make requests with Net::HTTP
    end
  end
end
get(url, data = {}) click to toggle source
# File lib/eventbrite_ruby/Client.rb, line 31
def get(url, data = {})
  if data[:continuation].present?
    url = "#{url}?continuation=#{data[:continuation]}"
    data.delete(:continuation)
  end
  connection.get do |req|
    req.url url
    req.headers['Content-Type'] = 'application/json'
    req.body = data.to_json
  end
end
post(url, data = {}) click to toggle source
# File lib/eventbrite_ruby/Client.rb, line 19
def post(url, data = {})
  if data[:continuation].present?
    url = "#{url}?continuation=#{data[:continuation]}"
    data.delete(:continuation)
  end
  connection.post do |req|
    req.url url
    req.headers['Content-Type'] = 'application/json'
    req.body = data.to_json
  end
end