Class: RetrieveResponse

Inherits:
Response show all
Defined in:
lib/refworks/retrieve/retrieve_response.rb

Instance Attribute Summary collapse

Attributes inherited from Response

#body, #parsed_response, #process_time, #result_code, #result_msg, #result_msg_code

Instance Method Summary collapse

Constructor Details

#initialize(raw_response) ⇒ RetrieveResponse

Returns a new instance of RetrieveResponse.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/refworks/retrieve/retrieve_response.rb', line 5

def initialize(raw_response)
  super(raw_response)
  if result_code != "200"
    @total_hits = "0"
    @total_returned = "0"
    return
  end

  # If results returned, process the references and metadata

  @total_hits = self.parsed_response["refworks"]["RWResult"]["RetrieveResult"]["totalHits"]
  @total_returned = self.parsed_response["refworks"]["RWResult"]["RetrieveResult"]["totalReturned"]

  refs = self.parsed_response["refworks"]["RWResult"]["RetrieveResult"]["reference"]

  # here we parse out references into an array of actual Reference objects (even if only 1 ref returned)
  @references = Array.new

  # The RefWorks API can return an array or a single element depending on how many references were returned.
  if refs.class == Array
    refs.each do |ref|
      @references << Reference.new(ref)
    end
  else
    # here, "refs" is just a hash representing a single reference
    # in other words, only one reference was returned
    @references << Reference.new(refs)
  end
end

Instance Attribute Details

#referencesObject (readonly)

Returns the value of attribute references.



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

def references
  @references
end

#total_hitsObject (readonly)

Returns the value of attribute total_hits.



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

def total_hits
  @total_hits
end

#total_returnedObject (readonly)

Returns the value of attribute total_returned.



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

def total_returned
  @total_returned
end