class OEHClient::Data::Structure

Constants

API_PROFILES
LABEL_API_NAME
LABEL_CUSTOMER_KEY
LABEL_SITE_KEY

Public Class Methods

fetch(parameters={}) click to toggle source

fetch makes the request to OEH for the structure and returns an instance of the structure

based on the data in the configured structure
# File lib/oehclient/data/structure.rb, line 15
def self.fetch(parameters={})

        # force the parameters empty hash if needed
        parameters ||= Hash.new

        # validate the parameters.  The implementation expects a Hash object
        if (!parameters.empty?)
                # implementation expects a Hash that contains the Customer Key (:ck),
                #  Site Key (:sk), and API Name (:api) because they are required to get
                #  structure from OEH
                if ((parameters.has_key?(:ck) || parameters.has_key?(:tid)) && parameters.has_key?(:sk) && parameters.has_key?(:api))

                        oeh_params          = {:sk => parameters[:sk]}

                        # set the values based on passed parameters
                        oeh_params.merge!({:ck => parameters[:ck]})                         if (parameters.has_key?(:ck))
                        oeh_params.merge!({:ckname => parameters[:keyname]})        if (parameters.has_key?(:keyname))
                        oeh_params.merge!({:tid => parameters[:tid]})                       if (parameters.has_key?(:tid))

                        # grab the API Name
                        api_name            = parameters[:api]

                        # set the space based on the site key value that was passed
                        @space                      = OEHClient::Config::SpaceManager.instance.get(parameters[:sk])           if (parameters.has_key?(:sk))

                        # Use the OEHClient object to call OEH profiles API and create an instance
                        #  of this class (OEHClient::Data::Structure) as the return value
                        response = OEHClient.get(self.request_url(api_name),
                                                                                @space.oauth_consumer, 
                                                                                :params => oeh_params)
                        # dynamically map the response object to a new OEHClient::Data::Structure class
                        OEHClient::Data::Structure.new(response[:body])

                else

                        # If the calling application passed a parameter Hash, but is missing key attributes,
                        #  raise the Oeh::Exception::MissingParameterException with the name of each
                        #  parameter
                        missing_parameters = []

                        missing_parameters << LABEL_CUSTOMER_KEY    unless (parameters.has_key?(:ck))
                        missing_parameters << LABEL_SITE_KEY                unless (parameters.has_key?(:sk))
                        missing_parameters << LABEL_API_NAME                unless (parameters.has_key?(:api))

                        # raise the OEHClient::Exception::MIssingParameterException using the list of missing parameter
                        # labels that have been added to the collection
                        raise OEHClient::Exception::MissingParameterException.new(missing_parameters)

                end

        else

                # if the parameters object is NIL then raise the OEHClient::Exception::MissingParameterException,
                #  passing the full set of expected parameter names
                raise OEHClient::Exception::MissingParameterException.new([LABEL_CUSTOMER_KEY, LABEL_SITE_KEY, LABEL_API_NAME])
                                
        end


end
request_url(api_name) click to toggle source

request_url returns the fully-qualified URL to return a given structure

# File lib/oehclient/data/structure.rb, line 77
def self.request_url(api_name)
        "#{OEHClient::Helper::Request::ONE_PROTOCOL}#{@space.host}#{OEHClient::Helper::Request::ONE_URI_PART}#{OEHClient::Helper::Request::API_URI_PART}#{OEHClient::Helper::Request::API_VERSION}#{API_PROFILES}/#{api_name}"
end