lib/norseal/api.rb in norseal-api-0.1.0 vs lib/norseal/api.rb in norseal-api-0.1.1

- old
+ new

@@ -1,11 +1,33 @@ -# require "norseal/api/version" +require 'her' +require 'active_support/concern' +require 'norseal/api/model' module Norseal module Api - class Product - def self.addition(num, num2) - num + num2 + 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 "norseal/api/resources/collection" + require "norseal/api/resources/product" + end + + def self.api + raise ClientNotConfigured.new("Norseal") unless @api + @api end end end