oeh-client 2.2.1 → 2.2.2

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.
@@ -1,97 +0,0 @@
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
@@ -1,97 +0,0 @@
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
@@ -1,14 +0,0 @@
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
@@ -1,36 +0,0 @@
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
@@ -1,36 +0,0 @@
1
- class OEHClient::Meta::Touchpoint < OEHClient::Data::Node
2
- include OEHClient::Meta::WorkspaceEntity
3
-
4
- # tell the workspace entity module how to reference within ONE
5
- self.entity_uri_stem = "touchpoints"
6
-
7
- # create a new instance of the class using the data set and assig the workspace
8
- def self.create(workspace, data)
9
- # create from the past data structure
10
- touchpoint_instance = OEHClient::Meta::Touchpoint.new(data)
11
- # assign the local workspace object
12
- touchpoint_instance.workspace = workspace
13
- # return the instance
14
- touchpoint_instance
15
- end # self.create
16
-
17
- # retrieve the full collection of touchpoints from the curent workspace
18
- def interactions()
19
- # initialize the collection array
20
- interaction_collection = Array.new
21
- # retrieve the collection from ONE using the workspace reference and current touchpoint
22
- OEHClient::Meta::Interaction.get_collection(self.class.session, space: workspace.id, params: {:site => id}).each do | interaction_item |
23
- # create the instance of the interaction and add it to the collection
24
- interaction_collection << OEHClient::Meta::Interaction.create(workspace, interaction_item)
25
- end
26
- # return the collection to calling process
27
- interaction_collection
28
- end # end def interactions
29
-
30
- # retrieve a single touchpoint from the current workspace based on the name
31
- def interaction(interaction_name)
32
- # create and return the instance of an interaction based on the name, current workspace, and current touchpoint
33
- OEHClient::Meta::Interaction.create(workspace, OEHClient::Meta::Interaction.find_by_name(self.class.session, interaction_name, space: workspace.id, params: {:site => id}))
34
- end # def interaction
35
-
36
- end # class OEHClient::Meta::Touchpoint
@@ -1,58 +0,0 @@
1
- class OEHClient::Meta::Workspace < OEHClient::Data::Node
2
- extend OEHClient::Meta::Entity
3
-
4
- # set the ONE entity URI Stem for workspace requests
5
- self.entity_uri_stem = "workspaces"
6
-
7
- ###
8
- ### ------------- Constants
9
- ###
10
-
11
- ONE_WORKSPACE_SITE_KEY = "siteKey"
12
-
13
-
14
- ###
15
- ### ------------- Attributes
16
- ###
17
-
18
- ###
19
- ### ------------- Class Methods
20
- ###
21
-
22
- def self.find_by_key(active_session, site_key, **args)
23
- # default the workspace instance NIL
24
- workspace_instance = nil
25
- # get the list of workspaces from the thinstance
26
- workspace_data = get(active_session, {:name => ONE_WORKSPACE_SITE_KEY, :value => site_key}, **args)
27
- unless (workspace_data.blank?)
28
- # convert the the workspace instance into a NEW instance of the OEHClient::Meta::Workspace instance
29
- workspace_instance = OEHClient::Meta::Workspace.new(workspace_data)
30
- # set the session object
31
- # workspace_instance.session = session
32
- # return the workspace instance
33
- workspace_instance
34
- end # unless workspace_data.blank?
35
- end # def self.find_by_key
36
-
37
-
38
- ###
39
- ### ------------- Instance Methods
40
- ###
41
-
42
- # retrieve the full collection of touchpoints from the curent workspace
43
- def touchpoints()
44
- touchpoint_collection = Array.new
45
- OEHClient::Meta::Touchpoint.get_collection(self.class.session, space: id).each do | touchpoint_item |
46
- touchpoint_collection << OEHClient::Meta::Touchpoint.create(self, touchpoint_item)
47
- end
48
- touchpoint_collection
49
- end
50
-
51
- # retrieve a single touchpoint from the current workspace based on the name
52
- def touchpoint(touchpoint_name)
53
- OEHClient::Meta::Touchpoint.create(self, OEHClient::Meta::Touchpoint.find_by_name(self.class.session, touchpoint_name, space: id))
54
- end
55
-
56
-
57
-
58
- end
@@ -1,13 +0,0 @@
1
- module OEHClient::Meta::WorkspaceEntity
2
-
3
- def self.included base
4
- base.send :include, InstanceMethods
5
- base.send :extend, OEHClient::Meta::Entity
6
- end
7
-
8
- module InstanceMethods
9
-
10
- attr_accessor :workspace
11
- end
12
-
13
- end
@@ -1,14 +0,0 @@
1
-
2
- module OEHClient
3
-
4
- module Meta
5
- end
6
-
7
- end
8
-
9
- require File.dirname(__FILE__) + '/meta/entity'
10
- require File.dirname(__FILE__) + '/meta/workspace_entity'
11
- require File.dirname(__FILE__) + '/meta/session'
12
- require File.dirname(__FILE__) + '/meta/workspace'
13
- require File.dirname(__FILE__) + '/meta/touchpoint'
14
- require File.dirname(__FILE__) + '/meta/interaction'