Class: EventbriteClient::API

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

Overview

Makes RESTful API calls

Instance Method Summary collapse

Constructor Details

#initialize(auth_tokens) ⇒ API

Setup a session with the specified API keys

Parameters:

  • auth_tokens (Hash{String=>String})

    Eventbrite API keys

Options Hash (auth_tokens):

  • :app_key (String)

    Application key

  • :user_key (String)

    Optional user key



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/EventbriteClient.rb', line 15

def initialize( auth_tokens )
  @base_url = "https://www.eventbrite.com"
  @auth = {:app_key => "IT7XL4RVM2CGSGTVLX"}
  @data_type = "json"

  if auth_tokens != nil and auth_tokens.is_a? Hash
    if auth_tokens.include? :app_key
    #use api_key OR api_key + user_key OR api_key+email+pass
    if auth_tokens.include? :user_key
      # read/write access on the user account associated with :user_key
      @auth = {:app_key => auth_tokens[:app_key], :user_key => auth_tokens[:user_key]}
    else
      # read-only access to public data
      @auth = {:app_key => auth_tokens[:app_key]}
    end 
  end                                                                                        end
end

Instance Method Details

#event_search(params) ⇒ Object

Parameters:

  • params (Hash{String=>String,Array,Integer})

    API request parameters

See Also:



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/EventbriteClient.rb', line 36

def event_search (params)
  querystring = @auth.merge( params.is_a?(Hash) ? params : {} )
  url = @base_url + "/#{@data_type}/event_search"
  data = RestClient.get url, {:params => querystring}
  result = JSON.parse(data)

  # if the hash has 'Error' as a key, we raise an error
  if result.has_key? 'Error'
            raise "web service error"
  end
  return result
end