module Arke::Resource::URL::ClassMethods

Public Instance Methods

endpoint(endpoint=nil) click to toggle source

Gets or sets the device endpoint. By default the endpoint uses {#resource_name} if an endpoint has not been provided.

@param [String] the service endpoint. if left nil it will simply return the existing endpoint

@return [String] the service endpoint

# File lib/arke/resource/url.rb, line 54
def endpoint(endpoint=nil)
  @endpoint = endpoint if endpoint
  @endpoint ||= resource_name
end
host(host=nil) click to toggle source

Gets or sets the resource host.

@param [String] host the resource host. if left nil, the method will simply return the current resource host

@return [String] the current resource host

# File lib/arke/resource/url.rb, line 30
def host(host=nil)
  @host = host if host
  @host
end
url(options={}) click to toggle source

Gets the resource url. This compiles the url template using the passed options and returns the resulting string.

@param [Hash] options the url options to pass to the template. By default the template looks for a an id and a query.

@return [String] the full resource url

# File lib/arke/resource/url.rb, line 42
def url(options={})
  template = options[:_template] ? Addressable::Template.new(options.delete(:_template)) : nil ||self.url_template
  association_options = {parent_resource_name: options.delete(:_parent_resource_name), relation_id: options.delete(:_relation_id), resource_name: options.delete(:_resource_name)}
  host + template.expand(association_options.merge(options.merge(endpoint: endpoint))).to_s
end
url_template(template=nil) click to toggle source

Gets or sets the url template for the resource. The url template is a {github.com/sporkmonger/addressable Addressable} template and defaults to {DEFAULT_URL_TEMPLATE}. If a parameter is passed to this method it will set the url template to the passed parameter, otherwise it will just return the URL template.

@param [String] template the url template to set, if left nil, the method will simply return the current url template

@return [Addressable::Template] the url template. If none has been set, it references {DEFAULT_URL_TEMPLATE}

# File lib/arke/resource/url.rb, line 20
def url_template(template=nil)
  @url_template = Addressable::Template.new(template) if template
  @url_template || Addressable::Template.new(DEFAULT_URL_TEMPLATE)
end