require 'oauth' require 'csv' require 'uuidtools' require 'json' require 'active_support' require File.dirname(__FILE__) + '/oehclient/helper' require File.dirname(__FILE__) + '/oehclient/exception' require File.dirname(__FILE__) + '/oehclient/config' require File.dirname(__FILE__) + '/oehclient/interaction' require File.dirname(__FILE__) + '/oehclient/data' module OEHClient class << self attr_accessor :spaces, :space_mgr # configure provides the basic interface for passing tenancy configuration to the gem def configure_space # if space_mgr attribute is NIL then return a new instance of the OEHClient::Config::SpaceManager # singleton class @space_mgr ||= OEHClient::Config::SpaceManager.instance # yield control to the block passed in the configuration yield(@space_mgr) end # get wraps the GET method of the access token and manages the response that is returned def get(token, url, header={}) # force the new hash. Testing in RSPEC uncovered issue with the default not being followed header ||= Hash.new # if the token is not a proper OAuth::AccessToken, then raise the Oeh::Exception::InvalidTokenException # exception to the calling method raise OEHClient::Exception::InvalidTokenException unless (token.kind_of?(OAuth::AccessToken)) # send the GET request, manage the returned response, and return the body of the response to the # calling method token.get(url, header.empty? ? OEHClient::Helper::Request.default_JSON_header() : header) end # post wraps the POST method of the access token and manages the response that is returned def post(token, url, header={}, body) # force the new hash. Testing in RSPEC uncovered issue with the default not being followed header ||= Hash.new # if the token is not a proper OAuth::AccessToken, then raise the Oeh::Exception::InvalidTokenException # exception to the calling method raise OEHClient::Exception::InvalidTokenException unless (token.kind_of?(OAuth::AccessToken)) # send the POST request, manage the returned response, and return the body of the response to the # calling method token.post(url, ActiveSupport::JSON.encode(body), header.empty? ? OEHClient::Helper::Request.default_JSON_header() : header) end # put wraps the PUT method of the access token and manages the response that is returned def put(token, url, header={}, body) # force the new hash. Testing in RSPEC uncovered issue with the default not being followed header ||= Hash.new # if the token is not a proper OAuth::AccessToken, then raise the Oeh::Exception::InvalidTokenException # exception to the calling method raise OEHClient::Exception::InvalidTokenException unless (token.kind_of?(OAuth::AccessToken)) # send the PUT request, manage the returned response, and return the body of the response to the # calling method token.put(url, ActiveSupport::JSON.encode(body), header.empty? ? OEHClient::Helper::Request.default_JSON_header() : header) end end end