Class: AllscriptsUnityClient::UnityResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/allscripts_unity_client/unity_response.rb

Direct Known Subclasses

JSONUnityResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, timezone) ⇒ UnityResponse

Returns a new instance of UnityResponse.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
# File 'lib/allscripts_unity_client/unity_response.rb', line 7

def initialize(response, timezone)
  raise ArgumentError, 'timezone can not be nil' if timezone.nil?
  raise ArgumentError, 'response can not be nil' if response.nil?

  @response = response
  @timezone = timezone
end

Instance Attribute Details

#responseObject

Returns the value of attribute response.



5
6
7
# File 'lib/allscripts_unity_client/unity_response.rb', line 5

def response
  @response
end

#timezoneObject

Returns the value of attribute timezone.



5
6
7
# File 'lib/allscripts_unity_client/unity_response.rb', line 5

def timezone
  @timezone
end

Instance Method Details

#to_hashObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/allscripts_unity_client/unity_response.rb', line 15

def to_hash
  result = @response[:magic_response][:magic_result][:diffgram]
  result = strip_attributes(result)
  result = convert_dates_to_utc(result)

  if result.nil?
    return []
  end

  # All magic responses wrap their result in an ActionResponse element
  result = result.values.first

  # Often the first element in ActionResponse is an element
  # called ActionInfo, but in some cases it has a different name
  # so we just get the first element.
  result.values.first
end