allscripts_unity_client 2.2.4 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,7 +9,6 @@ describe AllscriptsUnityClient::JSONClientDriver do
9
9
  client_driver
10
10
  end
11
11
 
12
- let(:new_relic_client_driver) { build(:json_client_driver, new_relic: true) }
13
12
  let(:get_server_info) { FixtureLoader.load_file('get_server_info.json') }
14
13
  let(:get_security_token) { FixtureLoader.load_file('get_security_token.json') }
15
14
  let(:retire_security_token) { FixtureLoader.load_file('retire_security_token.json') }
@@ -24,13 +23,13 @@ describe AllscriptsUnityClient::JSONClientDriver do
24
23
  end
25
24
 
26
25
  let(:json_hash) do
27
- Oj.dump(hash, mode: :strict)
26
+ MultiJSON.dump(hash)
28
27
  end
29
28
 
30
29
  describe '#initialize' do
31
30
  context 'when given proxy' do
32
31
  it 'passes configuration to connection' do
33
- expect(build(:json_client_driver, proxy: url).connection.proxy.uri.to_s).to eq(url)
32
+ expect(build(:json_client_driver, proxy: url).connection.proxy.to_s).to eq(url)
34
33
  end
35
34
  end
36
35
  end
@@ -40,21 +39,29 @@ describe AllscriptsUnityClient::JSONClientDriver do
40
39
  end
41
40
 
42
41
  describe '#magic' do
43
- before(:each) {
44
- stub_request(:post, 'http://www.example.com/Unity/UnityService.svc/json/MagicJson').to_return(body: get_server_info)
42
+ before do
43
+ stub_request(:post, "http://www.example.com/Unity/UnityService.svc/json/MagicJson").
44
+ to_return(status: 200, body: get_server_info, headers: {})
45
+
45
46
  allow(subject).to receive(:start_timer)
46
47
  allow(subject).to receive(:end_timer)
47
48
  allow(subject).to receive(:log_magic)
48
- }
49
+ end
49
50
 
50
51
  it 'should POST to /Unity/UnityService.svc/json/MagicJson' do
51
52
  subject.magic
52
- expect(WebMock).to have_requested(:post, 'http://www.example.com/Unity/UnityService.svc/json/MagicJson').with(body: /\{"Action":(null|"[^"]*"),"AppUserID":(null|"[^"]*"),"Appname":(null|"[^"]*"),"PatientID":(null|"[^"]*"),"Token":(null|"[^"]*"),"Parameter1":(null|"[^"]*"),"Parameter2":(null|"[^"]*"),"Parameter3":(null|"[^"]*"),"Parameter4":(null|"[^"]*"),"Parameter5":(null|"[^"]*"),"Parameter6":(null|"[^"]*"),"Data":(null|"[^"]*")\}/, headers: { 'Content-Type' => 'application/json' })
53
+ expect(WebMock).to have_requested(:post, 'http://www.example.com/Unity/UnityService.svc/json/MagicJson').
54
+ with(body: /\{"Action":(null|"[^"]*"),"AppUserID":(null|"[^"]*"),"Appname":(null|"[^"]*"),"PatientID":(null|"[^"]*"),"Token":(null|"[^"]*"),"Parameter1":(null|"[^"]*"),"Parameter2":(null|"[^"]*"),"Parameter3":(null|"[^"]*"),"Parameter4":(null|"[^"]*"),"Parameter5":(null|"[^"]*"),"Parameter6":(null|"[^"]*"),"Data":(null|"[^"]*")\}/,
55
+ headers: {'Content-Type' => 'application/json'}
56
+ )
53
57
  end
54
58
 
55
59
  it 'should serialize DateTime to iso8601 when given' do
56
60
  subject.magic(parameter1: DateTime.now)
