Class: EventbriteClient
- Inherits:
-
Object
- Object
- EventbriteClient
- Includes:
- HTTParty
- Defined in:
- lib/eventbrite-client.rb
Instance Method Summary collapse
-
#initialize(auth_tokens) ⇒ EventbriteClient
constructor
A new instance of EventbriteClient.
- #method_missing(method, *args, &block) ⇒ Object
-
#method_request(method, params) ⇒ Object
available API request methods are documented at: developer.eventbrite.com/doc.
Constructor Details
#initialize(auth_tokens) ⇒ EventbriteClient
Returns a new instance of EventbriteClient.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/eventbrite-client.rb', line 6 def initialize( auth_tokens ) @auth = {} @data_type = (auth_tokens.is_a?(Hash) and auth_tokens.include? :data_type) ? auth_tokens[:data_type] : 'json' if auth_tokens.is_a? Hash if auth_tokens.include? :access_token # use oauth2 authentication tokens self.class.headers 'Authorization' => "Bearer #{auth_tokens[:access_token]}" elsif 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]} elsif auth_tokens.include?(:user) && auth_tokens.include?(:password) # read/write access on the user account matching this login info @auth = {:app_key => auth_tokens[:app_key], :user => auth_tokens[:user], :password => auth_tokens[:password]} else # read-only access to public data @auth = {:app_key => auth_tokens[:app_key]} end end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
41 42 43 |
# File 'lib/eventbrite-client.rb', line 41 def method_missing(method, *args, &block) self.method_request(method, args[0]) end |
Instance Method Details
#method_request(method, params) ⇒ Object
available API request methods are documented at: developer.eventbrite.com/doc
31 32 33 34 35 36 37 38 39 |
# File 'lib/eventbrite-client.rb', line 31 def method_request( method, params ) #merge auth params into our request querystring querystring = @auth.merge( params.is_a?(Hash) ? params : {} ) resp = self.class.get("/#{@data_type}/#{method.to_s}",{:query => querystring}) if resp['error'] raise RuntimeError, resp['error']['error_message'], caller[1..-1] end return resp end |