smarts_api 0.0.1 → 0.0.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.
- data/Gemfile.lock +6 -4
- data/lib/smarts_api/message/connect_message.rb +7 -7
- data/lib/smarts_api/message/disconnect_message.rb +3 -3
- data/lib/smarts_api/message/evaluate_message.rb +5 -5
- data/lib/smarts_api/message.rb +6 -10
- data/lib/smarts_api/version.rb +1 -1
- data/lib/smarts_api.rb +20 -5
- data/smarts_api-0.0.1.gem +0 -0
- data/spec/smarts_api/message/connect_message_spec.rb +7 -7
- data/spec/smarts_api/message/disconnect_message_spec.rb +5 -5
- data/spec/smarts_api/message/evaluate_message_spec.rb +9 -9
- data/spec/smarts_api/message_spec.rb +7 -4
- data/spec/smarts_api_spec.rb +5 -2
- metadata +3 -2
data/Gemfile.lock
CHANGED
@@ -2,15 +2,15 @@ PATH
|
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
4
|
smarts_api (0.0.1)
|
5
|
-
|
5
|
+
activesupport
|
6
6
|
typhoeus
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
activesupport (3.2.14)
|
12
|
+
i18n (~> 0.6, >= 0.6.4)
|
13
|
+
multi_json (~> 1.0)
|
14
14
|
addressable (2.3.5)
|
15
15
|
crack (0.4.1)
|
16
16
|
safe_yaml (~> 0.9.0)
|
@@ -19,7 +19,9 @@ GEM
|
|
19
19
|
ffi (>= 1.3.0)
|
20
20
|
mime-types (~> 1.18)
|
21
21
|
ffi (1.9.0)
|
22
|
+
i18n (0.6.5)
|
22
23
|
mime-types (1.25)
|
24
|
+
multi_json (1.7.9)
|
23
25
|
rspec (2.14.1)
|
24
26
|
rspec-core (~> 2.14.0)
|
25
27
|
rspec-expectations (~> 2.14.0)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class SmartsApi::ConnectMessage < SmartsApi::Message
|
2
2
|
|
3
3
|
def send
|
4
|
-
|
4
|
+
log "Connecting to #{uri}"
|
5
5
|
response = Typhoeus::Request.post(uri,
|
6
6
|
:method => method,
|
7
7
|
:headers => {:Accept => "text/json"},
|
@@ -19,17 +19,17 @@ class SmartsApi::ConnectMessage < SmartsApi::Message
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def request_document
|
22
|
-
{:OperationId =>1 , :Header => {:DeploymentId => project_id}}.to_json
|
22
|
+
{:OperationId =>1 , :Header => {:DeploymentId => SmartsApi::Configuration.project_id}}.to_json
|
23
23
|
end
|
24
24
|
|
25
25
|
def request_params
|
26
26
|
params = {
|
27
|
-
:appId => app_id,
|
28
|
-
:pwd => pwd,
|
27
|
+
:appId => SmartsApi::Configuration.app_id,
|
28
|
+
:pwd => SmartsApi::Configuration.pwd,
|
29
29
|
:reqData => request_document,
|
30
30
|
:reqTime => self.timestamp,
|
31
|
-
:userId => user_id,
|
32
|
-
:workspaceId => workspace_id
|
31
|
+
:userId => SmartsApi::Configuration.user_id,
|
32
|
+
:workspaceId => SmartsApi::Configuration.workspace_id
|
33
33
|
}
|
34
34
|
signature = {
|
35
35
|
:sign => sign_request(params)
|
@@ -38,7 +38,7 @@ class SmartsApi::ConnectMessage < SmartsApi::Message
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def uri
|
41
|
-
"#{
|
41
|
+
"#{super}connect"
|
42
42
|
end
|
43
43
|
|
44
44
|
end
|
@@ -3,7 +3,7 @@ class SmartsApi::DisconnectMessage < SmartsApi::Message
|
|
3
3
|
|
4
4
|
def send(session)
|
5
5
|
body = make_form(request_params(session))
|
6
|
-
|
6
|
+
log "Disconnecting"
|
7
7
|
response = Typhoeus::Request.post(uri,
|
8
8
|
:method => method,
|
9
9
|
:headers => {:Accept => "text/json"},
|
@@ -21,7 +21,7 @@ class SmartsApi::DisconnectMessage < SmartsApi::Message
|
|
21
21
|
|
22
22
|
def request_params(session)
|
23
23
|
params = {
|
24
|
-
:appId => app_id,
|
24
|
+
:appId => SmartsApi::Configuration.app_id,
|
25
25
|
:reqTime => timestamp,
|
26
26
|
:session => session
|
27
27
|
}
|
@@ -32,7 +32,7 @@ class SmartsApi::DisconnectMessage < SmartsApi::Message
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def uri
|
35
|
-
"#{
|
35
|
+
"#{super}disconnect"
|
36
36
|
end
|
37
37
|
|
38
38
|
|
@@ -2,7 +2,7 @@ class SmartsApi::EvaluateMessage < SmartsApi::Message
|
|
2
2
|
|
3
3
|
def send(session, member, decision)
|
4
4
|
body = make_form(request_params(session, member, decision))
|
5
|
-
|
5
|
+
log "Evaluating"
|
6
6
|
response = Typhoeus::Request.post(uri,
|
7
7
|
:method => method,
|
8
8
|
:headers => {:Accept => "text/json"},
|
@@ -16,19 +16,19 @@ class SmartsApi::EvaluateMessage < SmartsApi::Message
|
|
16
16
|
body = reply["Body"]
|
17
17
|
|
18
18
|
if body.blank?
|
19
|
-
|
19
|
+
log "Rules Engine Evaluation failed. \n\n #{body} \n\n #{response.body}"
|
20
20
|
|
21
21
|
raise SmartsApi::Error, "Rules Evaluation failed. Returned JSON is blank."
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
log "Updating issues"
|
25
25
|
member.process_smarts_response body
|
26
26
|
return body
|
27
27
|
end
|
28
28
|
|
29
29
|
def request_params(session, member, decision)
|
30
30
|
params = {
|
31
|
-
:appId => app_id,
|
31
|
+
:appId => SmartsApi::Configuration.app_id,
|
32
32
|
:reqData => request_document(session, member, decision),
|
33
33
|
:reqTime => timestamp,
|
34
34
|
:session => session
|
@@ -46,6 +46,6 @@ class SmartsApi::EvaluateMessage < SmartsApi::Message
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def uri
|
49
|
-
"#{
|
49
|
+
"#{super}evaluate"
|
50
50
|
end
|
51
51
|
end
|
data/lib/smarts_api/message.rb
CHANGED
@@ -1,26 +1,22 @@
|
|
1
1
|
require 'typhoeus'
|
2
2
|
require 'json'
|
3
|
-
require 'active_support/core_ext/class'
|
4
3
|
require 'active_support/core_ext/array'
|
5
4
|
include ERB::Util
|
6
5
|
require 'openssl'
|
7
6
|
require 'base64'
|
8
7
|
|
9
8
|
class SmartsApi::Message
|
10
|
-
attr_reader :logger
|
11
|
-
cattr_accessor :user_id, :pwd, :app_id, :workspace_id, :access_key, :base_uri, :project_id
|
12
|
-
|
13
|
-
|
14
|
-
def initialize(logger=nil)
|
15
|
-
@logger = logger
|
16
|
-
end
|
17
9
|
|
18
10
|
def method
|
19
11
|
:post
|
20
12
|
end
|
21
13
|
|
22
14
|
def uri
|
23
|
-
base_uri
|
15
|
+
SmartsApi::Configuration.base_uri
|
16
|
+
end
|
17
|
+
|
18
|
+
def log(msg)
|
19
|
+
SmartsApi::Configuration.logger.info msg if SmartsApi::Configuration.logger.respond_to?(:info)
|
24
20
|
end
|
25
21
|
|
26
22
|
def sign_request(params)
|
@@ -42,7 +38,7 @@ class SmartsApi::Message
|
|
42
38
|
|
43
39
|
#5 Digest the encode string with SHA256, using the pre-shared AccessKey as the digest key.
|
44
40
|
digest = OpenSSL::Digest::Digest.new('sha256')
|
45
|
-
hash = OpenSSL::HMAC.hexdigest(digest, access_key, encoded)
|
41
|
+
hash = OpenSSL::HMAC.hexdigest(digest, SmartsApi::Configuration.access_key, encoded)
|
46
42
|
|
47
43
|
#6 OpenSSL::Digest correctly translates the Hash to a string of bytes. Sparkling Logic's algorithm ...unexpectedle converts the hex value to the corresponding ascii code.
|
48
44
|
#So we need to iterate each pair in our byte string and convert to ascii. this is a little ugly, but necessary
|
data/lib/smarts_api/version.rb
CHANGED
data/lib/smarts_api.rb
CHANGED
@@ -1,17 +1,32 @@
|
|
1
|
-
|
1
|
+
require 'active_support/core_ext/class'
|
2
2
|
module SmartsApi
|
3
|
+
def self.configure(configuration = SmartsApi::Configuration.new)
|
4
|
+
yield configuration if block_given?
|
5
|
+
@@configuration = configuration
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.configuration
|
9
|
+
@@configuration ||= SmartsApi::Configuration.new
|
10
|
+
end
|
11
|
+
|
12
|
+
class Configuration
|
13
|
+
cattr_accessor :logger
|
14
|
+
cattr_accessor :user_id, :pwd, :app_id, :workspace_id, :access_key, :base_uri, :project_id
|
15
|
+
end
|
16
|
+
|
17
|
+
|
3
18
|
Dir[File.expand_path('../../lib/smarts_api/*.rb', __FILE__)].each {|f| require f}
|
4
19
|
Dir[File.expand_path('../../lib/smarts_api/*/*.rb', __FILE__)].each {|f| require f}
|
5
20
|
|
6
21
|
def self.evaluate(decision, obj, logger = nil)
|
7
22
|
raise SmartsApi::Error.new("Object to be evaluated must define a method 'smarts_document'") unless obj.respond_to?(:smarts_document)
|
8
|
-
logger.info "processing request for #{obj}" if logger.respond_to?(:info)
|
23
|
+
logger.info "processing request for #{obj.class} id=#{obj.id}{" if logger.respond_to?(:info)
|
9
24
|
|
10
|
-
session = SmartsApi::ConnectMessage.new(
|
11
|
-
response = SmartsApi::EvaluateMessage.new(
|
25
|
+
session = SmartsApi::ConnectMessage.new().send
|
26
|
+
response = SmartsApi::EvaluateMessage.new().
|
12
27
|
send(session, obj, decision)
|
13
28
|
|
14
|
-
|
29
|
+
SmartsApi::DisconnectMessage.new().send(session)
|
15
30
|
end
|
16
31
|
|
17
32
|
end
|
Binary file
|
@@ -2,13 +2,13 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe SmartsApi::ConnectMessage do
|
4
4
|
before (:all) do
|
5
|
-
SmartsApi::
|
6
|
-
SmartsApi::
|
5
|
+
SmartsApi::Configuration.base_uri = "http://smarts.dev.thismashine.com/"
|
6
|
+
SmartsApi::Configuration.access_key = "sshhhh...Secret!"
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'should return session ID if successful' do
|
10
10
|
|
11
|
-
stub_http_request(:post, "#{SmartsApi::
|
11
|
+
stub_http_request(:post, "#{SmartsApi::Configuration.base_uri}connect")
|
12
12
|
.to_return(:status => 200, :body => "{\"Header\":{\"SessionId\":\"487d2c44-43fe-44d3-988f-ea462af03169\"},\"Body\":null,\"ErrorInfo\":null,\"Metrics\":null,\"Success\":true,\"OperationException\":null}")
|
13
13
|
|
14
14
|
|
@@ -18,7 +18,7 @@ describe SmartsApi::ConnectMessage do
|
|
18
18
|
|
19
19
|
it 'should throw an error if the connection returns an error' do
|
20
20
|
|
21
|
-
stub_http_request(:post, "#{SmartsApi::
|
21
|
+
stub_http_request(:post, "#{SmartsApi::Configuration.base_uri}connect")
|
22
22
|
.to_return(:status => 200, :body => "{\"OperationId\":0,\"Header\":{\"SessionId\":\"00000000-0000-0000-0000-000000000000\",\"TransactionTime\":\"2012-06-22T21:02:16.642625Z\",\"Workspace\":null,\"DeploymentId\":null,\"DecisionId\":null},\"Body\":null,\"ErrorInfo\":{\"ErrorCode\":\"ServerException\",\"ErrorMessage\":\"Exception during connection\",\"Details\":[\"Invalid API access\"]},\"Metrics\":null,\"Success\":false,\"OperationException\":{\"IsRestException\":true,\"ErrorType\":\"DocApiAccessDeniedException\",\"CompleteStackTrace\":\"Type: DocApiAccessDeniedException\\r\\nMessage: Invalid API access\\r\\nStack Trace:\\r\\n at Splog.Rest.Base.DocRestHttpHandler.VerifyHmacSignature(String method, IEnumerable`1 keys, String signature, String[] paramaters)\\r\\n at Splog.Rest.Decisions.DocRestDecisionService.Connect(String appId, String reqTime, String userId, String pwd, String workspaceId, String reqData, String sign)\\r\\n\\r\\n\",\"ExtraInfo\":null,\"Message\":\"[DecisionServer] Exception connecting to the decision server for session 72950db0-9639-477b-b824-b82ad5122b56\",\"Data\":{}}}")
|
23
23
|
|
24
24
|
expect{SmartsApi::ConnectMessage.new().send}.to raise_error(SmartsApi::Error)
|
@@ -27,7 +27,7 @@ describe SmartsApi::ConnectMessage do
|
|
27
27
|
|
28
28
|
it 'should throw an error if the returned sessionID is empty' do
|
29
29
|
|
30
|
-
stub_http_request(:post, "#{SmartsApi::
|
30
|
+
stub_http_request(:post, "#{SmartsApi::Configuration.base_uri}connect")
|
31
31
|
.to_return(:status => 200, :body => "{\"OperationId\":0,\"Header\":{\"SessionId\":\"00000000-0000-0000-0000-000000000000\",\"TransactionTime\":\"2012-06-22T21:02:16.642625Z\",\"Workspace\":null,\"DeploymentId\":null,\"DecisionId\":null},\"Body\":null,\"ErrorInfo\":{\"ErrorCode\":\"ServerException\",\"ErrorMessage\":\"Exception during connection\",\"Details\":[\"Invalid API access\"]},\"Metrics\":null,\"Success\":false,\"OperationException\":{\"IsRestException\":true,\"ErrorType\":\"DocApiAccessDeniedException\",\"CompleteStackTrace\":\"Type: DocApiAccessDeniedException\\r\\nMessage: Invalid API access\\r\\nStack Trace:\\r\\n at Splog.Rest.Base.DocRestHttpHandler.VerifyHmacSignature(String method, IEnumerable`1 keys, String signature, String[] paramaters)\\r\\n at Splog.Rest.Decisions.DocRestDecisionService.Connect(String appId, String reqTime, String userId, String pwd, String workspaceId, String reqData, String sign)\\r\\n\\r\\n\",\"ExtraInfo\":null,\"Message\":\"[DecisionServer] Exception connecting to the decision server for session 72950db0-9639-477b-b824-b82ad5122b56\",\"Data\":{}}}")
|
32
32
|
|
33
33
|
expect{SmartsApi::ConnectMessage.new().send}.to raise_error(SmartsApi::Error)
|
@@ -36,7 +36,7 @@ describe SmartsApi::ConnectMessage do
|
|
36
36
|
|
37
37
|
it 'should throw an error if no body is returned' do
|
38
38
|
|
39
|
-
stub_http_request(:post, "#{SmartsApi::
|
39
|
+
stub_http_request(:post, "#{SmartsApi::Configuration.base_uri}connect")
|
40
40
|
.to_return(:status => 200)
|
41
41
|
expect{SmartsApi::ConnectMessage.new().send}.to raise_error(SmartsApi::Error)
|
42
42
|
|
@@ -44,7 +44,7 @@ describe SmartsApi::ConnectMessage do
|
|
44
44
|
|
45
45
|
it 'should throw an error if status code is bad' do
|
46
46
|
|
47
|
-
stub_http_request(:post, "#{SmartsApi::
|
47
|
+
stub_http_request(:post, "#{SmartsApi::Configuration.base_uri}connect")
|
48
48
|
.to_return(:status => 500)
|
49
49
|
expect{SmartsApi::ConnectMessage.new().send}.to raise_error(SmartsApi::Error)
|
50
50
|
|
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
4
4
|
describe SmartsApi::DisconnectMessage do
|
5
5
|
it 'should return session ID if successful' do
|
6
6
|
|
7
|
-
stub_http_request(:post, "#{SmartsApi::
|
7
|
+
stub_http_request(:post, "#{SmartsApi::Configuration.base_uri}disconnect")
|
8
8
|
.to_return(:status => 200, :body => "{\"Header\":{\"SessionId\":\"487d2c44-43fe-44d3-988f-ea462af03169\"},\"Body\":null,\"ErrorInfo\":null,\"Metrics\":null,\"Success\":true,\"OperationException\":null}")
|
9
9
|
|
10
10
|
|
@@ -14,7 +14,7 @@ describe SmartsApi::DisconnectMessage do
|
|
14
14
|
|
15
15
|
it 'should throw an error if the connection returns an error' do
|
16
16
|
|
17
|
-
stub_http_request(:post, "#{SmartsApi::
|
17
|
+
stub_http_request(:post, "#{SmartsApi::Configuration.base_uri}disconnect")
|
18
18
|
.to_return(:status => 200, :body => "{\"OperationId\":0,\"Header\":{\"SessionId\":\"00000000-0000-0000-0000-000000000000\",\"TransactionTime\":\"2012-06-22T21:02:16.642625Z\",\"Workspace\":null,\"DeploymentId\":null,\"DecisionId\":null},\"Body\":null,\"ErrorInfo\":{\"ErrorCode\":\"ServerException\",\"ErrorMessage\":\"Exception during connection\",\"Details\":[\"Invalid API access\"]},\"Metrics\":null,\"Success\":false,\"OperationException\":{\"IsRestException\":true,\"ErrorType\":\"DocApiAccessDeniedException\",\"CompleteStackTrace\":\"Type: DocApiAccessDeniedException\\r\\nMessage: Invalid API access\\r\\nStack Trace:\\r\\n at Splog.Rest.Base.DocRestHttpHandler.VerifyHmacSignature(String method, IEnumerable`1 keys, String signature, String[] paramaters)\\r\\n at Splog.Rest.Decisions.DocRestDecisionService.Connect(String appId, String reqTime, String userId, String pwd, String workspaceId, String reqData, String sign)\\r\\n\\r\\n\",\"ExtraInfo\":null,\"Message\":\"[DecisionServer] Exception connecting to the decision server for session 72950db0-9639-477b-b824-b82ad5122b56\",\"Data\":{}}}")
|
19
19
|
|
20
20
|
expect{SmartsApi::DisconnectMessage.new().send("487d2c44-43fe-44d3-988f-ea462af03169")}.to raise_error(SmartsApi::Error)
|
@@ -23,7 +23,7 @@ describe SmartsApi::DisconnectMessage do
|
|
23
23
|
|
24
24
|
it 'should throw an error if the returned sessionID is empty returns an error' do
|
25
25
|
|
26
|
-
stub_http_request(:post, "#{SmartsApi::
|
26
|
+
stub_http_request(:post, "#{SmartsApi::Configuration.base_uri}disconnect")
|
27
27
|
.to_return(:status => 200, :body => "{\"OperationId\":0,\"Header\":{\"SessionId\":\"00000000-0000-0000-0000-000000000000\",\"TransactionTime\":\"2012-06-22T21:02:16.642625Z\",\"Workspace\":null,\"DeploymentId\":null,\"DecisionId\":null},\"Body\":null,\"ErrorInfo\":{\"ErrorCode\":\"ServerException\",\"ErrorMessage\":\"Exception during connection\",\"Details\":[\"Invalid API access\"]},\"Metrics\":null,\"Success\":false,\"OperationException\":{\"IsRestException\":true,\"ErrorType\":\"DocApiAccessDeniedException\",\"CompleteStackTrace\":\"Type: DocApiAccessDeniedException\\r\\nMessage: Invalid API access\\r\\nStack Trace:\\r\\n at Splog.Rest.Base.DocRestHttpHandler.VerifyHmacSignature(String method, IEnumerable`1 keys, String signature, String[] paramaters)\\r\\n at Splog.Rest.Decisions.DocRestDecisionService.Connect(String appId, String reqTime, String userId, String pwd, String workspaceId, String reqData, String sign)\\r\\n\\r\\n\",\"ExtraInfo\":null,\"Message\":\"[DecisionServer] Exception connecting to the decision server for session 72950db0-9639-477b-b824-b82ad5122b56\",\"Data\":{}}}")
|
28
28
|
|
29
29
|
expect{SmartsApi::DisconnectMessage.new().send("487d2c44-43fe-44d3-988f-ea462af03169")}.to raise_error(SmartsApi::Error)
|
@@ -32,14 +32,14 @@ describe SmartsApi::DisconnectMessage do
|
|
32
32
|
|
33
33
|
it 'should throw an error if no body is returned' do
|
34
34
|
|
35
|
-
stub_http_request(:post, "#{SmartsApi::
|
35
|
+
stub_http_request(:post, "#{SmartsApi::Configuration.base_uri}disconnect")
|
36
36
|
.to_return(:status => 200)
|
37
37
|
expect{SmartsApi::DisconnectMessage.new().send("487d2c44-43fe-44d3-988f-ea462af03169")}.to raise_error(SmartsApi::Error)
|
38
38
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'should throw an error if status code is bad' do
|
42
|
-
stub_http_request(:post, "#{SmartsApi::
|
42
|
+
stub_http_request(:post, "#{SmartsApi::Configuration.base_uri}disconnect")
|
43
43
|
.to_return(:status => 500)
|
44
44
|
expect{SmartsApi::DisconnectMessage.new().send("487d2c44-43fe-44d3-988f-ea462af03169")}.to raise_error(SmartsApi::Error)
|
45
45
|
|
@@ -3,8 +3,8 @@ require 'spec_helper'
|
|
3
3
|
describe SmartsApi::EvaluateMessage do
|
4
4
|
|
5
5
|
before (:all) do
|
6
|
-
SmartsApi::
|
7
|
-
SmartsApi::
|
6
|
+
SmartsApi::Configuration.base_uri = "http://smarts.dev.thismashine.com/"
|
7
|
+
SmartsApi::Configuration.access_key = "sshhhh...Secret!"
|
8
8
|
end
|
9
9
|
|
10
10
|
let(:eval_class) {
|
@@ -28,14 +28,14 @@ describe SmartsApi::EvaluateMessage do
|
|
28
28
|
|
29
29
|
body = "{\"OperationId\":1,\"Header\":{\"SessionId\":\"e3e2b012-e9b6-45e7-a96a-a009ebf0a07a\"},\"Body\":{\"Documents\":[{\"identification\":{\"actor_group\":\"root\",\"actor_id\":3,\"gender\":\"Male\",\"birth_date\":\"1984-12-08T06:00:00Z\"},\"historical_properties\":[{\"weight\":\"150\"}]}]},\"ErrorInfo\":null,\"Metrics\":null,\"Success\":true,\"OperationException\":null}"
|
30
30
|
|
31
|
-
stub_http_request(:post, "#{SmartsApi::
|
31
|
+
stub_http_request(:post, "#{SmartsApi::Configuration.base_uri}evaluate")
|
32
32
|
.to_return(:status => 200, :body => body)
|
33
33
|
SmartsApi::EvaluateMessage.new().send("487d2c44-43fe-44d3-988f-ea462af03169", eval_object, "Issues Analysis Decision").should == JSON.parse(body)["Body"]
|
34
34
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'should throw an error if the connection returns an error' do
|
38
|
-
stub_http_request(:post, "#{SmartsApi::
|
38
|
+
stub_http_request(:post, "#{SmartsApi::Configuration.base_uri}evaluate")
|
39
39
|
.to_return(:status => 200, :body => "{\"OperationId\":0,\"Header\":{\"SessionId\":\"00000000-0000-0000-0000-000000000000\",\"TransactionTime\":\"2012-06-22T21:02:16.642625Z\",\"Workspace\":null,\"DeploymentId\":null,\"DecisionId\":null},\"Body\":null,\"ErrorInfo\":{\"ErrorCode\":\"ServerException\",\"ErrorMessage\":\"Exception during connection\",\"Details\":[\"Invalid API access\"]},\"Metrics\":null,\"Success\":false,\"OperationException\":{\"IsRestException\":true,\"ErrorType\":\"DocApiAccessDeniedException\",\"CompleteStackTrace\":\"Type: DocApiAccessDeniedException\\r\\nMessage: Invalid API access\\r\\nStack Trace:\\r\\n at Splog.Rest.Base.DocRestHttpHandler.VerifyHmacSignature(String method, IEnumerable`1 keys, String signature, String[] paramaters)\\r\\n at Splog.Rest.Decisions.DocRestDecisionService.Connect(String appId, String reqTime, String userId, String pwd, String workspaceId, String reqData, String sign)\\r\\n\\r\\n\",\"ExtraInfo\":null,\"Message\":\"[DecisionServer] Exception connecting to the decision server for session 72950db0-9639-477b-b824-b82ad5122b56\",\"Data\":{}}}")
|
40
40
|
expect{SmartsApi::EvaluateMessage.new().send("487d2c44-43fe-44d3-988f-ea462af03169",eval_object, "Issues Analysis Decision")}.to raise_error(SmartsApi::Error)
|
41
41
|
|
@@ -43,7 +43,7 @@ describe SmartsApi::EvaluateMessage do
|
|
43
43
|
|
44
44
|
it 'should throw an error if the returned sessionID is empty returns an error' do
|
45
45
|
|
46
|
-
stub_http_request(:post, "#{SmartsApi::
|
46
|
+
stub_http_request(:post, "#{SmartsApi::Configuration.base_uri}evaluate")
|
47
47
|
.to_return(:status => 200, :body => "{\"OperationId\":0,\"Header\":{\"SessionId\":\"00000000-0000-0000-0000-000000000000\",\"TransactionTime\":\"2012-06-22T21:02:16.642625Z\",\"Workspace\":null,\"DeploymentId\":null,\"DecisionId\":null},\"Body\":null,\"ErrorInfo\":{\"ErrorCode\":\"ServerException\",\"ErrorMessage\":\"Exception during connection\",\"Details\":[\"Invalid API access\"]},\"Metrics\":null,\"Success\":false,\"OperationException\":{\"IsRestException\":true,\"ErrorType\":\"DocApiAccessDeniedException\",\"CompleteStackTrace\":\"Type: DocApiAccessDeniedException\\r\\nMessage: Invalid API access\\r\\nStack Trace:\\r\\n at Splog.Rest.Base.DocRestHttpHandler.VerifyHmacSignature(String method, IEnumerable`1 keys, String signature, String[] paramaters)\\r\\n at Splog.Rest.Decisions.DocRestDecisionService.Connect(String appId, String reqTime, String userId, String pwd, String workspaceId, String reqData, String sign)\\r\\n\\r\\n\",\"ExtraInfo\":null,\"Message\":\"[DecisionServer] Exception connecting to the decision server for session 72950db0-9639-477b-b824-b82ad5122b56\",\"Data\":{}}}")
|
48
48
|
expect{SmartsApi::EvaluateMessage.new().send("487d2c44-43fe-44d3-988f-ea462af03169",eval_object, "Issues Analysis Decision")}.to raise_error(SmartsApi::Error)
|
49
49
|
|
@@ -51,7 +51,7 @@ describe SmartsApi::EvaluateMessage do
|
|
51
51
|
|
52
52
|
it 'should throw an error if no body is returned' do
|
53
53
|
|
54
|
-
stub_http_request(:post, "#{SmartsApi::
|
54
|
+
stub_http_request(:post, "#{SmartsApi::Configuration.base_uri}evaluate")
|
55
55
|
.to_return(:status => 200)
|
56
56
|
expect{SmartsApi::EvaluateMessage.new().send("487d2c44-43fe-44d3-988f-ea462af03169",eval_object, "Issues Analysis Decision")}.to raise_error(SmartsApi::Error)
|
57
57
|
|
@@ -59,7 +59,7 @@ describe SmartsApi::EvaluateMessage do
|
|
59
59
|
|
60
60
|
it 'should throw an error if status code is bad' do
|
61
61
|
|
62
|
-
stub_http_request(:post, "#{SmartsApi::
|
62
|
+
stub_http_request(:post, "#{SmartsApi::Configuration.base_uri}evaluate")
|
63
63
|
.to_return(:status => 500)
|
64
64
|
expect{SmartsApi::EvaluateMessage.new().send("487d2c44-43fe-44d3-988f-ea462af03169",eval_object, "Issues Analysis Decision")}.to raise_error(SmartsApi::Error)
|
65
65
|
|
@@ -69,7 +69,7 @@ describe SmartsApi::EvaluateMessage do
|
|
69
69
|
eval_object.should_receive(:smarts_document)
|
70
70
|
body = "{\"OperationId\":1,\"Header\":{\"SessionId\":\"e3e2b012-e9b6-45e7-a96a-a009ebf0a07a\"},\"Body\":{\"Documents\":[{\"identification\":{\"actor_group\":\"root\",\"actor_id\":3,\"gender\":\"Male\",\"birth_date\":\"1984-12-08T06:00:00Z\"},\"historical_properties\":[{\"weight\":\"150\"}]}]},\"ErrorInfo\":null,\"Metrics\":null,\"Success\":true,\"OperationException\":null}"
|
71
71
|
|
72
|
-
stub_http_request(:post, "#{SmartsApi::
|
72
|
+
stub_http_request(:post, "#{SmartsApi::Configuration.base_uri}evaluate")
|
73
73
|
.to_return(:status => 200, :body => body)
|
74
74
|
SmartsApi::EvaluateMessage.new().send("487d2c44-43fe-44d3-988f-ea462af03169", eval_object, "Issues Analysis Decision").should == JSON.parse(body)["Body"]
|
75
75
|
end
|
@@ -78,7 +78,7 @@ describe SmartsApi::EvaluateMessage do
|
|
78
78
|
|
79
79
|
body = "{\"OperationId\":1,\"Header\":{\"SessionId\":\"e3e2b012-e9b6-45e7-a96a-a009ebf0a07a\"},\"Body\":{\"Documents\":[{\"identification\":{\"actor_group\":\"root\",\"actor_id\":3,\"gender\":\"Male\",\"birth_date\":\"1984-12-08T06:00:00Z\"},\"historical_properties\":[{\"weight\":\"150\"}]}]},\"ErrorInfo\":null,\"Metrics\":null,\"Success\":true,\"OperationException\":null}"
|
80
80
|
eval_object.should_receive(:process_smarts_response).with(JSON.parse(body)["Body"])
|
81
|
-
stub_http_request(:post, "#{SmartsApi::
|
81
|
+
stub_http_request(:post, "#{SmartsApi::Configuration.base_uri}evaluate")
|
82
82
|
.to_return(:status => 200, :body => body)
|
83
83
|
SmartsApi::EvaluateMessage.new().send("487d2c44-43fe-44d3-988f-ea462af03169", eval_object, "Issues Analysis Decision").should == JSON.parse(body)["Body"]
|
84
84
|
end
|
@@ -3,16 +3,19 @@ require 'spec_helper'
|
|
3
3
|
describe SmartsApi::Message do
|
4
4
|
|
5
5
|
before (:all) do
|
6
|
-
SmartsApi::
|
7
|
-
SmartsApi::
|
6
|
+
SmartsApi::Configuration.base_uri = "http://www.versign.com/request/doSomething.aspc"
|
7
|
+
SmartsApi::Configuration.access_key = "secretKey"
|
8
8
|
end
|
9
9
|
|
10
10
|
describe 'initializer' do
|
11
11
|
it "should keep the logger for logging purposes" do
|
12
12
|
logger = Logger.new(STDOUT)
|
13
|
-
|
13
|
+
SmartsApi::Configuration.logger = logger
|
14
|
+
message = SmartsApi::Message.new()
|
14
15
|
|
15
|
-
|
16
|
+
logger.should_receive(:info).with("Test is a pass!")
|
17
|
+
|
18
|
+
message.log "Test is a pass!"
|
16
19
|
|
17
20
|
end
|
18
21
|
end
|
data/spec/smarts_api_spec.rb
CHANGED
@@ -5,8 +5,8 @@ describe SmartsApi do
|
|
5
5
|
describe "evaluate" do
|
6
6
|
|
7
7
|
before (:all) do
|
8
|
-
SmartsApi::
|
9
|
-
SmartsApi::
|
8
|
+
SmartsApi::Configuration.base_uri = "http://smarts.dev.thismashine.com/"
|
9
|
+
SmartsApi::Configuration.access_key = "sshhhh...Secret!"
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "expectations on eval object" do
|
@@ -38,6 +38,7 @@ describe SmartsApi do
|
|
38
38
|
|
39
39
|
SmartsApi::ConnectMessage.any_instance.should_receive(:send).and_return("session 334")
|
40
40
|
SmartsApi::EvaluateMessage.any_instance.should_receive(:send)
|
41
|
+
SmartsApi::DisconnectMessage.any_instance.should_receive(:send).with("session 334")
|
41
42
|
SmartsApi.evaluate("string", instance)
|
42
43
|
end
|
43
44
|
end
|
@@ -49,6 +50,8 @@ describe SmartsApi do
|
|
49
50
|
instance.should_not be_nil
|
50
51
|
SmartsApi::ConnectMessage.any_instance.should_receive(:send).and_return("session 3339")
|
51
52
|
SmartsApi::EvaluateMessage.any_instance.should_receive(:send).with("session 3339", instance, "Chosen_decision")
|
53
|
+
SmartsApi::DisconnectMessage.any_instance.should_receive(:send).with("session 3339")
|
54
|
+
|
52
55
|
SmartsApi.evaluate("Chosen_decision", instance)
|
53
56
|
end
|
54
57
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smarts_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -91,7 +91,7 @@ dependencies:
|
|
91
91
|
- - ! '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
|
-
description: smarts_api-0.0.
|
94
|
+
description: smarts_api-0.0.2
|
95
95
|
email:
|
96
96
|
- theSteveMitchell@gmail.com
|
97
97
|
executables: []
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- lib/smarts_api/message/disconnect_message.rb
|
112
112
|
- lib/smarts_api/message/evaluate_message.rb
|
113
113
|
- lib/smarts_api/version.rb
|
114
|
+
- smarts_api-0.0.1.gem
|
114
115
|
- smarts_api.gemspec
|
115
116
|
- spec/smarts_api/message/connect_message_spec.rb
|
116
117
|
- spec/smarts_api/message/disconnect_message_spec.rb
|