module EventbriteSDK::Resource::Operations::Endpoint::ClassMethods

Public Instance Methods

define_path_methods() click to toggle source
# File lib/eventbrite_sdk/resource/operations/endpoint.rb, line 65
def define_path_methods
  @paths.values.each do |path_config|
    path_config.scan(/:\w+/).each do |path_attr|
      attr = path_attr.delete(':').to_sym

      define_method(attr) { @attrs[attr] if @attrs.respond_to?(attr) }
    end
  end
end
path(is_create = false) click to toggle source
# File lib/eventbrite_sdk/resource/operations/endpoint.rb, line 75
def path(is_create = false)
  if is_create
    @paths[:create]
  else
    @paths[:update]
  end
end
resource_path(path) click to toggle source

Define the url path for the resource. It also implicitly defines the primary key and any additional foreign keys required for this resource.

Example:

TicketClass is a resource that requires a primary key of id and a foreign key of event_id to be retrieved, modified or deleted.

resource_path('events/:event_id/ticket_classes/:id')

The resource now has id and event_id accessor methods, and requires those parameters to build the correct resource url path. See the retrieve method (above) for additional details.

# File lib/eventbrite_sdk/resource/operations/endpoint.rb, line 55
def resource_path(path)
  if path.is_a?(Hash)
    @paths = path
  else
    @paths = { create: path, update: path }
  end

  define_path_methods
end
retrieve(params, request = EventbriteSDK) click to toggle source

Retrieve a resource.

params: Hash of supported parameters. The keys and values are

used to build the request URL by substituting supported
keys in the resource_path with the value defined in params.

The :expand key allows the support of expansions of child
objects. It supports strings, symbols and arrays.

expand: :something
expand: %i(something another)
expand: %w(something another)
expand: 'something,another'

Example:

class Thing < Resource

resource_path('things/:id')

end

Thing.retrieve(id: 1234, expand: :others)

This tells the resource to replace the :id placeholder with the value 1234. It also will pass the :expand option with the

# File lib/eventbrite_sdk/resource/operations/endpoint.rb, line 30
def retrieve(params, request = EventbriteSDK)
  url_path = params.reduce(path) do |path_config, (key, value)|
    path_config.gsub(":#{key}", value.to_s)
  end

  api_token = params.fetch(:api_token, nil)
  query = params[:expand] && { expand: [*params[:expand]].join(',') }

  new request.get(url: url_path, query: query, api_token: api_token)
end