57
- expect(WebMock).to have_requested(:post, 'http://www.example.com/Unity/UnityService.svc/json/MagicJson').with(body: /\{"Action":(null|"[^"]*"),"AppUserID":(null|"[^"]*"),"Appname":(null|"[^"]*"),"PatientID":(null|"[^"]*"),"Token":(null|"[^"]*"),"Parameter1":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(-|\+)\d{2}:\d{2}","Parameter2":(null|"[^"]*"),"Parameter3":(null|"[^"]*"),"Parameter4":(null|"[^"]*"),"Parameter5":(null|"[^"]*"),"Parameter6":(null|"[^"]*"),"Data":(null|"[^"]*")\}/, headers: { 'Content-Type' => 'application/json' })
61
+ expect(WebMock).to have_requested(:post, 'http://www.example.com/Unity/UnityService.svc/json/MagicJson').
62
+ with(body: /\{"Action":(null|"[^"]*"),"AppUserID":(null|"[^"]*"),"Appname":(null|"[^"]*"),"PatientID":(null|"[^"]*"),"Token":(null|"[^"]*"),"Parameter1":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(-|\+)\d{2}:\d{2}","Parameter2":(null|"[^"]*"),"Parameter3":(null|"[^"]*"),"Parameter4":(null|"[^"]*"),"Parameter5":(null|"[^"]*"),"Parameter6":(null|"[^"]*"),"Data":(null|"[^"]*")\}/,
63
+ headers: { 'Content-Type' => 'application/json' }
64
+ )
58
65
  end
59
66
 
60
67
  it 'should call start_timer' do
@@ -144,109 +151,4 @@ describe AllscriptsUnityClient::JSONClientDriver do
144
151
  it { expect { subject.send(:raise_if_response_error, error_string) }.to raise_error(AllscriptsUnityClient::APIError) }
145
152
  end
146
153
  end
