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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: adb3d7f5fb0cac264e9ee0e8bcdecef49321ba97
4
- data.tar.gz: 4006475b317abf982369272640bacea76444aee4
3
+ metadata.gz: d45ff82ffa1f0cc9f7e439e29b36a7d41f9508b9
4
+ data.tar.gz: 78af373698dce39e44131bd8b0492233f84b2e8b
5
5
  SHA512:
6
- metadata.gz: 8b55859ebfcf46a3324d9f05894dc848227191713735dff741268ba8e3f33a3a195d143940af5e29e1fb69002aceda1c5b324a8605eb70a298365b19fc2b97b0
7
- data.tar.gz: 258a046184bcc8abe5b12b99f9dea5fcd91d10f09b4b4cfa733ca26f2dcdf8ac4eeed7b51297b080033e6db38159f82e890b8ce3ab8dedc9c4df553dd5c93be8
6
+ metadata.gz: 84e1d6cd45ea3a3f370504fbf331dd253a546bf448af2270608590b281cc1c7cc4b93b81388375225561dab6a4fb0b9e9ce91cb71189b1f6ddb981c219fe0207
7
+ data.tar.gz: 84e593af4e43f27e40bd8954a356f3eaa06a02909dd7c0c162a187465f71ad9bff62726b62624129d1ebae543b8bd8ff9d329d070ffaacbcbe0ba788e4951a1e
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Allscripts Unity Client [![Build Status](https://travis-ci.org/healthfinch/allscripts-unity-client.png?branch=master)](https://travis-ci.org/healthfinch/allscripts-unity-client) [![Coverage Status](https://coveralls.io/repos/healthfinch/allscripts-unity-client/badge.png?branch=master)](https://coveralls.io/r/healthfinch/allscripts-unity-client?branch=master)
2
2
 
3
3
  The `allscripts_unity_client` gem is a Ruby client for the Allscripts Unity API. See http://remotecentral.allscripts.com/UnityAPIReference for more documentation on the API.
4
-
4
+
5
5
  ## Installation
6
6
 
7
7
  Add this line to your application's Gemfile:
@@ -245,26 +245,6 @@ unity_client = AllscriptsUnityClient.create({
245
245
  This gem uses the [american_date](http://rubygems.org/gems/american_date) gem to force `Date.parse` to
246
246
  accept USA locale dates by default. There are currently no plans to support other locales. Pull requests welcome.
247
247
 
248
- ### New Relic support
249
-
250
- New Relic is supported for tracing Unity HTTP requests and the overall time processing the reqeusts takes. To enable
251
- New Relic, simply require the gem in your project and enable it on the client:
252
-
253
- ```ruby
254
- require 'newrelic_rpm'
255
- NewRelic::Agent.manual_start
256
-
257
- unity_client = AllscriptsUnityClient.create({
258
- base_unity_url: "http://unity.base.url",
259
- appname: "appname",
260
- username: "username",
261
- password: "password",
262
- new_relic: true
263
- })
264
- ```
265
-
266
- For more information on the New Relic gem, go here: (https://github.com/newrelic/rpm)
267
-
268
248
  ## Examples
269
249
 
270
250
  ### GetServerInfo SOAP
@@ -363,4 +343,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
363
343
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
364
344
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
365
345
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
366
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
346
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -8,35 +8,32 @@ Gem::Specification.new do |gem|
8
8
  gem.name = 'allscripts_unity_client'
9
9
  gem.version = AllscriptsUnityClient::VERSION
10
10
  gem.date = Date.today
11
- gem.required_ruby_version = '> 1.9.3'
11
+ gem.required_ruby_version = '> 2.0.0'
12
12
  gem.license = 'MIT'
13
13
  gem.homepage = 'https://github.com/healthfinch/allscripts-unity-client'
14
14
 
15
15
  gem.summary = 'Allscripts Unity API client'
16
- gem.description = 'Provides a simple interface to the Allscripts Unity API using JSON or SOAP. Developed at healthfinch, Inc. http://healthfinch.com'
16
+ gem.description = 'Provides a simple interface to the Allscripts Unity API using JSON. Developed at healthfinch http://healthfinch.com'
17
17
 
18
- gem.authors = ['Ash Gupta', 'Neil Goodman']
19
- gem.email = %w(ash.gupta@healthfinch.com neil@healthfinch.com)
18
+ gem.authors = ['Lucian Cesca']
19
+ gem.email = %w(lucian@healthfinch.com)
20
20
 
21
21
  gem.require_paths = ['lib']
22
22
 
23
23
  gem.files = `git ls-files`.split("\n").delete_if { |file| /^\.ruby-version$/.match(file) }
24
24
 
25
- gem.add_runtime_dependency 'savon', '~> 2.6.0'
26
- gem.add_runtime_dependency 'faraday', '~> 0.9.0'
27
- gem.add_runtime_dependency 'em-http-request', '~> 1.1.2'
28
- gem.add_runtime_dependency 'activesupport', '>= 0'
29
- gem.add_runtime_dependency 'nokogiri', '< 1.6', '>= 1.4.0'
30
- gem.add_runtime_dependency 'nori', '~> 2.4.0'
31
- gem.add_runtime_dependency 'american_date', '~> 1.1.0'
32
- gem.add_runtime_dependency 'oj', '~> 2.9.8'
33
- gem.add_runtime_dependency 'rubyntlm', '~> 0.4.0'
25
+ gem.add_dependency 'httpclient', '~> 2.6'
26
+ gem.add_dependency 'activesupport', '>= 3'
27
+ gem.add_dependency 'nokogiri', '< 1.6', '>= 1.4.0'
28
+ gem.add_dependency 'nori', '~> 2.4.0'
29
+ gem.add_dependency 'american_date', '~> 1.1.0'
30
+ gem.add_dependency 'multi_json', '~> 1.0'
31
+ gem.add_dependency 'rubyntlm', '~> 0.4.0'
34
32
 
35
33
  gem.add_development_dependency 'factory_girl', '~> 4.4.0'
36
34
  gem.add_development_dependency 'rake', '~> 10.3.1'
37
35
  gem.add_development_dependency 'faker', '~> 1.4.2'
38
36
  gem.add_development_dependency 'rspec', '~> 3.0.0'
39
- gem.add_development_dependency 'simplecov', '~> 0.8.2'
40
37
  gem.add_development_dependency 'webmock', '~> 1.18.0'
41
- gem.add_development_dependency 'coveralls', '~> 0.7.0'
38
+ gem.add_development_dependency 'simplecov', '~> 0.7.1'
42
39
  end
@@ -14,17 +14,6 @@ module AllscriptsUnityClient
14
14
  # options:: See ClientOptions.
15
15
  def initialize(options)
16
16
  @options = ClientOptions.new(options)
17
-
18
- # If New Relic support is enabled, setup method tracing
19
- if @options.new_relic
20
- NewRelicSupport.enable_method_tracer(self)
21
-
22
- class << self
23
- add_method_tracer :magic
24
- add_method_tracer :get_security_token!
25
- add_method_tracer :retire_security_token!
26
- end
27
- end
28
17
  end
29
18
 
30
19
  # Returns true if security token is not nil.
@@ -87,4 +76,4 @@ module AllscriptsUnityClient
87
76
  @timer = @end_time - @start_time
88
77
  end
89
78
  end
90
- end
79
+ end
@@ -2,7 +2,7 @@ module AllscriptsUnityClient
2
2
 
3
3
  # Contains various options for Unity configuration.
4
4
  class ClientOptions
5
- attr_accessor :proxy, :logger, :ca_file, :ca_path, :timeout, :new_relic
5
+ attr_accessor :proxy, :logger, :ca_file, :ca_path, :timeout
6
6
  attr_reader :base_unity_url, :username, :password, :appname, :timezone
7
7
 
8
8
  # Constructor.
@@ -17,7 +17,6 @@ module AllscriptsUnityClient
17
17
  # - :ca_file - A string path for a CA File on the OS (JSON only).
18
18
  # - :cs_path - A string path for a CA directory (JSON only).
19
19
  # - :timeout - The number of seconds to set the HTTP response timeout and keepalive timeout (JSON only).
20
- # - :new_relc - If set to true then New Relic mixins will be applied.
21
20
  # - :base_unity_url - The URL where a Unity server is located (i.e. https://unity.server.com) __(required)__
22
21
  def initialize(options = {})
23
22
  @username = options[:username]
@@ -28,7 +27,6 @@ module AllscriptsUnityClient
28
27
  @ca_file = options[:ca_file]
29
28
  @ca_path = options[:ca_path]
30
29
  @timeout = options[:timeout]
31
- @new_relic = options[:new_relic]
32
30
 
33
31
  self.timezone = options[:timezone]
34
32
  self.base_unity_url = options[:base_unity_url]
@@ -118,10 +116,5 @@ module AllscriptsUnityClient
118
116
  def timeout?
119
117
  !@timeout.to_s.strip.empty?
120
118
  end
121
-
122
- # Return true if new_relic is not nil.
123
- def new_relic?
124
- !@new_relic.nil?
125
- end
126
119
  end
127
- end
120
+ end
@@ -1,6 +1,5 @@
1
- require 'oj'
2
- require 'faraday'
3
- require 'em-http-request'
1
+ require 'multi_json'
2
+ require 'httpclient'
4
3
 
5
4
  module AllscriptsUnityClient
6
5
 
@@ -10,39 +9,52 @@ module AllscriptsUnityClient
10
9
 
11
10
  UNITY_JSON_ENDPOINT = '/Unity/UnityService.svc/json'
12
11
 
13
- # Constructor.
14
- #
15
- # options:: See ClientOptions.
16
12
  def initialize(options)
17
13
  super
18
- @connection = Faraday.new(build_faraday_options) do |conn|
19
- conn.adapter :em_http
20
- end
14
+
15
+
16
+ @connection = HTTPClient.new(
17
+ proxy: @options.proxy,
18
+ default_header: {'Content-Type' => 'application/json'}
19
+ )
20
+
21
+ set_http_client_ssl_config
22
+ set_http_client_timeouts
23
+ end
24
+
25
+ def set_http_client_timeouts
26
+ @connection.connect_timeout = @options.timeout || 90
27
+ @connection.send_timeout = @options.timeout || 90
28
+ @connection.receive_timeout = @options.timeout || 90
29
+ end
30
+
31
+ def set_http_client_ssl_config
32
+ ssl_options = OpenSSL::SSL::OP_ALL
33
+ ssl_options &= ~OpenSSL::SSL::OP_DONT_INSERT_EMPTY_FRAGMENTS if defined?(OpenSSL::SSL::OP_DONT_INSERT_EMPTY_FRAGMENTS)
34
+ ssl_options |= OpenSSL::SSL::OP_NO_COMPRESSION if defined?(OpenSSL::SSL::OP_NO_COMPRESSION)
35
+ ssl_options |= OpenSSL::SSL::OP_NO_SSLv2 if defined?(OpenSSL::SSL::OP_NO_SSLv2)
36
+ ssl_options |= OpenSSL::SSL::OP_NO_SSLv3 if defined?(OpenSSL::SSL::OP_NO_SSLv3)
37
+
38
+ @connection.ssl_config.options = ssl_options
39
+ @connection.ssl_config.ciphers = "ALL:!aNULL:!eNULL:!SSLv2"
40
+ end
41
+
42
+ def build_uri(request_location)
43
+ "#{@options.base_unity_url}#{[UNITY_JSON_ENDPOINT, request_location].join('/')}"
21
44
  end
22
45
 
23
- # Returns :json.
24
46
  def client_type
25
47
  :json
26
48
  end
27
49
 
28
- # See Client#magic.
29
50
  def magic(parameters = {})
30
51
  request_data = JSONUnityRequest.new(parameters, @options.timezone, @options.appname, @security_token)
31
52
 
32
- response = nil
33
- NewRelicSupport.trace_execution_scoped_if_available(self.class, ["Custom/UnityJSON/#{parameters[:action]}"]) do
34
- response = @connection.post do |request|
35
- request.url "#{UNITY_JSON_ENDPOINT}/MagicJson"
36
- request.headers['Content-Type'] = 'application/json'
37
- request.body = Oj.dump(request_data.to_hash, mode: :compat)
38
- set_request_timeout(request)
39
-
40
- start_timer
41
- end
42
- end_timer
43
- end
53
+ start_timer
54
+ response = @connection.post(build_uri('MagicJson'), MultiJson.dump(request_data.to_hash))
55
+ end_timer
44
56
 
45
- response = Oj.load(response.body, mode: :strict)
57
+ response = MultiJson.load(response.body)
46
58
 
47
59
  raise_if_response_error(response)
48
60
  log_magic(request_data)
@@ -63,18 +75,9 @@ module AllscriptsUnityClient
63
75
  'Appname' => appname
64
76
  }
65
77
 
66
- response = nil
67
- NewRelicSupport.trace_execution_scoped_if_available(self.class, ["Custom/UnityJSON/GetToken"]) do
68
- response = @connection.post do |request|
69
- request.url "#{UNITY_JSON_ENDPOINT}/GetToken"
70
- request.headers['Content-Type'] = 'application/json'
71
- request.body = Oj.dump(request_data, mode: :compat)
72
- set_request_timeout(request)
73
-
74
- start_timer
75
- end
76
- end_timer
77
- end
78
+ start_timer
79
+ response = @connection.post(build_uri('GetToken'), MultiJson.dump(request_data.to_hash))
80
+ end_timer
78
81
 
79
82
  raise_if_response_error(response.body)
80
83
  log_get_security_token
@@ -92,18 +95,9 @@ module AllscriptsUnityClient
92
95
  'Appname' => appname
93
96
  }
94
97
 
95
- response = nil
96
- NewRelicSupport.trace_execution_scoped_if_available(self.class, ["Custom/UnityJSON/RetireSecurityToken"]) do
97
- response = @connection.post do |request|
98
- request.url "#{UNITY_JSON_ENDPOINT}/RetireSecurityToken"
99
- request.headers['Content-Type'] = 'application/json'
100
- request.body = Oj.dump(request_data, mode: :compat)
101
- set_request_timeout(request)
102
-
103
- start_timer
104
- end
105
- end_timer
106
- end
98
+ start_timer
99
+ response = @connection.post(build_uri('RetireSecurityToken'), MultiJson.dump(request_data.to_hash))
100
+ end_timer
107
101
 
108
102
  raise_if_response_error(response.body)
109
103
  log_retire_security_token
@@ -122,64 +116,5 @@ module AllscriptsUnityClient
122
116
  raise APIError, response
123
117
  end
124
118
  end
125
-
126
- def build_faraday_options
127
- options = {}
128
-
129
- # Configure Faraday base url
130
- options[:url] = @options.base_unity_url
131
-
132
- # Configure root certificates for Faraday using options or via auto-detection
133
- if @options.ca_file?
134
- options[:ssl] = { ca_file: @options.ca_file }
135
- elsif @options.ca_path?
136
- options[:ssl] = { ca_path: @options.ca_path }
137
- elsif ca_file = JSONClientDriver.find_ca_file
138
- options[:ssl] = { ca_file: ca_file }
139
- elsif ca_path = JSONClientDriver.find_ca_path
140
- options[:ssl] = { ca_path: ca_path }
141
- end
142
-
143
- # Configure proxy
144
- if @options.proxy?
145
- options[:proxy] = @options.proxy
146
- end
147
-
148
- options
149
- end
150
-
151
- def self.find_ca_path
152
- if File.directory?('/usr/lib/ssl/certs')
153
- return '/usr/lib/ssl/certs'
154
- end
155
-
156
- nil
157
- end
158
-
159
- def self.find_ca_file
160
- if File.exists?('/opt/boxen/homebrew/opt/curl-ca-bundle/share/ca-bundle.crt')
161
- return '/opt/boxen/homebrew/opt/curl-ca-bundle/share/ca-bundle.crt'
162
- end
163
-
164
- if File.exists?('/opt/local/share/curl/curl-ca-bundle.crt')
165
- return '/opt/local/share/curl/curl-ca-bundle.crt'
166
- end
167
-
168
- if File.exists?('/usr/lib/ssl/certs/ca-certificates.crt')
169
- return '/usr/lib/ssl/certs/ca-certificates.crt'
170
- end
171
-
172
- nil
173
- end
174
-
175
- def set_request_timeout(request)
176
- if @options.timeout?
177
- request.options[:timeout] = @options.timeout
178
- request.options[:open_timeout] = @options.timeout
179
- else
180
- request.options[:timeout] = 90
181
- request.options[:open_timeout] = 90
182
- end
183
- end
184
119
  end
185
- end
120
+ end
@@ -9,7 +9,7 @@ module AllscriptsUnityClient
9
9
  DATETIME_REGEX = /^((\d{1,2}[-\/]\d{1,2}[-\/]\d{4})|(\d{4}[-\/]\d{1,2}[-\/]\d{1,2})|(\d{1,2}-[A-Za-z]{3,4}-\d{4})|([A-Za-z]{3,4} +\d{1,2} \d{2,4}))(T| +)(\d{1,2}:\d{2}(:\d{2})?(\.\d+)? ?(PM|AM|pm|am)?((-|\+)\d{2}:?\d{2})?Z?)$/
10
10
  DATE_REGEX = /^((\d{1,2}[-\/]\d{1,2}[-\/]\d{4})|(\d{4}[-\/]\d{1,2}[-\/]\d{1,2})|(\d{1,2}-[A-Za-z]{3,4}-\d{4})|([A-Za-z]{3,4} +\d{1,2} \d{2,4}))$/
11
11
 
12
- # Try to encode a string into a Data or ActiveSupport::TimeWithZone object.
12
+ # Try to encode a string into a Date or ActiveSupport::TimeWithZone object.
13
13
  #
14
14
  # Uses DATETIME_REGEX and DATE_REGEX to match possible date string.
15
15
  #
@@ -85,4 +85,4 @@ module AllscriptsUnityClient
85
85
  hash
86
86
  end
87
87
  end
88
- end
88
+ end
@@ -1,3 +1,3 @@
1
1
  module AllscriptsUnityClient
2
- VERSION = '2.2.4'
2
+ VERSION = '3.0.0'
3
3
  end
@@ -7,9 +7,7 @@ require 'allscripts_unity_client/json_unity_response'
7
7
  require 'allscripts_unity_client/client'
8
8
  require 'allscripts_unity_client/client_driver'
9
9
  require 'allscripts_unity_client/client_options'
10
- require 'allscripts_unity_client/soap_client_driver'
11
10
  require 'allscripts_unity_client/json_client_driver'
12
- require 'allscripts_unity_client/new_relic_support'
13
11
 
14
12
  # A library for consuming Allscripts Unity web services.
15
13
  module AllscriptsUnityClient
@@ -25,22 +23,17 @@ module AllscriptsUnityClient
25
23
  #
26
24
  # Returns an instance of Client.
27
25
  def self.create(options = {})
28
- options[:mode] ||= :soap
29
- options[:log] = true unless options[:log] === false
30
- raise_if_options_invalid options
26
+ options[:mode] ||= :json
27
+ if options[:log] != false # explictly
28
+ options[:log] = true
29
+ end
31
30
 
32
31
  if options[:mode] == :json
33
32
  client_driver = JSONClientDriver.new(options)
34
33
  else
35
- client_driver = SOAPClientDriver.new(options)
34
+ raise ArgumentError, ':mode must be :json' unless options[:mode] == :json
36
35
  end
37
36
 
38
37
  Client.new(client_driver)
39
38
  end
40
-
41
- private
42
-
43
- def self.raise_if_options_invalid(options)
44
- raise ArgumentError, ':mode must be :json or :soap' unless [:json, :soap].include?(options[:mode])
45
- end
46
- end
39
+ end
@@ -1,18 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe AllscriptsUnityClient do
4
- include Savon::SpecHelper
5
-
6
4
  subject { described_class }
7
5
 
8
6
  describe '.create' do
9
- context 'when given mode: :soap' do
10
- it 'returns a SOAPClient' do
11
- parameters = build(:allscripts_unity_client_parameters, mode: :soap)
12
- expect(subject.create(parameters).client_type).to be(:soap)
13
- end
14
- end
15
-
16
7
  context 'when given mode: :json' do
17
8
  it 'returns a client with client_type :json' do
18
9
  parameters = build(:allscripts_unity_client_parameters, mode: :json)
@@ -21,25 +12,19 @@ describe AllscriptsUnityClient do
21
12
  end
22
13
 
23
14
  context 'when not given :mode' do
24
- it 'returns a client with client_type :soap' do
15
+ it 'returns a client with client_type :json' do
25
16
  parameters = build(:allscripts_unity_client_parameters)
26
17
  parameters[:mode] = nil
27
- expect(subject.create(parameters).client_type).to be(:soap)
18
+ expect(subject.create(parameters).client_type).to be(:json)
28
19
  end
29
20
  end
30
- end
31
21
 
32
- describe '.raise_if_options_invalid' do
33
- context 'when not given :mode' do
34
- it { expect { subject.send(:raise_if_options_invalid, build(:allscripts_unity_client_parameters, mode: nil)) }.to raise_error(ArgumentError) }
35
- end
36
-
37
- context 'when given mode: :json' do
38
- it { expect { subject.send(:raise_if_options_invalid, build(:allscripts_unity_client_parameters, mode: :json)) }.not_to raise_error }
39
- end
40
-
41
- context 'when given mode: :soap' do
42
- it { expect { subject.send(:raise_if_options_invalid, build(:allscripts_unity_client_parameters, mode: :soap)) }.not_to raise_error }
22
+ context 'when given an invalid :mode' do
23
+ it 'raises an argument error' do
24
+ parameters = build(:allscripts_unity_client_parameters)
25
+ parameters[:mode] = :cheese
26
+ expect { subject.create(parameters) }.to raise_error(ArgumentError, ':mode must be :json')
27
+ end
43
28
  end
44
29
  end
45
- end
30
+ end
@@ -4,7 +4,6 @@ describe AllscriptsUnityClient::ClientDriver do
4
4
  it_behaves_like 'a client driver'
5
5
 
6
6
  subject { build(:client_driver) }
7
- let(:new_relic_client_driver) { build(:client_driver, new_relic: true) }
8
7
 
9
8
  describe '#client_type' do
10
9
  it { expect(subject.client_type).to be(:none) }
@@ -21,4 +20,4 @@ describe AllscriptsUnityClient::ClientDriver do
21
20
  describe '#retire_security_token!' do
22
21
  it { expect { subject.retire_security_token! }.to raise_error(NotImplementedError) }
23
22
  end
24
- end
23
+ end
@@ -182,20 +182,4 @@ describe AllscriptsUnityClient::ClientOptions do
182
182
  end
183
183
  end
184
184
  end
185
-
186
- describe '#new_relic?' do
187
- context 'when new_relic is nil' do
188
- it 'returns false' do
189
- subject.new_relic = nil
190
- expect(subject.new_relic?).to be_falsey
191
- end
192
- end
193
-
194
- context 'when timeout is not nil' do
195
- it 'returns true' do
196
- subject.new_relic = true
197
- expect(subject.new_relic?).to be_truthy
198
- end
199
- end
200
- end
201
- end
185
+ end
@@ -12,9 +12,7 @@ FactoryGirl.define do
12
12
  ca_file nil
13
13
  ca_path nil
14
14
  timeout nil
15
- new_relic nil
16
15
 
17
16
  factory :json_client_driver, class: AllscriptsUnityClient::JSONClientDriver
18
- factory :soap_client_driver, class: AllscriptsUnityClient::SOAPClientDriver
19
17
  end
20
- end
18
+ end
@@ -12,6 +12,5 @@ FactoryGirl.define do
12
12
  ca_file nil
13
13
  ca_path nil
14
14
  timeout nil
15
- new_relic nil
16
15
  end
17
- end
16
+ end