cts-mpx 1.0.3 → 1.1.0
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/.rubocop.yml +8 -0
- data/EXAMPLES.md +17 -5
- data/Gemfile.lock +3 -3
- data/Guardfile +19 -22
- data/config/web_services.json +2 -2
- data/cts-mpx.gemspec +1 -1
- data/lib/cts/mpx.rb +5 -7
- data/lib/cts/mpx/driver.rb +21 -19
- data/lib/cts/mpx/driver/assemblers.rb +10 -24
- data/lib/cts/mpx/driver/connections.rb +27 -16
- data/lib/cts/mpx/driver/exceptions.rb +6 -3
- data/lib/cts/mpx/driver/helpers.rb +1 -1
- data/lib/cts/mpx/driver/page.rb +1 -1
- data/lib/cts/mpx/driver/request.rb +1 -0
- data/lib/cts/mpx/driver/response.rb +10 -22
- data/lib/cts/mpx/entries.rb +7 -14
- data/lib/cts/mpx/entry.rb +16 -18
- data/lib/cts/mpx/field.rb +6 -5
- data/lib/cts/mpx/fields.rb +4 -1
- data/lib/cts/mpx/query.rb +3 -8
- data/lib/cts/mpx/registry.rb +3 -2
- data/lib/cts/mpx/service.rb +2 -0
- data/lib/cts/mpx/services.rb +1 -1
- data/lib/cts/mpx/services/data.rb +5 -6
- data/lib/cts/mpx/services/ingest.rb +1 -0
- data/lib/cts/mpx/user.rb +3 -1
- data/lib/cts/mpx/validators.rb +1 -0
- data/lib/cts/mpx/version.rb +1 -1
- data/uml.nomnoml +2 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7972d6219f8ea4529c9dc0863e85417d0948cb0c
|
4
|
+
data.tar.gz: 40b45a11bd0f15d0ebf9ecddb3ba74b7da06ac3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7eb12fb8ae45a387aa7599171b387a4412a0bd4ee4ec4fe5481b812c1fa3c2cece788a1d771630a162026ad004816e30b91f1bd6d369e58b8bcc5050b74d6ca6
|
7
|
+
data.tar.gz: 55392ff698ab16f63c8b6de195623e06d293ebf63083b3e983b2d002a36fd6168ec4f59fff6065b3ed69e36717efc9312ec4064c34324e950f16ac16cc0ba783
|
data/.rubocop.yml
CHANGED
@@ -55,6 +55,11 @@ Style/FrozenStringLiteralComment:
|
|
55
55
|
Style/MixinUsage:
|
56
56
|
Exclude:
|
57
57
|
- 'bin/*'
|
58
|
+
- 'spec/spec_helper_shared_examples.rb'
|
59
|
+
|
60
|
+
# it's about the line count, and white space on the left.
|
61
|
+
Style/ClassAndModuleChildren:
|
62
|
+
Enabled: false
|
58
63
|
|
59
64
|
# Purty hashes.
|
60
65
|
Layout/AlignHash:
|
@@ -84,5 +89,8 @@ Metrics/ParameterLists:
|
|
84
89
|
RSpec/NamedSubject:
|
85
90
|
Enabled: false
|
86
91
|
|
92
|
+
RSpec/DescribeSymbol:
|
93
|
+
Enabled: false
|
94
|
+
|
87
95
|
Lint/Debugger:
|
88
96
|
Enabled: false
|
data/EXAMPLES.md
CHANGED
@@ -13,8 +13,7 @@ account = 'http://access.auth.theplatform.com/data/Account/1'
|
|
13
13
|
### Login
|
14
14
|
|
15
15
|
``` ruby
|
16
|
-
user = Cts::Mpx::User.create
|
17
|
-
user.sign_in
|
16
|
+
user = Cts::Mpx::User.create(username: ENV["MPX_USERNAME"], password: ENV["MPX_PASSWORD"]).sign_in
|
18
17
|
```
|
19
18
|
|
20
19
|
### Logout
|
@@ -38,7 +37,7 @@ puts response.status
|
|
38
37
|
|
39
38
|
``` ruby
|
40
39
|
response = Cts::Mpx::Services::Data.get user: user, service: 'Media Data Service', endpoint: 'Media', account: account, fields: 'id,guid'
|
41
|
-
puts response.page
|
40
|
+
puts response.page.entries
|
42
41
|
```
|
43
42
|
|
44
43
|
### POST
|
@@ -57,7 +56,7 @@ Cts::Mpx::Services::Data.put user: user, service: 'Media Data Service', endpoin
|
|
57
56
|
|
58
57
|
``` ruby
|
59
58
|
response = Cts::Mpx::Services::Data.delete user: user, service: 'Media Data Service', endpoint: 'Media', account: account, fields: 'id,guid', ids: "1,2,3,4"
|
60
|
-
puts response.page
|
59
|
+
puts response.page.entries
|
61
60
|
```
|
62
61
|
|
63
62
|
## Page class
|
@@ -78,4 +77,17 @@ puts page.to_s
|
|
78
77
|
|
79
78
|
``` ruby
|
80
79
|
puts page.to_s(true)
|
81
|
-
```
|
80
|
+
```
|
81
|
+
|
82
|
+
## Query
|
83
|
+
|
84
|
+
``` ruby
|
85
|
+
media_query = Query.create({
|
86
|
+
account_id: "http://access.auth.theplatform.com/data/Account/2034777617",
|
87
|
+
service: 'Media Data Service',
|
88
|
+
endpoint: 'Media',
|
89
|
+
fields: 'id,guid,title,ownerId'
|
90
|
+
}).run user: user
|
91
|
+
|
92
|
+
media_query.entries
|
93
|
+
```
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cts-mpx (1.0.
|
5
|
-
creatable
|
4
|
+
cts-mpx (1.0.3)
|
5
|
+
creatable (~> 2.2.1)
|
6
6
|
excon
|
7
7
|
oj (= 3.5.0)
|
8
8
|
|
@@ -15,7 +15,7 @@ GEM
|
|
15
15
|
debug_inspector (>= 0.0.1)
|
16
16
|
bump (0.6.1)
|
17
17
|
coderay (1.1.2)
|
18
|
-
creatable (2.
|
18
|
+
creatable (2.2.1)
|
19
19
|
debug_inspector (0.0.3)
|
20
20
|
diff-lcs (1.3)
|
21
21
|
docile (1.3.1)
|
data/Guardfile
CHANGED
@@ -1,41 +1,38 @@
|
|
1
1
|
clearing :on
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
guard :bundler do
|
4
|
+
require 'guard/bundler'
|
5
|
+
require 'guard/bundler/verify'
|
6
|
+
helper = Guard::Bundler::Verify.new
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
files = ['Gemfile']
|
9
|
+
files += Dir['*.gemspec'] if files.any? { |f| helper.uses_gemspec?(f) }
|
10
10
|
|
11
|
-
#
|
12
|
-
|
13
|
-
|
11
|
+
# Assume files are symlinked from somewhere
|
12
|
+
files.each { |file| watch(helper.real_path(file)) }
|
13
|
+
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
guard :rubocop, cli: '-fs --color -S -a' do
|
16
|
+
watch(%r{.+\.rb$}) { |m| File.dirname(m[0]) }
|
17
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
18
|
+
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
guard 'yard', server: false do
|
21
|
+
watch(%r{app\/.+\.rb})
|
22
|
+
watch(%r{lib\/.+\.rb})
|
23
|
+
watch(%r{ext\/.+\.c})
|
24
|
+
end
|
25
25
|
|
26
26
|
guard :rspec, cmd: "bundle exec rspec" do
|
27
27
|
require "guard/rspec/dsl"
|
28
28
|
dsl = Guard::RSpec::Dsl.new(self)
|
29
29
|
|
30
|
-
# Feel free to open issues for suggestions and improvements
|
31
|
-
|
32
|
-
# RSpec files
|
33
30
|
rspec = dsl.rspec
|
34
31
|
watch(rspec.spec_helper) { rspec.spec_dir }
|
35
32
|
watch(rspec.spec_support) { rspec.spec_dir }
|
33
|
+
watch(%r{spec\/spec_*}) { rspec.spec_dir }
|
36
34
|
watch(rspec.spec_files)
|
37
35
|
|
38
|
-
# Ruby files
|
39
36
|
ruby = dsl.ruby
|
40
37
|
dsl.watch_spec_files_for(ruby.lib_files)
|
41
38
|
end
|
data/config/web_services.json
CHANGED
data/cts-mpx.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.require_paths = ["lib"]
|
18
18
|
spec.required_ruby_version = '>= 2.4.0'
|
19
19
|
|
20
|
-
spec.add_runtime_dependency "creatable"
|
20
|
+
spec.add_runtime_dependency "creatable", "~> 2.2.1"
|
21
21
|
spec.add_runtime_dependency "excon"
|
22
22
|
spec.add_runtime_dependency "oj", "3.5.0"
|
23
23
|
|
data/lib/cts/mpx.rb
CHANGED
@@ -32,11 +32,9 @@ require 'cts/mpx/entry'
|
|
32
32
|
require 'cts/mpx/entries'
|
33
33
|
require 'cts/mpx/query'
|
34
34
|
|
35
|
-
# Comcast Technical Solutions
|
36
|
-
module Cts
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
Registry.initialize
|
41
|
-
end
|
35
|
+
# Comcast Technical Solutions - Mpx
|
36
|
+
module Cts::Mpx
|
37
|
+
Services.initialize
|
38
|
+
Registry.initialize
|
39
|
+
Driver::Connections.initialize
|
42
40
|
end
|
data/lib/cts/mpx/driver.rb
CHANGED
@@ -4,43 +4,45 @@ module Cts
|
|
4
4
|
module Driver
|
5
5
|
module_function
|
6
6
|
|
7
|
-
#
|
7
|
+
# used when the token has a problem
|
8
|
+
class TokenError < RuntimeError
|
9
|
+
end
|
10
|
+
|
11
|
+
# used when the login credentials are incorrect
|
12
|
+
class CredentialsError < RuntimeError
|
13
|
+
end
|
14
|
+
|
15
|
+
# used when the services cannot be communicated with
|
16
|
+
class ConnectionError < RuntimeError
|
17
|
+
end
|
18
|
+
|
19
|
+
# used when the service returns an exception
|
20
|
+
class ServiceError < RuntimeError
|
21
|
+
end
|
22
|
+
|
8
23
|
# path to our gem directory, includes support for bundled env's.
|
9
|
-
#
|
10
24
|
# @return [String] full path to the root of our gem directory.
|
11
|
-
#
|
12
25
|
def gem_dir
|
13
26
|
return Dir.pwd unless Gem.loaded_specs.include? 'cts-mpx'
|
27
|
+
|
14
28
|
Gem.loaded_specs['cts-mpx'].full_gem_path
|
15
29
|
end
|
16
30
|
|
17
|
-
#
|
18
31
|
# path to our config files
|
19
|
-
#
|
20
32
|
# @return [String] full path to the root of our gem directory.
|
21
|
-
#
|
22
33
|
def config_dir
|
23
34
|
"#{gem_dir}/config"
|
24
35
|
end
|
25
36
|
|
26
|
-
#
|
27
37
|
# load a json file into a simple hash
|
28
|
-
#
|
29
38
|
# @param [String] filename filename to load
|
30
|
-
#
|
31
39
|
# @raise [RuntimeError] if the filename does not exist.
|
32
40
|
# @raise [RuntimeError] if the file cannot be parsed, supplies the exception.
|
33
|
-
#
|
34
41
|
# @return [Hash] data from the file
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
begin
|
40
|
-
Oj.load File.read filename
|
41
|
-
rescue Oj::ParseError => exception
|
42
|
-
raise "#{filename}: #{exception.message}"
|
43
|
-
end
|
42
|
+
def parse_json(string)
|
43
|
+
Oj.compat_load string
|
44
|
+
rescue Oj::ParseError => exception
|
45
|
+
raise "#{string}: #{exception.message}"
|
44
46
|
end
|
45
47
|
end
|
46
48
|
end
|
@@ -62,32 +62,18 @@ module Cts
|
|
62
62
|
|
63
63
|
service = Services[].find { |s| s.name == service && s.endpoints.include?(endpoint) }
|
64
64
|
|
65
|
-
h = {
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
h.merge!(token: user.token, schema: service.endpoints[endpoint]['schema'], form: service.form)
|
71
|
-
end
|
65
|
+
h = {
|
66
|
+
schema: service.type == 'data' ? service.schema : service.endpoints[endpoint]['schema'],
|
67
|
+
form: service.form,
|
68
|
+
token: user.token
|
69
|
+
}
|
72
70
|
|
73
71
|
h[:account] = account_id if account_id
|
74
|
-
h
|
75
|
-
h
|
76
|
-
h
|
77
|
-
|
78
|
-
|
79
|
-
# Assembles range, count, entries, sort into a query
|
80
|
-
# @param [String] range string (service) format of a range.
|
81
|
-
# @param [TrueFalse] count ask for a count of objects from the services.
|
82
|
-
# @param [TrueFalse] entries return an array of entries.
|
83
|
-
# @param [String] sort set the sort field
|
84
|
-
# @return [Hash] assembled query for a data call
|
85
|
-
def query_data(range: nil, count: nil, entries: nil, sort: nil)
|
86
|
-
h = {}
|
87
|
-
h.store :range, range if range
|
88
|
-
h.store :count, count if count
|
89
|
-
h.store :entries, entries if entries
|
90
|
-
h.store :sort, sort if sort
|
72
|
+
h[:count] = count if count
|
73
|
+
h[:entries] = entries if entries
|
74
|
+
h[:range] = range if range
|
75
|
+
h[:sort] = sort if sort
|
76
|
+
h[:query]&.merge! query if query.any?
|
91
77
|
h
|
92
78
|
end
|
93
79
|
end
|
@@ -1,40 +1,51 @@
|
|
1
1
|
module Cts
|
2
2
|
module Mpx
|
3
3
|
module Driver
|
4
|
-
#
|
5
4
|
# Container for active connections to the data service.
|
6
|
-
#
|
7
5
|
module Connections
|
8
6
|
module_function
|
9
7
|
|
10
|
-
#
|
11
8
|
# Addressable method for active connections. If you provide a string that is not active, an active one
|
12
9
|
# will be created.
|
13
|
-
#
|
14
10
|
# @param [String] uri uri of a service to connect to, must contain theplatform.
|
15
|
-
#
|
16
11
|
# @return [Excon] assembled excon objects with service defaults.
|
17
12
|
# @return [Excon[]] if nil, an array of all open connections.
|
18
|
-
#
|
19
13
|
def [](uri = nil)
|
20
|
-
return @
|
14
|
+
return @collection unless uri
|
15
|
+
|
21
16
|
begin
|
22
17
|
parsed_uri = URI.parse uri
|
23
18
|
rescue URI::InvalidURIError
|
24
|
-
raise ArgumentError, "#{uri} is not a uri"
|
19
|
+
raise ArgumentError, "(#{uri}) is not a uri"
|
25
20
|
end
|
26
21
|
|
27
|
-
raise ArgumentError, "#{uri} does not contain theplatform in it." unless parsed_uri.host
|
22
|
+
raise ArgumentError, "(#{uri}) does not contain theplatform in it." unless parsed_uri.host&.include? "theplatform"
|
23
|
+
|
24
|
+
c = create_connection parsed_uri unless @collection.include? parsed_uri.host
|
25
|
+
@collection.push c
|
26
|
+
@collection.last
|
27
|
+
c
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
+
def create_connection(parsed_uri)
|
31
|
+
Excon.new([parsed_uri.scheme, parsed_uri.host].join("://"), persistent: true)
|
30
32
|
end
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
def collection
|
35
|
+
@collection
|
36
|
+
end
|
37
|
+
|
38
|
+
def initialize
|
39
|
+
Excon.defaults[:omit_nil] = true
|
40
|
+
Excon.defaults[:persistent] = true
|
41
|
+
Excon.defaults[:headers] = {
|
42
|
+
'Content-Type' => "application/json",
|
43
|
+
"User-Agent" => "cts-mpx ruby sdk version #{Cts::Mpx::VERSION}",
|
44
|
+
'Content-Encoding' => 'bzip2,xz,gzip,deflate'
|
45
|
+
}
|
46
|
+
|
47
|
+
@collection = []
|
48
|
+
end
|
38
49
|
end
|
39
50
|
end
|
40
51
|
end
|
@@ -20,7 +20,7 @@ module Cts
|
|
20
20
|
# @raise [ArgumentError] if the argument is not of the correct type
|
21
21
|
# @return [nil]
|
22
22
|
def raise_unless_argument_error?(data, type = nil, &block)
|
23
|
-
raise(ArgumentError, "#{data} is not a valid #{type}") if Validators.argument_error?(data, type, &block)
|
23
|
+
raise(ArgumentError, "#{data || 'nil'} is not a valid #{type}") if Validators.argument_error?(data, type, &block)
|
24
24
|
|
25
25
|
nil
|
26
26
|
end
|
@@ -39,8 +39,11 @@ module Cts
|
|
39
39
|
# @param [Object] keyword keyword to assure is supplied
|
40
40
|
# @raise [ArgumentError] if the keyword is not suppplied
|
41
41
|
# @return [nil]
|
42
|
-
def raise_unless_required_keyword?(keyword
|
43
|
-
|
42
|
+
def raise_unless_required_keyword?(a_binding, keyword)
|
43
|
+
value = a_binding.local_variable_get(keyword)
|
44
|
+
raise ArgumentError, "#{keyword} is a required keyword." unless value
|
45
|
+
|
46
|
+
nil
|
44
47
|
end
|
45
48
|
end
|
46
49
|
end
|
@@ -58,7 +58,7 @@ module Cts
|
|
58
58
|
# @return [nil] nil
|
59
59
|
#
|
60
60
|
def required_arguments(keywords, a_binding)
|
61
|
-
keywords.each { |
|
61
|
+
keywords.each { |keyword| Exceptions.raise_unless_required_keyword?(a_binding, keyword) }
|
62
62
|
nil
|
63
63
|
end
|
64
64
|
end
|
data/lib/cts/mpx/driver/page.rb
CHANGED
@@ -1,68 +1,56 @@
|
|
1
1
|
module Cts
|
2
2
|
module Mpx
|
3
3
|
module Driver
|
4
|
-
#
|
5
4
|
# Class to contain a response from the services, has a few helper methods to make reading the data easier.
|
6
|
-
#
|
5
|
+
# @!attribute original
|
6
|
+
# @return [Excon::Response] copy of the original excon response.
|
7
7
|
class Response
|
8
8
|
include Creatable
|
9
|
-
|
10
|
-
# @!attribute original
|
11
|
-
# @return [Excon::Response] copy of the original excon response.
|
12
9
|
attribute name: 'original', kind_of: Excon::Response
|
13
10
|
|
14
|
-
#
|
15
11
|
# Hash output of the data returned from the services.
|
16
|
-
#
|
17
12
|
# @return [Hash] Hash including keys specific to the service and type of service.
|
18
|
-
#
|
19
13
|
def data
|
20
14
|
return @data if @data
|
21
15
|
|
22
16
|
raise 'response does not appear to be healthy' unless healthy?
|
23
17
|
|
18
|
+
# TODO: make the driver.load file become load string.
|
24
19
|
begin
|
25
|
-
@data = Oj.
|
20
|
+
@data = Oj.compat_load(original.body)
|
26
21
|
rescue Oj::ParseError => e
|
27
22
|
raise "could not parse data: #{e}"
|
28
23
|
end
|
24
|
+
|
25
|
+
raise ServiceError, "title: #{@data['title']} description: #{@data['description']} cid: (#{@data['correlationId']})" if @data['isException']
|
26
|
+
|
29
27
|
@data
|
30
28
|
end
|
31
29
|
|
32
|
-
#
|
33
30
|
# Is the response healthy? did it have a status code outside 2xx or 3xx.
|
34
|
-
#
|
35
31
|
# @return [TrueFalse] false if status <= 199 or => 400, otherwise true.
|
36
|
-
#
|
37
32
|
def healthy?
|
38
33
|
return false if status <= 199 || status >= 400
|
34
|
+
|
39
35
|
true
|
40
36
|
end
|
41
37
|
|
42
|
-
#
|
43
38
|
# Does this response contain a service exception
|
44
|
-
#
|
45
39
|
# @return [TrueFalse] true if it does, false if it does not.
|
46
|
-
#
|
47
40
|
def service_exception?
|
48
|
-
|
41
|
+
original.body.include? '"isException":true,'
|
49
42
|
end
|
50
43
|
|
51
|
-
#
|
52
44
|
# a page of data, processes the response.data for any entries.
|
53
|
-
#
|
54
45
|
# @return [Cts::Mpx::Driver::Page] a page of data.
|
55
|
-
#
|
56
46
|
def page
|
57
47
|
raise 'response does not appear to be healthy' unless healthy?
|
48
|
+
|
58
49
|
Cts::Mpx::Driver::Page.create entries: data['entries'], xmlns: data['$xmlns']
|
59
50
|
end
|
60
51
|
|
61
|
-
#
|
62
52
|
# Status code of the response
|
63
|
-
#
|
64
53
|
# @return [Fixnum] http status code
|
65
|
-
#
|
66
54
|
def status
|
67
55
|
original.status || nil
|
68
56
|
end
|
data/lib/cts/mpx/entries.rb
CHANGED
@@ -11,19 +11,6 @@ module Cts
|
|
11
11
|
|
12
12
|
attribute name: 'collection', kind_of: Array
|
13
13
|
|
14
|
-
# Create a new entries collection from a page
|
15
|
-
# @param [Page] page the page object to process
|
16
|
-
# @raise [ArgumentError] if :page is not available
|
17
|
-
# @return [Entries] a new entries collection
|
18
|
-
def self.create_from_page(page)
|
19
|
-
Exceptions.raise_unless_argument_error? page, Page
|
20
|
-
entries = page.entries.each do |e|
|
21
|
-
entry = Entry.create(fields: Fields.create_from_data(data: e, xmlns: page.xmlns))
|
22
|
-
entry.id = entry.fields['id'] if entry.fields['id']
|
23
|
-
end
|
24
|
-
Entries.create(collection: entries)
|
25
|
-
end
|
26
|
-
|
27
14
|
# Addressable method, indexed by entry object
|
28
15
|
# @param [Entry] key the entry to return
|
29
16
|
# @return [Self.collection,Entry,nil] Can return the collection, a single entry, or nil if nothing found
|
@@ -81,7 +68,13 @@ module Cts
|
|
81
68
|
# A hash of all available entries
|
82
69
|
# @return [Hash]
|
83
70
|
def to_h
|
84
|
-
|
71
|
+
output = { xmlns: {}, entries: [] }
|
72
|
+
|
73
|
+
each do |entry|
|
74
|
+
output[:entries].push entry.to_h[:entry]
|
75
|
+
output[:xmlns].merge! entry.fields.xmlns
|
76
|
+
end
|
77
|
+
output
|
85
78
|
end
|
86
79
|
end
|
87
80
|
end
|
data/lib/cts/mpx/entry.rb
CHANGED
@@ -16,7 +16,6 @@ module Cts
|
|
16
16
|
# @return [Entry] the resulting entry
|
17
17
|
def self.load_by_id(user: nil, id: nil, fields: nil, account_id: nil)
|
18
18
|
Driver::Helpers.required_arguments %i[user id], binding
|
19
|
-
|
20
19
|
Driver::Exceptions.raise_unless_argument_error? user, User
|
21
20
|
Driver::Exceptions.raise_unless_reference? id
|
22
21
|
|
@@ -28,13 +27,12 @@ module Cts
|
|
28
27
|
|
29
28
|
# Return the id of the entry.
|
30
29
|
# @return [Entry] the resulting entry
|
31
|
-
|
32
|
-
fields['id']
|
33
|
-
end
|
30
|
+
attr_reader :id
|
34
31
|
|
35
32
|
# Set the id of the entry, will check if it's a valid reference.
|
36
33
|
# @param [String] account_id account_id to set the entry to
|
37
34
|
# @return [Entry] the resulting entry
|
35
|
+
# TODO add a spec here to assure @id is set to id
|
38
36
|
def id=(id)
|
39
37
|
if id.nil?
|
40
38
|
fields.remove 'id'
|
@@ -42,7 +40,7 @@ module Cts
|
|
42
40
|
else
|
43
41
|
Driver::Exceptions.raise_unless_reference? id
|
44
42
|
result = Services.from_url id
|
45
|
-
fields['id'] = id
|
43
|
+
@id = fields['id'] = id
|
46
44
|
@service = result[:service]
|
47
45
|
@endpoint = result[:endpoint]
|
48
46
|
end
|
@@ -68,8 +66,7 @@ module Cts
|
|
68
66
|
# @param [String] fields comma delimited list of fields to collect
|
69
67
|
# @return [Driver::Response] Response of the call.
|
70
68
|
def load(user: nil, fields: nil, account_id: 'urn:theplatform:auth:root')
|
71
|
-
Driver::
|
72
|
-
|
69
|
+
Driver::Exceptions.raise_unless_required_keyword? binding, :user
|
73
70
|
Driver::Exceptions.raise_unless_argument_error? user, User
|
74
71
|
Driver::Exceptions.raise_unless_argument_error? fields, String if fields
|
75
72
|
Driver::Exceptions.raise_unless_reference? id
|
@@ -77,9 +74,11 @@ module Cts
|
|
77
74
|
Registry.fetch_and_store_domain user: user, account_id: account_id
|
78
75
|
response = Services::Data.get account_id: account_id, user: user, service: service, endpoint: endpoint, fields: fields, ids: id.split("/").last
|
79
76
|
|
80
|
-
|
77
|
+
entries = response.data['entries']
|
78
|
+
|
79
|
+
raise "could not load #{id}" unless entries.any?
|
81
80
|
|
82
|
-
self.fields.parse data:
|
81
|
+
self.fields.parse data: entries.first, xmlns: response.data['xmlns']
|
83
82
|
self
|
84
83
|
end
|
85
84
|
|
@@ -89,19 +88,18 @@ module Cts
|
|
89
88
|
def save(user: nil)
|
90
89
|
Driver::Helpers.required_arguments %i[user], binding
|
91
90
|
Driver::Exceptions.raise_unless_argument_error? user, User
|
91
|
+
raise ArgumentError, "fields['ownerId'] is a required field" unless fields['ownerId']
|
92
|
+
raise ArgumentError, "endpoint is a required attribute" unless endpoint
|
93
|
+
raise ArgumentError, "service is a required attribute" unless service
|
92
94
|
|
93
95
|
p = Driver::Page.create entries: [fields.to_h], xmlns: fields.xmlns
|
96
|
+
Registry.fetch_and_store_domain user: user, account_id: fields["ownerId"]
|
94
97
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
raise ArgumentError, "service is a required keyword" unless service
|
99
|
-
raise ArgumentError, "endpoint is a required keyword" unless endpoint
|
100
|
-
|
101
|
-
response = Services::Data.post user: user, service: service, endpoint: endpoint, page: p
|
102
|
-
end
|
98
|
+
response_params = { account_id: fields['ownerId'], user: user, service: service, endpoint: endpoint, page: p }
|
99
|
+
result = Services::Data.send(id ? :put : :post, response_params)
|
100
|
+
result.data if result.service_exception?
|
103
101
|
|
104
|
-
|
102
|
+
self
|
105
103
|
end
|
106
104
|
end
|
107
105
|
end
|
data/lib/cts/mpx/field.rb
CHANGED
@@ -12,7 +12,7 @@ module Cts
|
|
12
12
|
|
13
13
|
attribute name: 'name', kind_of: String
|
14
14
|
attribute name: 'value'
|
15
|
-
attribute
|
15
|
+
attribute(name: 'xmlns', kind_of: Hash) { |o, xmlns| o.xmlns = xmlns if o.custom? }
|
16
16
|
|
17
17
|
# Return just the name value as key/value
|
18
18
|
# @return [Hash]
|
@@ -21,10 +21,11 @@ module Cts
|
|
21
21
|
end
|
22
22
|
|
23
23
|
# Determines if this field is a custom field or not
|
24
|
-
# @return [Symbol]
|
25
|
-
def
|
26
|
-
return
|
27
|
-
|
24
|
+
# @return [Symbol] true if it is a custom field
|
25
|
+
def custom?
|
26
|
+
return true if name.include? "$"
|
27
|
+
|
28
|
+
false
|
28
29
|
end
|
29
30
|
|
30
31
|
# Set the namespace of the field
|
data/lib/cts/mpx/fields.rb
CHANGED
@@ -26,8 +26,10 @@ module Cts
|
|
26
26
|
# @return [Self.collection,Field,nil] Can return the collection, a single field, or nil if nothing found
|
27
27
|
def [](key = nil)
|
28
28
|
return @collection unless key
|
29
|
+
|
29
30
|
result = @collection.find { |f| f.name == key }
|
30
31
|
return result.value if result
|
32
|
+
|
31
33
|
nil
|
32
34
|
end
|
33
35
|
|
@@ -54,6 +56,7 @@ module Cts
|
|
54
56
|
# @return [Self]
|
55
57
|
def add(field)
|
56
58
|
return self if @collection.include? field
|
59
|
+
|
57
60
|
Driver::Exceptions.raise_unless_argument_error? field, Field
|
58
61
|
@collection.push field
|
59
62
|
self
|
@@ -83,7 +86,7 @@ module Cts
|
|
83
86
|
data.delete :service
|
84
87
|
data.delete :endpoint
|
85
88
|
reset
|
86
|
-
@collection = data.map { |k, v| Field.create
|
89
|
+
@collection = data.map { |k, v| Field.create(name: k.to_s, value: v, xmlns: xmlns) }
|
87
90
|
end
|
88
91
|
|
89
92
|
# Remove a field object from the collection
|
data/lib/cts/mpx/query.rb
CHANGED
@@ -59,7 +59,7 @@ module Cts
|
|
59
59
|
# List of entries created from the page
|
60
60
|
# @return [Entries] populated Entries object
|
61
61
|
def entries
|
62
|
-
|
62
|
+
@page.to_mpx_entries
|
63
63
|
end
|
64
64
|
|
65
65
|
# Run the query
|
@@ -97,13 +97,8 @@ module Cts
|
|
97
97
|
output.store attribute, instance_variable_get("@#{attribute}") unless instance_variable_get("@#{attribute}").nil?
|
98
98
|
end
|
99
99
|
|
100
|
-
unless output[:return_count].nil?
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
unless output[:return_entries].nil?
|
105
|
-
output[:entries] = output.delete :return_entries
|
106
|
-
end
|
100
|
+
output[:count] = output.delete :return_count unless output[:return_count].nil?
|
101
|
+
output[:entries] = output.delete :return_entries unless output[:return_entries].nil?
|
107
102
|
|
108
103
|
output
|
109
104
|
end
|
data/lib/cts/mpx/registry.rb
CHANGED
@@ -32,8 +32,8 @@ module Cts
|
|
32
32
|
return domains['urn:theplatform:auth:root'] if account_id == 'urn:theplatform:auth:root'
|
33
33
|
|
34
34
|
Driver::Exceptions.raise_unless_argument_error?(user, 'User') { !user.is_a? User }
|
35
|
-
Driver::Exceptions.raise_unless_argument_error?(account_id, 'account_id') { !Validators.account_id? account_id }
|
36
35
|
user.token!
|
36
|
+
Driver::Exceptions.raise_unless_argument_error?(account_id, 'account_id') { !Validators.account_id? account_id }
|
37
37
|
|
38
38
|
response = Services::Web.post user: user, service: 'Access Data Service', endpoint: 'Registry', method: 'resolveDomain', arguments: { 'accountId' => account_id }
|
39
39
|
response.data['resolveDomainResponse']
|
@@ -56,7 +56,8 @@ module Cts
|
|
56
56
|
# find and store the root registry from the US
|
57
57
|
def initialize
|
58
58
|
@domains = {}
|
59
|
-
|
59
|
+
content = File.read "#{Driver.config_dir}/root_registry_sea1.json"
|
60
|
+
store_domain(Driver.parse_json(content)['resolveDomainResponse'], 'urn:theplatform:auth:root')
|
60
61
|
end
|
61
62
|
end
|
62
63
|
end
|
data/lib/cts/mpx/service.rb
CHANGED
@@ -53,6 +53,7 @@ module Cts
|
|
53
53
|
Exceptions.raise_unless_account_id account_id
|
54
54
|
reg = Registry.domains[account_id]
|
55
55
|
return reg[name] if reg
|
56
|
+
|
56
57
|
nil
|
57
58
|
end
|
58
59
|
|
@@ -63,6 +64,7 @@ module Cts
|
|
63
64
|
Exceptions.raise_unless_account_id account_id
|
64
65
|
u = url account_id
|
65
66
|
return true if u
|
67
|
+
|
66
68
|
false
|
67
69
|
end
|
68
70
|
end
|
data/lib/cts/mpx/services.rb
CHANGED
@@ -57,7 +57,7 @@ module Cts
|
|
57
57
|
raise ArgumentError, 'type must be supplied' unless type
|
58
58
|
raise ArgumentError, 'file must be supplied' unless file
|
59
59
|
|
60
|
-
@raw_reference.store(type, Driver.
|
60
|
+
@raw_reference.store(type, Driver.parse_json(File.read(file)))
|
61
61
|
true
|
62
62
|
end
|
63
63
|
|
@@ -17,8 +17,10 @@ module Cts
|
|
17
17
|
services = Services[].select { |s| s.type == 'data' }
|
18
18
|
return services unless key
|
19
19
|
raise ArgumentError, 'key must be a string' unless key.is_a? String
|
20
|
+
|
20
21
|
service = services.find { |e| e.name == key }
|
21
22
|
raise ArgumentError, "#{key} must be a service name." unless service
|
23
|
+
|
22
24
|
service
|
23
25
|
end
|
24
26
|
|
@@ -51,12 +53,10 @@ module Cts
|
|
51
53
|
|
52
54
|
host = Driver::Assemblers.host user: user, service: service, account_id: account_id
|
53
55
|
path = Driver::Assemblers.path service: service, endpoint: endpoint, extra_path: extra_path, ids: ids
|
54
|
-
query = Driver::Assemblers.query user: user, account_id: account_id, service: service, endpoint: endpoint, query: query
|
56
|
+
query = Driver::Assemblers.query user: user, account_id: account_id, service: service, endpoint: endpoint, query: query, range: range
|
57
|
+
|
58
|
+
query[:fields] = fields if Services[service].type == 'data' && fields
|
55
59
|
|
56
|
-
if Services[service].type == 'data'
|
57
|
-
query.merge! Driver::Assemblers.query_data range: range, count: count, entries: entries, sort: sort
|
58
|
-
query[:fields] = fields if fields
|
59
|
-
end
|
60
60
|
request = Driver::Request.create(method: method, url: [host, path].join, query: query, headers: headers)
|
61
61
|
request.call
|
62
62
|
end
|
@@ -74,7 +74,6 @@ module Cts
|
|
74
74
|
# @return [Response] Response of the call
|
75
75
|
def post(user: nil, account_id: nil, service: nil, endpoint: nil, extra_path: nil, query: {}, page: nil, headers: {}, method: :post)
|
76
76
|
prep_call(user: user, account_id: account_id, service: service, query: query, headers: headers, required_arguments: ['user', 'service', 'endpoint', 'page'], page: page, binding: binding)
|
77
|
-
|
78
77
|
host = Driver::Assemblers.host user: user, service: service
|
79
78
|
path = Driver::Assemblers.path service: service, endpoint: endpoint, extra_path: extra_path
|
80
79
|
query = Driver::Assemblers.query user: user, account_id: account_id, service: service, endpoint: endpoint, query: query
|
data/lib/cts/mpx/user.rb
CHANGED
@@ -18,7 +18,7 @@ module Cts
|
|
18
18
|
attribute name: 'password', kind_of: String
|
19
19
|
attribute name: 'idle_timeout', kind_of: Integer
|
20
20
|
attribute name: 'duration', kind_of: Integer
|
21
|
-
attribute name: 'token', kind_of: String
|
21
|
+
attribute name: 'token', kind_of: [String, NilClass]
|
22
22
|
|
23
23
|
# Attempt to sign the user in with the provided credentials
|
24
24
|
# @param [Numeric] idle_timeout how long the token will stay alive without communicating with the services
|
@@ -35,8 +35,10 @@ module Cts
|
|
35
35
|
|
36
36
|
self.token = 'sign_in_token'
|
37
37
|
response = Services::Web.post user: self, service: 'User Data Service', endpoint: 'Authentication', method: 'signIn', arguments: arguments, headers: headers
|
38
|
+
self.token = nil
|
38
39
|
|
39
40
|
raise "sign_in exception, status: #{response.status}" unless response.status == 200
|
41
|
+
|
40
42
|
self.token = response.data['signInResponse']['token']
|
41
43
|
self
|
42
44
|
end
|
data/lib/cts/mpx/validators.rb
CHANGED
data/lib/cts/mpx/version.rb
CHANGED
data/uml.nomnoml
CHANGED
@@ -145,7 +145,7 @@
|
|
145
145
|
fetch_domain(user, account_id = 'urn:theplatform:auth:root')
|
146
146
|
store_domain(data, account_id = 'urn:theplatform:auth:root')
|
147
147
|
initialize
|
148
|
-
|
148
|
+
raise_argument_exception(data, name)
|
149
149
|
]
|
150
150
|
[<class> Service|
|
151
151
|
|
|
@@ -239,4 +239,4 @@
|
|
239
239
|
[Driver]->[Response]
|
240
240
|
[Services]->[Data]
|
241
241
|
[Services]->[Web]
|
242
|
-
[Services]->[Ingest]
|
242
|
+
[Services]->[Ingest]
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cts-mpx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ernie Brodeur
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: creatable
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.2.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.2.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: excon
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|