147
-
148
- describe '#build_faraday_options' do
149
- context 'when given options with ca_file' do
150
- it 'sets ca_file' do
151
- client_driver = build(:json_client_driver, ca_file: 'test_file')
152
- expect(client_driver.send(:build_faraday_options)[:ssl][:ca_file]).to eq('test_file')
153
- end
154
- end
155
-
156
- context 'when given options with ca_path' do
157
- it 'sets ca_path' do
158
- client_driver = build(:json_client_driver, ca_path: 'test_path')
159
- expect(client_driver.send(:build_faraday_options)[:ssl][:ca_path]).to eq('test_path')
160
- end
161
- end
162
-
163
- context 'when given options with nil ca_file and ca_path' do
164
- it 'calls JSONClientDriver.find_ca_file' do
165
- allow(AllscriptsUnityClient::JSONClientDriver).to receive(:find_ca_file).and_return('/test/file')
166
- expect(subject.send(:build_faraday_options)[:ssl][:ca_file]).to eq('/test/file')
167
- end
168
- end
169
-
170
- context 'when given options with nil ca_file, ca_path, and JSONClientDriver.find_ca_file returns nil' do
171
- it 'calls JSONClientDriver.find_ca_file' do
172
- allow(AllscriptsUnityClient::JSONClientDriver).to receive(:find_ca_file).and_return(nil)
173
- allow(AllscriptsUnityClient::JSONClientDriver).to receive(:find_ca_path).and_return('/test/path')
174
- expect(subject.send(:build_faraday_options)[:ssl][:ca_path]).to eq('/test/path')
175
- end
176
- end
177
- end
178
-
179
- describe '.find_ca_path' do
180
- context 'when Ubuntu certs path is found' do
181
- it 'returns the Ubuntu certs path' do
182
- allow(File).to receive(:directory?).with('/usr/lib/ssl/certs').and_return(true)
183
- expect(AllscriptsUnityClient::JSONClientDriver.send(:find_ca_path)).to eq('/usr/lib/ssl/certs')
184
- end
185
- end
186
-
187
- context 'when no certificate path is found' do
188
- it 'returns nil' do
189
- allow(File).to receive(:directory?).with('/usr/lib/ssl/certs').and_return(false)
190
- expect(AllscriptsUnityClient::JSONClientDriver.send(:find_ca_path)).to be_nil
191
- end
192
- end
193
- end
194
-
195
- describe '.find_ca_file' do
196
- context 'when OS X ca-bundle.crt found' do
197
- it 'returns the ca-bundle.crt' do
198
- allow(File).to receive(:exists?).with('/opt/boxen/homebrew/opt/curl-ca-bundle/share/ca-bundle.crt').and_return(true)
199
- expect(AllscriptsUnityClient::JSONClientDriver.send(:find_ca_file)).to eq('/opt/boxen/homebrew/opt/curl-ca-bundle/share/ca-bundle.crt')
200
- end
201
- end
202
-
203
- context 'when OS X curl-ca-bundle.crt found' do
204
- it 'returns the curl-ca-bundle.crt' do
205
- allow(File).to receive(:exists?).with('/opt/boxen/homebrew/opt/curl-ca-bundle/share/ca-bundle.crt').and_return(false)
206
- allow(File).to receive(:exists?).with('/opt/local/share/curl/curl-ca-bundle.crt').and_return(true)
207
- expect(AllscriptsUnityClient::JSONClientDriver.send(:find_ca_file)).to eq('/opt/local/share/curl/curl-ca-bundle.crt')
208
- end
209
- end
210
-
211
- context 'when CentOS ca-certificates.crt found' do
212
- it 'returns the curl-ca-bundle.crt' do
213
- allow(File).to receive(:exists?).with('/opt/boxen/homebrew/opt/curl-ca-bundle/share/ca-bundle.crt').and_return(false)
214
- allow(File).to receive(:exists?).with('/opt/local/share/curl/curl-ca-bundle.crt').and_return(false)
215
- allow(File).to receive(:exists?).with('/usr/lib/ssl/certs/ca-certificates.crt').and_return(true)
216
- expect(AllscriptsUnityClient::JSONClientDriver.send(:find_ca_file)).to eq('/usr/lib/ssl/certs/ca-certificates.crt')
217
- end
218
- end
219
-
220
- context 'when no certificate file is found' do
221
- it 'returns nil' do
222
- allow(File).to receive(:exists?).with('/opt/boxen/homebrew/opt/curl-ca-bundle/share/ca-bundle.crt').and_return(false)
223
- allow(File).to receive(:exists?).with('/opt/local/share/curl/curl-ca-bundle.crt').and_return(false)
224
- allow(File).to receive(:exists?).with('/usr/lib/ssl/certs/ca-certificates.crt').and_return(false)
225
- expect(AllscriptsUnityClient::JSONClientDriver.send(:find_ca_file)).to be_nil
226
- end
227
- end
228
- end
229
-
230
- describe '.set_request_timeout' do
231
- context 'when given options with timeout set' do
232
- it 'sets timeout and open_timeout on the request' do
233
- client_driver = build(:json_client_driver, timeout: 10)
234
- options = {}
235
- request = double('request', options: options)
236
- client_driver.send(:set_request_timeout, request)
237
- expect(options[:timeout]).to eq(10)
238
- expect(options[:open_timeout]).to eq(10)
239
- end
240
- end
241
-
242
- context 'when given options without timeout set' do
243
- it 'sets timeout and open_timeout to 90 on the request' do
244
- options = {}
245
- request = double('request', options: options)
246
- subject.send(:set_request_timeout, request)
247
- expect(options[:timeout]).to eq(90)
248
- expect(options[:open_timeout]).to eq(90)
249
- end
250
- end
251
- end
252
- end
154
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,15 +1,6 @@
1
1
  require 'pathname'
2
2
  require 'simplecov'
3
3
 
4
- # Setup coveralls only if running inside Travis-CI
5
- if ENV['TRAVIS']
6
- require 'coveralls'
7
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
8
- SimpleCov::Formatter::HTMLFormatter,
9
- Coveralls::SimpleCov::Formatter
10
- ]
11
- end
12
-
13
4
  # Configure coverage stats.
14
5
  SimpleCov.start do
15
6
  ignored_files = %w(version.rb allscripts_unity_client.gemspec Gemfile Rakefile)
@@ -26,7 +17,6 @@ $:.unshift lib unless $:.include?(lib)
26
17
  require 'allscripts_unity_client'
27
18
  require 'rspec'
28
19
  require 'webmock/rspec'
29
- require 'savon/mock/spec_helper'
30
20
  require 'securerandom'
31
21
  require 'faker'
32
22
  require 'factory_girl'
@@ -92,4 +82,4 @@ RSpec.configure do |config|
92
82
  # a real object. This is generally recommended.
93
83
  # mocks.verify_partial_doubles = true
94
84
  end
