class ContextIO::Lite::URLBuilder
Public Class Methods
register_url(resource_class, &block)
click to toggle source
Register a block that calculates the URL for a given resource.
@param [Class] resource_class The class of the resource you are
registering.
@param [Block] block The code that will compute the url for the
resource. This is actually a path. Start after the version number of the API in the URL. When a URL is being calculated for a specific resource, the resource instance will be yielded to the block.
@example For Accounts
register_url ContextIO::Account do |account| "accounts/#{account.id}" end
# File lib/contextio/lite/url_builder.rb, line 39 def self.register_url(resource_class, &block) @registered_urls ||= {} @registered_urls[resource_class] = block end
uri_encode(param)
click to toggle source
# File lib/contextio/lite/url_builder.rb, line 85 def self.uri_encode(param) if param.is_a? String URI.encode param else param end end
url_for(resource)
click to toggle source
Tells you the right URL for a resource to fetch attributes from.
@param [Contextio::Resource, Contextio::ResourceCollection] resource The
resource or resource collection.
@return [String] The path for that resource in the API
.
# File lib/contextio/lite/url_builder.rb, line 18 def self.url_for(resource) if (builder = @registered_urls[resource.class]) builder.call(resource) else raise Error, "URL could not be built for unregistered Class: #{resource.class}." end end