Class: OEHClient::Data::Structure
- Defined in:
- lib/oehclient/data/structure.rb
Constant Summary collapse
- API_PROFILES =
"/profiles"
- LABEL_CUSTOMER_KEY =
"Customer Key"
- LABEL_SITE_KEY =
"Site Key"
- LABEL_API_NAME =
"API Name"
Instance Attribute Summary
Attributes inherited from Node
Class Method Summary collapse
-
.fetch(parameters = {}) ⇒ Object
fetch makes the request to OEH for the structure and returns an instance of the structure based on the data in the configured structure.
-
.request_url(api_name) ⇒ Object
request_url returns the fully-qualified URL to return a given structure.
Methods inherited from Node
Constructor Details
This class inherits a constructor from OEHClient::Data::Node
Class Method Details
permalink .fetch(parameters = {}) ⇒ Object
fetch makes the request to OEH for the structure and returns an instance of the structure
based on the data in the configured structure
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# 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 |
permalink .request_url(api_name) ⇒ Object
request_url returns the fully-qualified URL to return a given structure
77 78 79 |
# 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 |