oeh-client 0.2.0 → 0.2.1
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 +4 -4
- data/.gitignore +2 -1
- data/lib/oehclient/config/space.rb +41 -11
- data/lib/oehclient/meta/entity.rb +51 -0
- data/lib/oehclient/meta/workspace.rb +77 -0
- data/lib/oehclient/meta.rb +11 -0
- data/lib/oehclient/version.rb +1 -1
- data/lib/oehclient.rb +2 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54084e658360c3951949a193c23952f5dabca96f
|
4
|
+
data.tar.gz: 2757288cd34409759ca970ba100e810f6e47dac6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4aa2a59d7dd7137e65dc0acd8db6b789aceffb7d9507ac19f1b25fb7ed0a0df0aabe3b5a10d2b130681b54bc3d082f5c1af0762e12696c3e088504f9138d2f9a
|
7
|
+
data.tar.gz: 07f540d2b1f742e0d90827723ff1e2422378a1b32dc60fd84a27c2272b21cd7c0cb35904354acc545fe1dd2a173ae346fbc11f73ef57a6684382ced87750ad80
|
data/.gitignore
CHANGED
@@ -3,15 +3,27 @@ require 'rest-client'
|
|
3
3
|
|
4
4
|
class OEHClient::Config::Space
|
5
5
|
|
6
|
+
###
|
7
|
+
### ------------- Constants
|
8
|
+
###
|
9
|
+
|
10
|
+
|
11
|
+
###
|
12
|
+
### ------------- Attributes
|
13
|
+
###
|
14
|
+
|
6
15
|
attr_accessor :site_key, # The ONE Site KEY Value
|
7
16
|
:host, # The name of the HOST machine on thunderhead.com (ONEDEMO, EU2, NA4, etc..)
|
8
17
|
:api_key, # The API key provided in the ONE SETTINGS interface
|
9
18
|
:shared_secret, # The shared secret value provided in the ONE SETTINGS interface
|
10
19
|
:username, # The fully-qualified username configured for access to the space
|
11
20
|
:meta_password, # The password needed to access meta-data from the OEH server
|
12
|
-
:cookies # The cookies returned from an OEH API request
|
21
|
+
:cookies # The cookies returned from an OEH API request
|
22
|
+
|
23
|
+
###
|
24
|
+
### ------------- Class Methods
|
25
|
+
###
|
13
26
|
|
14
|
-
# ---- Class Methods
|
15
27
|
|
16
28
|
# create builds a new instance of the Site class, populats the attributes using the properties HASH provided
|
17
29
|
# and returns an instance of the class.
|
@@ -34,7 +46,10 @@ class OEHClient::Config::Space
|
|
34
46
|
end
|
35
47
|
|
36
48
|
|
37
|
-
|
49
|
+
###
|
50
|
+
### ------------- Instance Methods
|
51
|
+
###
|
52
|
+
|
38
53
|
|
39
54
|
# token is the method used to generate a new OAuth::AccessToken object based on the configuration of
|
40
55
|
# the related space
|
@@ -79,30 +94,45 @@ class OEHClient::Config::Space
|
|
79
94
|
def meta_credentials()
|
80
95
|
{:username => @username, :password => @meta_password, :rememberMe => "false"}
|
81
96
|
end # def meta_credentials
|
82
|
-
|
97
|
+
# return the URL for the posting a login request
|
83
98
|
def login_url()
|
84
99
|
"#{OEHClient::Helper::Request::ONE_PROTOCOL}#{@host}#{OEHClient::Helper::Request::THUNDERHEAD_DOMAIN}/one/idm_login"
|
85
100
|
end # def login_url
|
86
|
-
|
101
|
+
# return the URL for posting a logout request
|
87
102
|
def logout_url()
|
88
103
|
"#{OEHClient::Helper::Request::ONE_PROTOCOL}#{@host}#{OEHClient::Helper::Request::THUNDERHEAD_DOMAIN}/one/logout"
|
89
104
|
end
|
90
105
|
|
91
106
|
# logon to the OEH thinstance with the existing credentials
|
92
107
|
def login()
|
108
|
+
# post the login request
|
93
109
|
response = OEHClient.post(login_url, nil, :payload => meta_credentials)
|
94
|
-
|
110
|
+
# store the cookies if they are returned in the response
|
111
|
+
@cookies = response[:cookies] if (response.has_key?(:cookies))
|
95
112
|
end
|
96
113
|
|
114
|
+
# logout of the OEH thinstance and remove the current cookie references
|
97
115
|
def logout()
|
116
|
+
# construct a header object, merging cookies (if present) wit the default JSON header
|
98
117
|
header = Hash.new
|
99
|
-
header.merge!(:cookies => @cookies)
|
118
|
+
header.merge!(:cookies => @cookies) unless (@cookies.blank?)
|
100
119
|
header.merge!(OEHClient::Helper::Request.default_JSON_header)
|
120
|
+
# post the logout request
|
121
|
+
OEHClient.post(logout_url, nil, :header => header)
|
122
|
+
# remove the cookies if the logout is posted successfully
|
123
|
+
@cookies = nil
|
124
|
+
end
|
101
125
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
@cookies
|
126
|
+
# retrieve the workspace meta-data object from the thinstance in realtime
|
127
|
+
def workspace()
|
128
|
+
# if the cookies are currently NIL then login using the existing credentials
|
129
|
+
login() if (@cookies.nil?)
|
130
|
+
# get the workspace object using the site key, the host value, and the exisitng cookies
|
131
|
+
workspace_instance = OEHClient::Meta::Workspace.fetch(@site_key, @host, :cookies => @cookies)
|
132
|
+
# assign the current space to the workspace instance
|
133
|
+
workspace_instance.space = self
|
134
|
+
# return the workspace instance object
|
135
|
+
workspace_instance
|
106
136
|
end
|
107
137
|
|
108
138
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class OEHClient::Meta::Entity
|
2
|
+
|
3
|
+
###
|
4
|
+
### ------------- Constants
|
5
|
+
###
|
6
|
+
|
7
|
+
###
|
8
|
+
### ------------- Attributes
|
9
|
+
###
|
10
|
+
attr_accessor :space # The configured OEHClient::Config::Space object that represents the OEH workspace
|
11
|
+
|
12
|
+
|
13
|
+
###
|
14
|
+
### ------------- Class Methods
|
15
|
+
###
|
16
|
+
|
17
|
+
def self.create()
|
18
|
+
end # def self.create
|
19
|
+
|
20
|
+
def self.fetch(space, entity_type)
|
21
|
+
|
22
|
+
url = "#{OEHClient::Helper::Request::ONE_PROTOCOL}#{space.host}#{OEHClient::Helper::Request::THUNDERHEAD_DOMAIN}/one/services/api/#{entity_type.downcase.pluralize}"
|
23
|
+
|
24
|
+
header = (!space.cookies.nil? ? {:cookies => space.cookies}.merge!(OEHClient::Helper::Request.default_JSON_header()) : OEHClient::Helper::Request.default_JSON_header())
|
25
|
+
|
26
|
+
response = OEHClient.get(url, nil, :header => header)
|
27
|
+
|
28
|
+
puts "FETCH #{entity_type} response: #{response[:body]}"
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
###
|
33
|
+
### ------------- Instance Methods
|
34
|
+
###
|
35
|
+
|
36
|
+
# add_attribute dynamically creates an attr_accessor for the passed key_value pair either
|
37
|
+
# as a simple value attribute or as an instance of another Node class
|
38
|
+
def add_attribute(name, value)
|
39
|
+
|
40
|
+
# generate a ruby-friendly attribute accessor based on the name of the
|
41
|
+
# structure attribute
|
42
|
+
accessor_name = name.underscore
|
43
|
+
accessor_name.gsub!(/( )/, '_') if (accessor_name.match(/\s/))
|
44
|
+
# create the accessor in the current class and set the value based on the type
|
45
|
+
# of object that represents the value
|
46
|
+
self.class.send(:attr_accessor, accessor_name)
|
47
|
+
instance_variable_set("@#{accessor_name}", (value.kind_of?(Hash) ? OEHClient::Data::Node.new(value) : value))
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
class OEHClient::Meta::Workspace
|
2
|
+
|
3
|
+
###
|
4
|
+
### ------------- Constants
|
5
|
+
###
|
6
|
+
|
7
|
+
ONE_PARAM_DATA = "data"
|
8
|
+
ONE_PARAM_NAME = "name"
|
9
|
+
ONE_PARAM_SITE_KEY = "siteKey"
|
10
|
+
ONE_PARAM_ID = "id"
|
11
|
+
ONE_PARAM_CREATED_ON = "createdDate"
|
12
|
+
ONE_PARAM_CREATED_BY = "createdBy"
|
13
|
+
ONE_PARAM_CONTROL_GROUP = "controlGroup"
|
14
|
+
ONE_PARAM_ADMIN_ROLE = "adminRole"
|
15
|
+
|
16
|
+
###
|
17
|
+
### ------------- Attributes
|
18
|
+
###
|
19
|
+
attr_accessor :name, # The name of the workspace
|
20
|
+
:id, # The internal ID of the workspace
|
21
|
+
:created_on, # The date and time the workspace was created
|
22
|
+
:created_by, # The user that created the workspace
|
23
|
+
:control_group, # The percentage of the control groupd setting
|
24
|
+
:admin_role, # boolean value that determins if the current user is identified
|
25
|
+
# as an admin of the workspace
|
26
|
+
:space # The related OEHClient::Config::Space object
|
27
|
+
|
28
|
+
|
29
|
+
###
|
30
|
+
### ------------- Class Methods
|
31
|
+
###
|
32
|
+
|
33
|
+
def self.create()
|
34
|
+
end # def self.create
|
35
|
+
|
36
|
+
def self.fetch(site_key, host, *args)
|
37
|
+
# retrieved the passed options from the SPLAT
|
38
|
+
options = (args.length > 0 ? args[0] : Hash.new)
|
39
|
+
# default the workspace instance NIL
|
40
|
+
workspace_instance = nil
|
41
|
+
# construnct the URL for getting the workspaces from the current thinstance
|
42
|
+
url = "#{OEHClient::Helper::Request::ONE_PROTOCOL}#{host}#{OEHClient::Helper::Request::THUNDERHEAD_DOMAIN}/one/services/api/workspaces"
|
43
|
+
# construct a header using the space cookies or just with the default JSON header
|
44
|
+
header = (options.has_key?(:cookies) ? {:cookies => options[:cookies]}.merge!(OEHClient::Helper::Request.default_JSON_header()) : OEHClient::Helper::Request.default_JSON_header())
|
45
|
+
# get the list of workspaces from the thinstance
|
46
|
+
response = OEHClient.get(url, nil, :header => header)
|
47
|
+
# constinue only if we have a :body component of the resposne
|
48
|
+
if (response.has_key?(:body))
|
49
|
+
# for each fo the workspaces, grab the individual data
|
50
|
+
response[:body][ONE_PARAM_DATA].each do | workspace_data |
|
51
|
+
# look for workspace that maches the passed site key
|
52
|
+
unless (workspace_data[ONE_PARAM_SITE_KEY].casecmp(site_key) == 0)
|
53
|
+
# convert the the workspace instance into a NEW instance of the OEHClient::Meta::Workspace class
|
54
|
+
workspace_instance = OEHClient::Meta::Workspace.new
|
55
|
+
# map all the attributes of the workspace data to the new OEHClient::Meta::Workspace
|
56
|
+
# object
|
57
|
+
workspace_instance.name = workspace_data[ONE_PARAM_NAME]
|
58
|
+
workspace_instance.id = workspace_data[ONE_PARAM_ID]
|
59
|
+
workspace_instance.created_on = Time.at(workspace_data[ONE_PARAM_CREATED_ON]/1000)
|
60
|
+
workspace_instance.created_by = workspace_data[ONE_PARAM_CREATED_BY][ONE_PARAM_NAME]
|
61
|
+
workspace_instance.control_group = workspace_data[ONE_PARAM_CONTROL_GROUP]
|
62
|
+
workspace_instance.admin_role = workspace_data[ONE_PARAM_ADMIN_ROLE]
|
63
|
+
# break out of the look since we found our workspace data
|
64
|
+
break
|
65
|
+
end # unless
|
66
|
+
end # do each data element
|
67
|
+
end # if response has body
|
68
|
+
# return the workspace instance
|
69
|
+
workspace_instance
|
70
|
+
end # def self.fetch
|
71
|
+
|
72
|
+
###
|
73
|
+
### ------------- Instance Methods
|
74
|
+
###
|
75
|
+
|
76
|
+
|
77
|
+
end
|
data/lib/oehclient/version.rb
CHANGED
data/lib/oehclient.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oeh-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Balliet
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -168,6 +168,9 @@ files:
|
|
168
168
|
- lib/oehclient/interaction.rb
|
169
169
|
- lib/oehclient/interaction/interaction.rb
|
170
170
|
- lib/oehclient/interaction/optimization.rb
|
171
|
+
- lib/oehclient/meta.rb
|
172
|
+
- lib/oehclient/meta/entity.rb
|
173
|
+
- lib/oehclient/meta/workspace.rb
|
171
174
|
- lib/oehclient/version.rb
|
172
175
|
- oeh-client.gemspec
|
173
176
|
homepage: https://rubygems.org/gems/oeh-client
|