lib/finix.rb in finix-0.15 vs lib/finix.rb in finix-0.16
- old
+ new
@@ -1,24 +1,24 @@
-require 'finix/version' unless defined? Finix::VERSION
-require 'finix/client'
-require 'finix/error'
+require_relative 'finix/version' unless defined? Finix::VERSION
+require_relative 'finix/client'
+require_relative 'finix/errors'
module Finix
@client = nil
@config = {:root_url => 'https://localhost/processing'}
@hypermedia_registry = {}
@errors_registry = {
- :unknown => Finix::ResourceErrors,
- 400 => Finix::BadRequest,
- 401 => Finix::Unauthorized,
- 402 => Finix::PaymentRequired,
- 403 => Finix::Forbidden,
- 404 => Finix::NotFound,
- 405 => Finix::MethodNotAllowed,
- 422 => Finix::UnprocessableEntity,
- 500 => Finix::InternalServerError
+ :unknown => Errors,
+ 400 => BadRequest,
+ 401 => Unauthorized,
+ 402 => PaymentRequired,
+ 403 => Forbidden,
+ 404 => NotFound,
+ 405 => MethodNotAllowed,
+ 422 => UnprocessableEntity,
+ 500 => InternalServerError
}
class << self
attr_accessor :client
@@ -33,36 +33,41 @@
@config = @config.merge(options)
@config[:user] = @config[:user].strip unless @config[:user].nil?
@config[:password] = @config[:password].strip unless @config[:password].nil?
- @client = Finix::Client.new @config
+ @client = Client.new @config
end
def split_the_href(href)
URI.parse(href).path.sub(/\/$/, '').split('/')
end
def get_href(cls)
- href = Finix.hypermedia_registry.key(cls)
+ href = hypermedia_registry.key(cls)
sps = cls
while href.nil?
sps = sps.superclass
break if sps.nil?
- clss = Finix::Utils.eval_class cls, sps.name.split('::').last
- href = Finix.hypermedia_registry.key(clss)
+ clss = Finix::Utils.eval_class cls, sps
+ href = hypermedia_registry.key(clss)
end
href
end
def from_hypermedia_registry(href, attributes={})
split_uri = split_the_href(href)
split_uri.reverse!.each do |resource|
- cls = Finix.hypermedia_registry[resource]
- cls = cls.send :hypermedia_subtype, attributes if not cls.nil? and cls.respond_to?(:hypermedia_subtype)
+ cls = find_resource_cls(resource, attributes)
return cls unless cls.nil?
end
- Finix::Utils.eval_class self, 'UnknownResource'
+ Finix::Utils.eval_class self, UnknownResource
+ end
+
+ def find_resource_cls(resource, attributes={})
+ cls = hypermedia_registry[resource]
+ cls = cls.send :hypermedia_subtype, attributes if not cls.nil? and cls.respond_to?(:hypermedia_subtype)
+ cls
end
def get(*args, &block)
self.client.get *args
end
\ No newline at end of file