Class: EventbriteRuby::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/eventbrite_ruby/Client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(personal_key: nil) ⇒ Client

Returns a new instance of Client.



5
6
7
# File 'lib/eventbrite_ruby/Client.rb', line 5

def initialize(personal_key: nil)
  @personal_key = personal_key || EventbriteRuby.personal_key
end

Instance Attribute Details

#personal_keyObject

Returns the value of attribute personal_key.



3
4
5
# File 'lib/eventbrite_ruby/Client.rb', line 3

def personal_key
  @personal_key
end

Instance Method Details

#connectionObject



9
10
11
12
13
14
15
16
17
# 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 = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# 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 = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# 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