Sha256: 35be6c8030fe2ecb65a095f7fa99dd790ec1cea313463c45544c1a5a7451e963

Contents?: true

Size: 1.49 KB

Versions: 3

Compression:

Stored size: 1.49 KB

Contents

require 'finix/version' unless defined? Finix::VERSION

module Finix

  @client = nil
  @config = {:root_url=>'https://localhost/processing'}
  @hypermedia_registry = {}

  class << self

    attr_accessor :client
    attr_accessor :config
    attr_accessor :hypermedia_registry

    def configure(options={})
      unless options[:root_url].nil? # reset us/pass as well if user update :root_url
        @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 = Finix::Client.new @config
    end

    def split_the_href(href)
      URI.parse(href).path.sub(/\/$/, '').split('/')
    end

    def from_hypermedia_registry(resource_name)
      cls = Finix.hypermedia_registry[resource_name]
      if cls.nil?
        return Finix::UnknownResource
      end
      cls
    end

    def from_href(href)
      split_uri = split_the_href(href)
      split_uri.reverse!.each do |resource|
        cls = Finix.hypermedia_registry[resource]
        return cls unless cls.nil?
      end
    end

    def is_collection(href)
      split_uri = split_the_href(href)
      Finix.hypermedia_registry.has_key?(split_uri.last)
    end

    def get(*args, &block)
      self.client.get *args
    end

    def post(*args, &block)
      self.client.post *args
    end

    def put(*args, &block)
      self.client.put *args
    end
  end
end

require 'finix/resources'

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
finix-0.4 lib/finix.rb
finix-0.3 lib/finix.rb
finix-0.2 lib/finix.rb