require 'her' require 'active_support/concern' require 'norseal/api/model' module Norseal module Api class ClientNotConfigured < Exception; end def self.configure(host, api_key, &block) @api = Her::API.new @api.setup :url => "http://#{host}/" do |c| # c.use FaradayMiddleware::EncodeJson c.use Her::Middleware::AcceptJSON c.use Her::Middleware::FirstLevelParseJSON c.authorization :token, api_key yield c if block_given? c.adapter Faraday.default_adapter unless c.builder.handlers.include?(Faraday::Adapter::Test) end require "api/resources/collection" require "api/resources/product" end def self.api raise ClientNotConfigured.new("Norseal") unless @api @api end end end