95
- end
85
+ end
@@ -1,18 +1,4 @@
1
1
  shared_examples 'a client driver' do
2
- describe '#initialize' do
3
- context 'when options.new_relic is true' do
4
- it 'enables NewRelic tracing' do
5
- allow(AllscriptsUnityClient::NewRelicSupport).to receive(:enable_method_tracer)
6
- allow(described_class).to receive(:add_method_tracer)
7
- new_relic_client_driver
8
- expect(AllscriptsUnityClient::NewRelicSupport).to have_received(:enable_method_tracer).with(new_relic_client_driver)
9
- expect(described_class).to have_received(:add_method_tracer).with(:magic)
10
- expect(described_class).to have_received(:add_method_tracer).with(:get_security_token!)
11
- expect(described_class).to have_received(:add_method_tracer).with(:retire_security_token!)
12
- end
13
- end
14
- end
15
-
16
2
  describe '#security_token?' do
17
3
  context 'when @security_token is nil' do
18
4
  it do
@@ -129,4 +115,4 @@ shared_examples 'a client driver' do
129
115
  expect(subject.instance_variable_get('@timer')).to eq(subject.instance_variable_get('@end_time') - subject.instance_variable_get('@start_time'))
130
116
  end
131
117
  end
132
- end
118
+ end
metadata CHANGED
@@ -1,72 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: allscripts_unity_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.4
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Ash Gupta
8
- - Neil Goodman
7
+ - Lucian Cesca
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-01-16 00:00:00.000000000 Z
11
+ date: 2015-03-18 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: savon
14
+ name: httpclient
16
15
  requirement: !ruby/object:Gem::Requirement
17
16
  requirements:
18
17
  - - "~>"
19
18
  - !ruby/object:Gem::Version
20
- version: 2.6.0
19
+ version: '2.6'
21
20
  type: :runtime
22
21
  prerelease: false
23
22
  version_requirements: !ruby/object:Gem::Requirement
24
23
  requirements:
25
24
  - - "~>"
26
25
  - !ruby/object:Gem::Version
27
- version: 2.6.0
28
- - !ruby/object:Gem::Dependency
29
- name: faraday
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - "~>"
33
- - !ruby/object:Gem::Version
34
- version: 0.9.0
35
- type: :runtime
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - "~>"
40
- - !ruby/object:Gem::Version
41
- version: 0.9.0
42
- - !ruby/object:Gem::Dependency
43
- name: em-http-request
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - "~>"
47
- - !ruby/object:Gem::Version
48
- version: 1.1.2
49
- type: :runtime
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - "~>"
54
- - !ruby/object:Gem::Version
55
- version: 1.1.2
26
+ version: '2.6'
56
27
  - !ruby/object:Gem::Dependency
57
28
  name: activesupport
58
29
  requirement: !ruby/object:Gem::Requirement
59
30
  requirements:
60
31
  - - ">="
61
32
  - !ruby/object:Gem::Version
62
- version: '0'
33
+ version: '3'
63
34
  type: :runtime
64
35
  prerelease: false
65
36
  version_requirements: !ruby/object:Gem::Requirement
66
37
  requirements:
67
38
  - - ">="
68
39
  - !ruby/object:Gem::Version
69
- version: '0'
40
+ version: '3'
70
41
  - !ruby/object:Gem::Dependency
71
42
  name: nokogiri
72
43
  requirement: !ruby/object:Gem::Requirement
@@ -116,19 +87,19 @@ dependencies:
116
87
  - !ruby/object:Gem::Version
117
88
  version: 1.1.0
118
89
  - !ruby/object:Gem::Dependency
119
- name: oj
90
+ name: multi_json
120
91
  requirement: !ruby/object:Gem::Requirement
121
92
  requirements:
122
93
  - - "~>"
123
94
  - !ruby/object:Gem::Version
124
- version: 2.9.8
95
+ version: '1.0'
125
96
  type: :runtime
126
97
  prerelease: false
127
98
  version_requirements: !ruby/object:Gem::Requirement
128
99
  requirements:
129
100
  - - "~>"
130
101
  - !ruby/object:Gem::Version
131
- version: 2.9.8
102
+ version: '1.0'
132
103
  - !ruby/object:Gem::Dependency
133
104
  name: rubyntlm
