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



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

#passwordObject

Returns the value of attribute password.



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

def password
  @password
end

#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



27
28
29
30
31
32
33
# File 'lib/eventbrite_ruby/Client.rb', line 27

def get(url, data)
  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
# File 'lib/eventbrite_ruby/Client.rb', line 19

def post(url, data)
  connection.post do |req|
    req.url url
    req.headers['Content-Type'] = 'application/json'
    req.body = data.to_json
  end
end