Class: Eventbrite::APIResource

Inherits:
EventbriteObject show all
Defined in:
lib/eventbrite/api_resource.rb

Instance Attribute Summary

Attributes inherited from EventbriteObject

#token

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from EventbriteObject

#[], #[]=, #as_json, construct_from, #each, #initialize, #inspect, #keys, #next?, #next_page, #paginated?, #refresh_from, #to_hash, #to_json, #to_s, #values

Constructor Details

This class inherits a constructor from Eventbrite::EventbriteObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Eventbrite::EventbriteObject

Class Method Details

.class_nameObject



3
4
5
6
# File 'lib/eventbrite/api_resource.rb', line 3

def self.class_name
  name_without_namespace = self.name.split('::')[-1]
  name_without_namespace.gsub(/([^\^])([A-Z])/,'\1_\2').downcase
end

.retrieve(id, token = nil) ⇒ Object



28
29
30
31
32
# File 'lib/eventbrite/api_resource.rb', line 28

def self.retrieve(id, token=nil)
  instance = self.new(id, token)
  instance.refresh
  instance
end

.urlObject



8
9
10
11
12
13
# File 'lib/eventbrite/api_resource.rb', line 8

def self.url
  if self == APIResource
    raise NotImplementedError.new('APIResource is an abstract class.  You should perform actions on its subclasses (Event, Attendee, etc.)')
  end
  "/#{CGI.escape(class_name.downcase)}s"
end

Instance Method Details

#refreshObject



22
23
24
25
26
# File 'lib/eventbrite/api_resource.rb', line 22

def refresh
  response, token = Eventbrite.request(:get, url, @token, @retrieve_options)
  refresh_from(response, token)
  self
end

#urlObject



15
16
17
18
19
20
# File 'lib/eventbrite/api_resource.rb', line 15

def url
  unless id = self.id
    raise InvalidRequestError.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{id.inspect}")
  end
  "#{self.class.url}/#{CGI.escape(id)}"
end