134
105
  requirement: !ruby/object:Gem::Requirement
@@ -199,20 +170,6 @@ dependencies:
199
170
  - - "~>"
200
171
  - !ruby/object:Gem::Version
201
172
  version: 3.0.0
202
- - !ruby/object:Gem::Dependency
203
- name: simplecov
204
- requirement: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - "~>"
207
- - !ruby/object:Gem::Version
208
- version: 0.8.2
209
- type: :development
210
- prerelease: false
211
- version_requirements: !ruby/object:Gem::Requirement
212
- requirements:
213
- - - "~>"
214
- - !ruby/object:Gem::Version
215
- version: 0.8.2
216
173
  - !ruby/object:Gem::Dependency
217
174
  name: webmock
218
175
  requirement: !ruby/object:Gem::Requirement
@@ -228,24 +185,23 @@ dependencies:
228
185
  - !ruby/object:Gem::Version
229
186
  version: 1.18.0
230
187
  - !ruby/object:Gem::Dependency
231
- name: coveralls
188
+ name: simplecov
232
189
  requirement: !ruby/object:Gem::Requirement
233
190
  requirements:
234
191
  - - "~>"
235
192
  - !ruby/object:Gem::Version
236
- version: 0.7.0
193
+ version: 0.7.1
237
194
  type: :development
238
195
  prerelease: false
239
196
  version_requirements: !ruby/object:Gem::Requirement
240
197
  requirements:
241
198
  - - "~>"
242
199
  - !ruby/object:Gem::Version
243
- version: 0.7.0
244
- description: Provides a simple interface to the Allscripts Unity API using JSON or
245
- SOAP. Developed at healthfinch, Inc. http://healthfinch.com
200
+ version: 0.7.1
201
+ description: Provides a simple interface to the Allscripts Unity API using JSON. Developed
202
+ at healthfinch http://healthfinch.com
246
203
  email:
247
- - ash.gupta@healthfinch.com
248
- - neil@healthfinch.com
204
+ - lucian@healthfinch.com
249
205
  executables: []
250
206
  extensions: []
251
207
  extra_rdoc_files: []
@@ -265,8 +221,6 @@ files:
265
221
  - lib/allscripts_unity_client/json_client_driver.rb
266
222
  - lib/allscripts_unity_client/json_unity_request.rb
267
223
  - lib/allscripts_unity_client/json_unity_response.rb
268
- - lib/allscripts_unity_client/new_relic_support.rb
269
- - lib/allscripts_unity_client/soap_client_driver.rb
270
224
  - lib/allscripts_unity_client/unity_request.rb
271
225
  - lib/allscripts_unity_client/unity_response.rb
272
226
  - lib/allscripts_unity_client/utilities.rb
@@ -305,12 +259,9 @@ files:
305
259
  - spec/json_client_driver_spec.rb
306
260
  - spec/json_unity_request_spec.rb
307
261
  - spec/json_unity_response_spec.rb
308
- - spec/new_relic_support_spec.rb
309
- - spec/soap_client_driver_spec.rb
310
262
  - spec/spec_helper.rb
311
263
  - spec/support/factory_girl.rb
312
264
  - spec/support/fixture_loader.rb
313
- - spec/support/new_relic.rb
314
265
  - spec/support/shared_examples_for_client_driver.rb
315
266
  - spec/support/shared_examples_for_unity_request.rb
316
267
  - spec/support/shared_examples_for_unity_response.rb
@@ -329,7 +280,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
329
280
  requirements:
330
281
  - - ">"
331
282
  - !ruby/object:Gem::Version
332
- version: 1.9.3
283
+ version: 2.0.0
333
284
  required_rubygems_version: !ruby/object:Gem::Requirement
334
285
  requirements:
335
286
  - - ">="
@@ -337,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
337
288
  version: '0'
338
289
  requirements: []
339
290
  rubyforge_project:
340
- rubygems_version: 2.2.2
291
+ rubygems_version: 2.4.3
341
292
  signing_key:
342
293
  specification_version: 4
343
294
  summary: Allscripts Unity API client
