Class: Response

Inherits:
Object
  • Object
show all
Defined in:
lib/refworks/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_response) ⇒ Response

Returns a new instance of Response.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/refworks/response.rb', line 5

def initialize(raw_response)
  # The RefWorks API emits invalid XML.  Specifically, when the session is invalid, the ResultMsg field
  # which comes back contains some illegal raw characters.  This is the only set of transformations I
  # could find which completely eliminate the junk characters.

  # Trying to work around the malformed response bug
  p raw_response.body
  # Replace non UTF-8 chars with the empty string
  raw_response.body.encode!('UTF-8', 'binary', :invalid => :replace, :undef => :replace, :replace => '')
  # Remove characters which are not allowed to appear in XML messages
  raw_response.body.gsub!(/[\u0001-\u0019]/,'')
  p raw_response.body

  @body = raw_response.body
  @parsed_response = raw_response.parsed_response
  @result_code = parsed_response["refworks"]["RWResult"]["result"]
  @process_time = parsed_response["refworks"]["RWResult"]["processTime"]
  @result_msg = parsed_response["refworks"]["RWResult"]["resultMsg"]
  @result_msg_code = parsed_response["refworks"]["RWResult"]["resultMsgCode"]
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/refworks/response.rb', line 3

def body
  @body
end

#parsed_responseObject (readonly)

Returns the value of attribute parsed_response.



3
4
5
# File 'lib/refworks/response.rb', line 3

def parsed_response
  @parsed_response
end

#process_timeObject (readonly)

Returns the value of attribute process_time.



3
4
5
# File 'lib/refworks/response.rb', line 3

def process_time
  @process_time
end

#result_codeObject (readonly)

Returns the value of attribute result_code.



3
4
5
# File 'lib/refworks/response.rb', line 3

def result_code
  @result_code
end

#result_msgObject (readonly)

Returns the value of attribute result_msg.



3
4
5
# File 'lib/refworks/response.rb', line 3

def result_msg
  @result_msg
end

#result_msg_codeObject (readonly)

Returns the value of attribute result_msg_code.



3
4
5
# File 'lib/refworks/response.rb', line 3

def result_msg_code
  @result_msg_code
end