oeh-client 2.2.2 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4bec0ddd14a97b575b75493774289c2bba409a2d
4
- data.tar.gz: 32090d1adabc23a2dffe22e92cc1f57feeaa3bcb
3
+ metadata.gz: 3f7b97eb02dc3346e3cf60404722416dbb25e92b
4
+ data.tar.gz: eb3ed9815faf0bd3387507a2d5b676e9fbb5fd8e
5
5
  SHA512:
6
- metadata.gz: a477d4f83d54c24268550567fb1582060c065e30efd2e5b976e98d743c7db79522d721c4505446ff7226d2e512eff031ccf2e02c22dbd32de81ae35ea77abedd
7
- data.tar.gz: 997695f476c2f872011288d98803d05a0fa93a3c45c562a49721fea33701fcb99d93602e93df32f56fc27e2e164eebdc219c5e904c2e2ff7f04da9bbb686ac30
6
+ metadata.gz: c8f7d75978c452397fa719598ac5b3a1e730f8f75531272ef71a2ff529487894524da0b4d33aea4aeb5c4b8e7f4988fb3df925432086b86edf7854431e984e1e
7
+ data.tar.gz: efc1479d6c157534cbb49cfcab6ee8cc54fa2194f32f23eb2eeff4a1b6f1a2c3f46de859ebf844e52c03afafbff16da45ad7ab49a19485b29596675aee4f5cbf
@@ -0,0 +1,114 @@
1
+ require 'erb'
2
+ require 'rest-client'
3
+
4
+ class OEHClient::Config::Space
5
+
6
+ ###
7
+ ### ------------- Constants
8
+ ###
9
+
10
+
11
+ ###
12
+ ### ------------- Attributes
13
+ ###
14
+
15
+ attr_accessor :site_key, # The ONE Site KEY Value
16
+ :host, # The name of the HOST machine on thunderhead.com (ONEDEMO, EU2, NA4, etc..)
17
+ :api_key, # The API key provided in the ONE SETTINGS interface
18
+ :shared_secret, # The shared secret value provided in the ONE SETTINGS interface
19
+ :username, # The fully-qualified username configured for access to the space
20
+ :meta_password, # The password needed to access meta-data from the OEH server
21
+ :workspace # The ONE workspace related to the current space
22
+
23
+ ###
24
+ ### ------------- Class Methods
25
+ ###
26
+
27
+
28
+ # create builds a new instance of the Site class, populats the attributes using the properties HASH provided
29
+ # and returns an instance of the class.
30
+ def self.create(properties={})
31
+
32
+ # create a new instance of the OHEClient::Space class
33
+ space_instance = OEHClient::Config::Space.new()
34
+
35
+ # assign all attributes from the passed properties hash
36
+ space_instance.site_key = properties[:site_key] if (properties.has_key?(:site_key))
37
+ space_instance.host = properties[:host] if (properties.has_key?(:host))
38
+ space_instance.api_key = properties[:api_key] if (properties.has_key?(:api_key))
39
+ space_instance.shared_secret = properties[:shared_secret] if (properties.has_key?(:shared_secret))
40
+ space_instance.username = properties[:username] if (properties.has_key?(:username))
41
+ space_instance.meta_password = properties[:meta_password] if (properties.has_key?(:meta_password))
42
+
43
+ # return the instance of the OEHClient::Site Class
44
+ space_instance
45
+
46
+ end
47
+
48
+
49
+ ###
50
+ ### ------------- Instance Methods
51
+ ###
52
+
53
+
54
+ # token is the method used to generate a new OAuth::AccessToken object based on the configuration of
55
+ # the related space
56
+ def token()
57
+
58
+ # raise the OEHClient::InvalidSpaceException the current instance is not valid
59
+ raise OEHClient::Exception::InvalidSpaceConfigException unless is_valid?
60
+
61
+ # Create the consumer and access token
62
+ oauth_consumer = OAuth::Consumer.new("#{@api_key}!#{@username}",
63
+ @shared_secret,
64
+ {:site => "#{OEHClient::Helper::Request::ONE_PROTOCOL}#{@host}",
65
+ :scheme => :header})
66
+ # return the access token
67
+ return(OAuth::AccessToken.new(oauth_consumer))
68
+
69
+ end
70
+ # return a new instance of the OAuth::Consumer using the details of the space
71
+ def oauth_consumer()
72
+ OAuth::Consumer.new("#{@api_key}!#{@username}",
73
+ @shared_secret,
74
+ {:site => "#{OEHClient::Helper::Request::ONE_PROTOCOL}#{@host}",
75
+ :scheme => :header})
76
+ end
77
+
78
+ # is_valid determines if the current class has values for all the attributes. Each attribute is
79
+ # required with a non-nul / non-blank value to be considered valid
80
+ def is_valid?()
81
+ ((!@site_key.nil? && !@site_key.empty?) && (!@host.nil? && !@host.empty?) &&
82
+ (!@api_key.nil? && !@api_key.empty?) && (!@shared_secret.nil? && !@shared_secret.empty?) &&
83
+ (!@username.nil? && !@username.empty?))
84
+ end
85
+
86
+ # determines if the space configuration appears to be valid for access to the raw meta-data entities.
87
+ # The method expects the standard valid attributes from is_valid? as well as the meta_password
88
+ # attribute
89
+ def meta_access?()
90
+ self.is_valid? && (!@meta_password.blank?)
91
+ end
92
+
93
+ # return the hash that
94
+ def meta_credentials()
95
+ {:username => @username, :password => @meta_password, :rememberMe => "false"}
96
+ end # def meta_credentials
97
+ # return the URL for the posting a login request
98
+ def login_url()
99
+ "#{OEHClient::Helper::Request::ONE_PROTOCOL}#{@host}/one/idm_login"
100
+ end # def login_url
101
+ # return the URL for posting a logout request
102
+ def logout_url()
103
+ "#{OEHClient::Helper::Request::ONE_PROTOCOL}#{@host}/one/logout"
104
+ end
105
+
106
+ # retrieve the workspace meta-data object from the thinstance in realtime
107
+ def get_workspace()
108
+ # create an active session with ONE
109
+ workspace = OEHClient::Meta::Session.attach(self).workspace(site_key) if (workspace.nil?)
110
+ # return the active workspace object
111
+ workspace
112
+ end
113
+
114
+ end
@@ -0,0 +1,55 @@
1
+ require 'singleton'
2
+
3
+ class OEHClient::Config::SpaceManager
4
+ include Singleton
5
+
6
+
7
+ attr_accessor :spaces
8
+
9
+ # Constructor. Initialize the spaces collection as a new hash
10
+ def initialize
11
+ @spaces = Hash.new
12
+ end
13
+
14
+ # register_space is a wrapper method that converts the passed Hash object to an instance of the
15
+ # OEHClient::Config::Space object, which is passed to the register method
16
+ def register_space(space_config={})
17
+
18
+ # Pass a new instance of the space object to the register_space method
19
+ register(OEHClient::Config::Space.create(space_config))
20
+
21
+ end
22
+
23
+ # get_space returns the instance of the OEHClient::Config::Space
24
+ def get(site_key)
25
+
26
+ # raise the OEHClient::Exception::InvalidSpaceException if the space has not been registered
27
+ raise OEHClient::Exception::InvalidSpaceException unless (@spaces.has_key?(site_key))
28
+
29
+ # return the space configuration instance
30
+ @spaces[site_key]
31
+
32
+ end
33
+
34
+ private
35
+
36
+ # register adds the instance of the OEHClient::Config::Space object to the spaces hash, using the
37
+ # site_key value as the hash KEY
38
+ def register(space_instance)
39
+
40
+ # Raise OEHClient::Exception::InvalidSpaceException if the space instance is NOT valie
41
+ raise OEHClient::Exception::InvalidSpaceConfigException unless (space_instance.is_valid?)
42
+ # Raise the OEHClient::Exception::InvalidSpaceObjectException if the space_instance object is not
43
+ # the proper type of object (OEHClient::Config::Space)
44
+ raise OEHClient::Exception::InvalidSpaceObjectException unless (space_instance.kind_of?(OEHClient::Config::Space))
45
+
46
+ # Assign the space instance to the spaces collection
47
+ @spaces[space_instance.site_key] = space_instance
48
+
49
+ end
50
+
51
+
52
+
53
+
54
+
55
+ end
@@ -0,0 +1,11 @@
1
+
2
+ module OEHClient
3
+
4
+ module Config
5
+ end
6
+
7
+ end
8
+
9
+ require File.dirname(__FILE__) + '/config/space'
10
+ require File.dirname(__FILE__) + '/config/space_manager'
11
+
@@ -0,0 +1,66 @@
1
+
2
+ class OEHClient::Data::Node
3
+
4
+ attr_accessor :nodes
5
+
6
+ def initialize(data)
7
+
8
+ # Raise an exception if the data passed is not already a hash
9
+
10
+ # based on the type of object that is passed, create the proper attribute accessor
11
+ # to allow easy access to data. For example, a simple value in the structure called
12
+ # firstName will be represented in the object as my_structure.first_name. Simple
13
+ # object are represented as related node classes. For example a Preference node with
14
+ # an attribute of nonSmokingRoom will be represented as my_structure.preference.non_smoking_room
15
+ data.each do | key, value |
16
+ (value.kind_of?(Array) ? add_collection(key, value) : add_attribute(key, value))
17
+ end
18
+
19
+ end
20
+
21
+ # return the names of each of the attributes of the current nodes of the structure
22
+ def attribute_names()
23
+ name_collection = Array.new
24
+ instance_variable_names.each do | structure_attribute |
25
+ structure_attribute.slice!(0)
26
+ name_collection << structure_attribute
27
+ end
28
+ name_collection
29
+ end # def attribute_names
30
+
31
+
32
+ private
33
+
34
+ # add_collection dynamically create an attr_accessor as an array of Oeh::Structure::Node
35
+ # classes related to the current instance of the object.
36
+ def add_collection(name, value_collection)
37
+
38
+ # initialize the array object that will act as the value of the attribute
39
+ node_collection = []
40
+
41
+ # for each hash in the array, add a new structure node
42
+ value_collection.each do | structure_node |
43
+ node_collection << OEHClient::Data::Structure.new(structure_node)
44
+ end
45
+ # add the arry of node objects to the accessor
46
+ add_attribute(name, node_collection)
47
+
48
+ end
49
+
50
+ # add_attribute dynamically creates an attr_accessor for the passed key_value pair either
51
+ # as a simple value attribute or as an instance of another Node class
52
+ def add_attribute(name, value)
53
+
54
+ # generate a ruby-friendly attribute accessor based on the name of the
55
+ # structure attribute
56
+ accessor_name = name.underscore
57
+ accessor_name.gsub!(/( )/, '_') if (accessor_name.match(/\s/))
58
+ # create the accessor in the current class and set the value based on the type
59
+ # of object that represents the value
60
+ self.class.send(:attr_accessor, accessor_name)
61
+ instance_variable_set("@#{accessor_name}", (value.kind_of?(Hash) ? OEHClient::Data::Node.new(value) : value))
62
+
63
+ end
64
+
65
+
66
+ end
@@ -0,0 +1,82 @@
1
+ class OEHClient::Data::Structure < OEHClient::Data::Node
2
+
3
+ API_PROFILES = "/profiles"
4
+
5
+ LABEL_CUSTOMER_KEY = "Customer Key"
6
+ LABEL_SITE_KEY = "Site Key"
7
+ LABEL_API_NAME = "API Name"
8
+
9
+ #
10
+ # Class Methods
11
+ #
12
+
13
+ # fetch makes the request to OEH for the structure and returns an instance of the structure
14
+ # based on the data in the configured structure
15
+ def self.fetch(parameters={})
16
+
17
+ # force the parameters empty hash if needed
18
+ parameters ||= Hash.new
19
+
20
+ # validate the parameters. The implementation expects a Hash object
21
+ if (!parameters.empty?)
22
+ # implementation expects a Hash that contains the Customer Key (:ck),
23
+ # Site Key (:sk), and API Name (:api) because they are required to get
24
+ # structure from OEH
25
+ if ((parameters.has_key?(:ck) || parameters.has_key?(:tid)) && parameters.has_key?(:sk) && parameters.has_key?(:api))
26
+
27
+ oeh_params = {:sk => parameters[:sk]}
28
+
29
+ # set the values based on passed parameters
30
+ oeh_params.merge!({:ck => parameters[:ck]}) if (parameters.has_key?(:ck))
31
+ oeh_params.merge!({:keyname => parameters[:keyname]}) if (parameters.has_key?(:keyname))
32
+ oeh_params.merge!({:tid => parameters[:tid]}) if (parameters.has_key?(:tid))
33
+
34
+ # grab the API Name
35
+ api_name = parameters[:api]
36
+
37
+ # set the space based on the site key value that was passed
38
+ @space = OEHClient::Config::SpaceManager.instance.get(parameters[:sk]) if (parameters.has_key?(:sk))
39
+
40
+ # Use the OEHClient object to call OEH profiles API and create an instance
41
+ # of this class (OEHClient::Data::Structure) as the return value
42
+ response = OEHClient.get(self.request_url(api_name),
43
+ @space.oauth_consumer,
44
+ :params => oeh_params)
45
+ # dynamically map the response object to a new OEHClient::Data::Structure class
46
+ OEHClient::Data::Structure.new(response[:body])
47
+
48
+ else
49
+
50
+ # If the calling application passed a parameter Hash, but is missing key attributes,
51
+ # raise the Oeh::Exception::MissingParameterException with the name of each
52
+ # parameter
53
+ missing_parameters = []
54
+
55
+ missing_parameters << LABEL_CUSTOMER_KEY unless (parameters.has_key?(:ck))
56
+ missing_parameters << LABEL_SITE_KEY unless (parameters.has_key?(:sk))
57
+ missing_parameters << LABEL_API_NAME unless (parameters.has_key?(:api))
58
+
59
+ # raise the OEHClient::Exception::MIssingParameterException using the list of missing parameter
60
+ # labels that have been added to the collection
61
+ raise OEHClient::Exception::MissingParameterException.new(missing_parameters)
62
+
63
+ end
64
+
65
+ else
66
+
67
+ # if the parameters object is NIL then raise the OEHClient::Exception::MissingParameterException,
68
+ # passing the full set of expected parameter names
69
+ raise OEHClient::Exception::MissingParameterException.new([LABEL_CUSTOMER_KEY, LABEL_SITE_KEY, LABEL_API_NAME])
70
+
71
+ end
72
+
73
+
74
+ end
75
+
76
+ # request_url returns the fully-qualified URL to return a given structure
77
+ def self.request_url(api_name)
78
+ "#{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}"
79
+ end
80
+
81
+
82
+ end
@@ -0,0 +1,10 @@
1
+
2
+ module OEHClient
3
+
4
+ module Data
5
+ end
6
+
7
+ end
8
+
9
+ require File.dirname(__FILE__) + '/data/node'
10
+ require File.dirname(__FILE__) + '/data/structure'
@@ -0,0 +1,64 @@
1
+ module OEHClient
2
+
3
+ module Exception
4
+
5
+ # Used when an invalid OAuth consumer is detected as part of the client-side API calls
6
+ class InvalidConsumerException < ::Exception
7
+
8
+ end
9
+
10
+ # InvalidSpaceConfigException is used when a OEHClient::Space instance is missing one or more
11
+ # of the key data attributes
12
+ class InvalidSpaceConfigException < ::Exception
13
+
14
+ end
15
+
16
+ # InvalidSpaceException is used when a space is not configured
17
+ class InvalidSpaceException < ::Exception
18
+
19
+ end
20
+
21
+ # InvalideSpaceObjectException is used when a method expects a OEHClient::Config::Space object and
22
+ # the object passed is not of the same type
23
+ class InvalidSpaceObjectException < ::Exception
24
+
25
+ end
26
+
27
+ # HTTPRequestException is used to manage any REST error code that is returned by the OEH
28
+ # server
29
+ class HTTPRequestException < ::Exception
30
+
31
+ attr_accessor :http_code
32
+
33
+ # override the constructor to add the code value to exception class
34
+ def initialize(msg, code)
35
+ super(msg)
36
+ @http_code = code
37
+ end
38
+
39
+ end
40
+
41
+ # Missing ParameterException is used to identify the list of parameters that are required, but missing
42
+ # by a key method
43
+ class MissingParameterException < ::Exception
44
+
45
+ def initialize(parameter_list)
46
+
47
+ super("Missing the required parameters #{parameter_list.join(', ')}")
48
+ end
49
+
50
+ end
51
+
52
+ class IncorrectParameterTypeException < ::Exception
53
+
54
+
55
+ def initialize(expected_kind, passed_kind)
56
+
57
+ super("Incorrect Parameter Type. Expected #{expected_kind} but received #{passed_kind}")
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+
64
+ end
@@ -0,0 +1,97 @@
1
+ require 'erb'
2
+
3
+ module OEHClient
4
+
5
+ module Helper
6
+
7
+ module Request
8
+
9
+ ONE_PROTOCOL = "https://"
10
+ THUNDERHEAD_DOMAIN = ".thunderhead.com"
11
+ ONE_URI_PART = "/one/oauth1"
12
+
13
+ API_URI_PART = "/rt/api"
14
+ API_VERSION = "/2.0"
15
+
16
+ POST_METHOD = "post"
17
+ PUT_METHOD = "put"
18
+
19
+ # request_url builds the target request URL with the passed parameters, URL encoding the parameters
20
+ # as necessary to create a valid request
21
+ def self.format_url(url, params)
22
+
23
+ # for each of the parameters, build a single query parameter string
24
+ parameter_part = ""
25
+ params.each do |key, value|
26
+ # if there is more than one argument, add the apppropriate separator (&) between
27
+ # query parameters
28
+ parameter_part << "&" if (parameter_part.length > 0)
29
+ # URL Encode the value of the property
30
+ parameter_part << "#{key.to_s}=#{ERB::Util.url_encode(value)}"
31
+
32
+ end
33
+ # return the fully-qualified URL with parameters (if passsed)
34
+ (parameter_part.length > 0 ? "#{url}?#{parameter_part}" : "#{url}")
35
+
36
+ end
37
+
38
+ # default_JSON_header is the default header that is passed to any OEH Request if not provided explicitly by the
39
+ # calling methods
40
+ def self.default_JSON_header()
41
+ {'Accept' => 'application/json' , 'dataMimeType' => 'application/json','Content-Type' =>'application/json', 'X-Requested-With' => 'XMLHttpRequest' }
42
+ end
43
+
44
+
45
+ end # module Request
46
+
47
+ module Response
48
+
49
+ # determine if the string that was passed is valid JSON syntax and can be parsed by the the
50
+ # ActiveSupport::JSON.decode method
51
+ def self.valid_json?(json)
52
+ valid_indicator = true
53
+ begin
54
+ ActiveSupport::JSON.decode(json)
55
+ rescue ActiveSupport::JSON.parse_error
56
+ valid_indicator = false
57
+ end
58
+ end
59
+
60
+
61
+ def self.handle(rest_response)
62
+
63
+ valid_response_codes = [100, 200, 204, 302]
64
+ # raise a generic HTTPRequestException if the the status code is not 100 (Continue) or 200 (OK)
65
+ raise OEHClient::Exception::HTTPRequestException.new("HTTP Request Exception with code #{rest_response.code} -- details: #{rest_response.body}", rest_response.code) unless (valid_response_codes.include?(rest_response.code))
66
+
67
+ api_response = Hash.new
68
+
69
+ api_response[:body] = (rest_response.code == 204 ? {} : (OEHClient::Helper::Response.valid_json?(rest_response.body) ? ActiveSupport::JSON.decode(rest_response.body) : rest_response.body))
70
+ api_response[:cookies] = rest_response.cookies
71
+
72
+ api_response
73
+
74
+ end
75
+
76
+ end # module Response
77
+
78
+
79
+ module Timestamp
80
+
81
+ # convert the time value from a Time, DateTime, String, or Integer to a proper ONE timestamp value
82
+ # format (UTC Milliseconds)
83
+ def self.to_one_timestamp(timevalue)
84
+
85
+ one_timestamp = timevalue if (timevalue.is_a?(Integer))
86
+ one_timestamp = timevalue.utc.strftime("%s%L").to_i if (timevalue.is_a?(Time) || timevalue.is_a?(DateTime))
87
+ one_timestamp = Time.parse(timevalue).utc.strftime("%s%L").to_i if (timevalue.is_a?(String))
88
+
89
+ one_timestamp
90
+
91
+ end
92
+
93
+ end
94
+
95
+ end
96
+
97
+ end
@@ -0,0 +1,97 @@
1
+ module OEHClient::Meta::Entity
2
+
3
+ ###
4
+ ### ------------- Constants
5
+ ###
6
+
7
+ ONE_PARAM_DATA = "data"
8
+ ONE_PARAM_SUCCESS = "success"
9
+ ONE_PARAM_ID = "id"
10
+ ONE_PARAM_NAME = "name"
11
+ ONE_PARAM_CREATED_ON = "createdDate"
12
+ ONE_PARAM_CREATED_BY = "createdBy"
13
+
14
+ ONE_PARAM_ITEMS = "items"
15
+
16
+ ###
17
+ ### ------------- Class Attributes
18
+ ###
19
+
20
+ def entity_uri_stem=(uri_stem)
21
+ @entity_stem = uri_stem
22
+ end
23
+
24
+ def entity_uri_stem
25
+ @entity_stem
26
+ end
27
+
28
+ def session=(session_instance)
29
+ @session = session_instance
30
+ end
31
+
32
+ def session
33
+ @session
34
+ end
35
+
36
+ ###
37
+ ### ------------- Helper Class Methods
38
+ ###
39
+
40
+ def create()
41
+ end # def self.create
42
+
43
+ def find_by_name(active_session, name, **args)
44
+ get(active_session, {:name => ONE_PARAM_NAME, :value => name}, args)
45
+ end
46
+
47
+ ###
48
+ ### ------------- Core Class Methods
49
+ ###
50
+
51
+ def get_collection(active_session, **args)
52
+ # store the active session object for future use
53
+ self.session = active_session if (session.nil?)
54
+ # get the list of args
55
+ entity_uri = (args.has_key?(:space)) ? "workspaces/#{args[:space]}/#{entity_uri_stem}" : "#{entity_uri_stem}"
56
+ # construct the URL for retrieving the entity
57
+ url = "#{OEHClient::Helper::Request::ONE_PROTOCOL}#{self.session.space.host}/one/services/api/#{entity_uri}"
58
+ # set the header information
59
+ header = (!self.session.cookies.nil? ? {:cookies => self.session.cookies}.merge!(OEHClient::Helper::Request.default_JSON_header()) : OEHClient::Helper::Request.default_JSON_header())
60
+ # construct the request params using the header and params (if passed)
61
+ request_params = {:header => header}
62
+ request_params.merge!({:params => args[:params]}) if (args.has_key?(:params))
63
+ # GET the data
64
+ collection_response = OEHClient.get(url, nil, request_params)
65
+ # return the data object for valid requests or a blank array otherwise
66
+ ((collection_response.has_key?(:body) && collection_response[:body][ONE_PARAM_SUCCESS]) ? (collection_response[:body][ONE_PARAM_DATA].is_a?(Hash) ? collection_response[:body][ONE_PARAM_DATA][ONE_PARAM_ITEMS] : collection_response[:body][ONE_PARAM_DATA]) : [] )
67
+ end # def get_collection
68
+
69
+ def get(active_session, attribute_nvp, **args)
70
+ # store the active session object for future use
71
+ session = active_session if (session.nil?)
72
+ # initialize the entity instance as a blank hash
73
+ entity_instance = Hash.new
74
+ # Get the collection of objects requested
75
+ get_collection(session, **args).each do | collection_instance |
76
+ # find the matching entry and assign the entity instance
77
+ entity_instance = collection_instance if (collection_instance[attribute_nvp[:name]].casecmp(attribute_nvp[:value]) == 0)
78
+ end # Each OEHClient::Meta::Entity.get_collection
79
+ # return the copy of the entity instance data
80
+ entity_instance
81
+ end # def get
82
+
83
+ ###
84
+ ### ------------- Instance Attributes
85
+ ###
86
+
87
+ ###
88
+ ### ------------- Instance Methods
89
+ ###
90
+
91
+ ###
92
+ ### ------------- Protected Class Methods
93
+ ###
94
+
95
+ protected
96
+
97
+ end
@@ -0,0 +1,14 @@
1
+ class OEHClient::Meta::Interaction < OEHClient::Data::Node
2
+ include OEHClient::Meta::WorkspaceEntity
3
+
4
+ self.entity_uri_stem = "pageCfg/pages"
5
+
6
+
7
+ def self.create(workspace, data)
8
+ interaction_instance = OEHClient::Meta::Interaction.new(data)
9
+ interaction_instance.workspace = workspace
10
+
11
+ interaction_instance
12
+ end
13
+
14
+ end
@@ -0,0 +1,36 @@
1
+ class OEHClient::Meta::Session
2
+
3
+ attr_accessor :cookies, :space
4
+
5
+ def self.attach(space)
6
+ # post the login request
7
+ response = OEHClient.post(space.login_url, nil, :payload => space.meta_credentials)
8
+ # create a new session object
9
+ session_instance = OEHClient::Meta::Session.new()
10
+ # assign the space object
11
+ session_instance.space = space
12
+ # store the cookies if they are returned in the response
13
+ session_instance.cookies = response[:cookies] if (response.has_key?(:cookies))
14
+ # return the session instance
15
+ session_instance
16
+ end
17
+
18
+ def detach()
19
+ # construct a header object, merging cookies (if present) wit the default JSON header
20
+ header = Hash.new
21
+ header.merge!(:cookies => @cookies) unless (@cookies.blank?)
22
+ header.merge!(OEHClient::Helper::Request.default_JSON_header)
23
+ # post the logout request
24
+ OEHClient.post(@space.logout_url, nil, :header => header)
25
+ # remove the cookies if the logout is posted successfully
26
+ @cookies = nil
27
+ end
28
+
29
+ # retrieve the workspace meta-data object from the thinstance in realtime
30
+ def workspace(site_key)
31
+ # get the workspace object using the site key, the host value, and the exisitng cookies
32
+ OEHClient::Meta::Workspace.find_by_key(self, site_key)
33
+ end
34
+
35
+
36
+ end