@@ -1,30 +0,0 @@
1
- module AllscriptsUnityClient
2
-
3
- # A mixin to provide support for New Relic instrumentation.
4
- module NewRelicSupport
5
-
6
- # Mixin NewRelic::Agent::MethodTracer for a given object.
7
- #
8
- # instance:: The object to use as the target for the mixin.
9
- def self.enable_method_tracer(instance)
10
- class << instance
11
- if !respond_to?(:trace_execution_scoped) && !respond_to?(:add_method_tracer)
12
- extend ::NewRelic::Agent::MethodTracer
13
- end
14
- end
15
- end
16
-
17
- # If a given class supports New Relic trace_execution_scoped, then
18
- # run the given block using that method.
19
- #
20
- # klass:: The target class.
21
- # scope:: A New Relic scope string.
22
- def self.trace_execution_scoped_if_available(klass, scope)
23
- if klass.respond_to?(:trace_execution_scoped)
24
- klass.trace_execution_scoped(scope, &Proc.new)
25
- else
26
- yield if block_given?
27
- end
28
- end
29
- end
30
- end
@@ -1,145 +0,0 @@
1
- require 'savon'
2
-
3
- module AllscriptsUnityClient
4
-
5
- # A ClientDriver that supports Unity's SOAP endpoints.
6
- class SOAPClientDriver < ClientDriver
7
- attr_accessor :savon_client
8
-
9
- UNITY_SOAP_ENDPOINT = '/Unity/UnityService.svc/unityservice'
10
- UNITY_ENDPOINT_NAMESPACE = 'http://www.allscripts.com/Unity/IUnityService'
11
-
12
- # Constructor.
13
- #
14
- # options:: See ClientOptions.
15
- def initialize(options)
16
- super
17
-
18
- client_proxy = @options.proxy
19
- base_unity_url = "#{@options.base_unity_url}#{UNITY_SOAP_ENDPOINT}"
20
-
21
- @savon_client = Savon.client do
22
- # Removes the wsdl: namespace from body elements in the SOAP
23
- # request. Unity doesn't recognize elements otherwise.
24
- namespace_identifier nil
25
-
26
- # Manually registers SOAP endpoint since Unity WSDL is not very
27
- # good.
28
- endpoint base_unity_url
29
-
30
- # Manually register SOAP namespace. This URL isn't live, but the
31
- # internal SOAP endpoints expect it.
32
- namespace 'http://www.allscripts.com/Unity'
33
-
34
- # Register proxy with Savon if one was given.
35
- unless client_proxy.nil?
36
- proxy client_proxy
37
- end
38
-
39
- # Unity expects the SOAP envelop to be namespaced with soap:
40
- env_namespace :soap
41
-
42
- # Unity uses Microsoft style CamelCase for keys. Only really useful when using
43
- # symbol keyed hashes.
44
- convert_request_keys_to :camelcase
45
-
46
- # Enable gzip on HTTP responses. Unity does not currently support this
47
- # as of Born On 10/7/2013, but it doesn't hurt to future-proof. If gzip
48
- # is ever enabled, this library will get a speed bump for free.
49
- headers({ 'Accept-Encoding' => 'gzip,deflate'})
50
-
51
- # Disable Savon logs
52
- log false
53
- end
54
- end
55
-
56
- # Returns :soap.
57
- def client_type
58
- :soap
59
- end
60
-
61
- # See Client#magic.
62
- def magic(parameters = {})
63
- request_data = UnityRequest.new(parameters, @options.timezone, @options.appname, @security_token)
64
- call_data = {
65
- message: request_data.to_hash,
66
- soap_action: "#{UNITY_ENDPOINT_NAMESPACE}/Magic"
67
- }
68
-
69
- response = nil
70
- begin
71
- start_timer
72
- NewRelicSupport.trace_execution_scoped_if_available(self.class, ["Custom/UnitySOAP/#{parameters[:action]}"]) do
73
- response = @savon_client.call('Magic', call_data)
74
- end_timer
75
- end
76
- rescue Savon::SOAPFault => e
77
- raise APIError, e.message
78
- end
79
-
80
- log_magic(request_data)
81
-
82
- response = UnityResponse.new(response.body, @options.timezone)
83
- response.to_hash
84
- end
85
-
86
- # See Client#get_security_token!.
87
- def get_security_token!(parameters = {})
88
- username = parameters[:username] || @options.username
89
- password = parameters[:password] || @options.password
90
- appname = parameters[:appname] || @options.appname
91
-
92
- call_data = {
93
- message: {
94
- 'Username' => username,
95
- 'Password' => password,
96
- 'Appname' => appname
97
- },
98
- soap_action: "#{UNITY_ENDPOINT_NAMESPACE}/GetSecurityToken"
99
- }
100
-
101
- begin
102
- start_timer
103
- response = nil
104
- NewRelicSupport.trace_execution_scoped_if_available(self.class, ["Custom/UnitySOAP/GetToken"]) do
105
- response = @savon_client.call('GetSecurityToken', call_data)
106
- end_timer
107
- end
108
- rescue Savon::SOAPFault => e
109
- raise APIError, e.message
110
- end
111
-
112
- log_get_security_token
113
-
114
- @security_token = response.body[:get_security_token_response][:get_security_token_result]
115
- end
116
-
117
- # See Client#retire_security_token!.
118
- def retire_security_token!(parameters = {})
119
- token = parameters[:token] || @security_token
120
- appname = parameters[:appname] || @options.appname
121
-
122
- call_data = {
123
- message: {
124
- 'Token' => token,
125
- 'Appname' => appname
126
- },
127
- soap_action: "#{UNITY_ENDPOINT_NAMESPACE}/RetireSecurityToken"
128
- }
129
-
130
- begin
131
- start_timer
132
- NewRelicSupport.trace_execution_scoped_if_available(self.class, ["Custom/UnitySOAP/RetireSecurityToken"]) do
133
- @savon_client.call('RetireSecurityToken', call_data)
134
- end_timer
135
- end
136
- rescue Savon::SOAPFault => e
137
- raise APIError, e.message
138
- end
139
-
140
- log_retire_security_token
141
-
142
- @security_token = nil
143
- end
144
- end
145
- end
@@ -1,49 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe AllscriptsUnityClient::NewRelicSupport do
4
- subject { described_class }
5
- let(:scope) { ['scope'] }
6
- let(:block) { lambda {} }
7
-
8
- before :all do
9
- # Mock a test class for NewRelic mixin tests.
10
- class NewRelicSupportTest
11
- end
12
- end
13
-
14
- describe '.enable_method_tracer' do
15
- context 'when given an object that does not have the NewRelic::Agent::MethodTracer module mixed in' do
16
- it 'mixes in the NewRelic::Agent::MethodTracer module' do
17
- allow(NewRelicSupportTest).to receive(:extend)
18
- subject.enable_method_tracer(NewRelicSupportTest.new)
19
- expect(NewRelicSupportTest).to have_received(:extend).with(::NewRelic::Agent::MethodTracer)
20
- end
21
- end
22
-
23
- context 'when given an object that does have the NewRelic::Agent::MethodTracer module mixed in' do
24
- it 'does not mix in the NewRelic::Agent::MethodTracer module' do
25
- allow(NewRelicSupportTest).to receive(:extend)
26
- allow(NewRelicSupportTest).to receive(:trace_execution_scoped)
27
- allow(NewRelicSupportTest).to receive(:add_method_tracer)
28
- subject.enable_method_tracer(NewRelicSupportTest.new)
29
- expect(NewRelicSupportTest).not_to have_received(:extend).with(::NewRelic::Agent::MethodTracer)
30
- end
31
- end
32
- end
33
-
34
- describe '.trace_execution_scoped_if_available' do
35
- context 'when a class does not have trace_execution_scoped and is given block' do
36
- it 'will yield to the block' do
37
- expect { |b| subject.trace_execution_scoped_if_available(NewRelicSupportTest, scope, &b) }.to yield_control
38
- end
39
- end
40
-
41
- context 'when a class has trace_execution_scoped and is given a block' do
42
- it 'will pass the block to trace_execution_scoped' do
43
- allow(NewRelicSupportTest).to receive(:trace_execution_scoped)
44
- subject.trace_execution_scoped_if_available(NewRelicSupportTest, scope, &block)
45
- expect(NewRelicSupportTest).to have_received(:trace_execution_scoped).with(scope)
46
- end
47
- end
48
- end
49
- end