module Finix

Constants

VERSION

Attributes

client[RW]
config[RW]
errors_registry[RW]
hypermedia_registry[RW]

Public Class Methods

configure(options={}) click to toggle source
# File lib/finix.rb, line 29
def configure(options={})
  unless options[:root_url].nil?
    @config = {}
  end

  @config = @config.merge(options)
  @config[:user] = @config[:user].strip unless @config[:user].nil?
  @config[:password] = @config[:password].strip unless @config[:password].nil?

  @client = Client.new @config
end
find_resource_cls(resource, attributes={}) click to toggle source
# File lib/finix.rb, line 67
def find_resource_cls(resource, attributes={})
  cls = hypermedia_registry[resource]
  # cls = hypermedia_registry["__stub__#{resource}"] if cls.nil?
  cls = cls.send :hypermedia_subtype, attributes if not cls.nil? and cls.respond_to?(:hypermedia_subtype)
  cls
end
from_hypermedia_registry(href, attributes={}) click to toggle source
# File lib/finix.rb, line 58
def from_hypermedia_registry(href, attributes={})
  split_uri = split_the_href(href)
  split_uri.reverse!.each do |resource|
    cls = find_resource_cls(resource, attributes)
    return cls unless cls.nil?
  end
  Finix::Utils.eval_class self, UnknownResource
end
get(*args, &block) click to toggle source
# File lib/finix.rb, line 74
def get(*args, &block)
  self.client.get *args
end
get_href(cls) click to toggle source
# File lib/finix.rb, line 45
def get_href(cls)
  href = (not cls.nil? and not cls.hypermedia_types.nil?) ? cls.hypermedia_types.last : hypermedia_registry.key(cls)

  sps = cls
  while href.nil?
    sps = sps.superclass
    break if sps.nil?
    clss = Finix::Utils.eval_class cls, sps
    href = hypermedia_registry.key(clss)
  end
  href
end
post(*args, &block) click to toggle source
# File lib/finix.rb, line 78
def post(*args, &block)
  self.client.post *args
end
put(*args, &block) click to toggle source
# File lib/finix.rb, line 82
def put(*args, &block)
  self.client.put *args
end
split_the_href(href) click to toggle source
# File lib/finix.rb, line 41
def split_the_href(href)
  URI.parse(href).path.sub(/\/$/, '').split('/')
end