Class: AuthorsResponse

Inherits:
Response show all
Defined in:
lib/refworks/authors/authors_response.rb

Direct Known Subclasses

AuthorsAllResponse, AuthorsSearchResponse

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) ⇒ AuthorsResponse

Returns a new instance of AuthorsResponse.



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
# File 'lib/refworks/authors/authors_response.rb', line 5

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

  # If results returned, process the authors and metadata

  @total = self.parsed_response["refworks"]["RWResult"]["RWAuthor"]["total"]

  author_list = self.parsed_response["refworks"]["RWResult"]["RWAuthor"]["Author"]

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

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

Instance Attribute Details

#authorsObject (readonly)

Returns the value of attribute authors.



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

def authors
  @authors
end

#totalObject (readonly)

Returns the value of attribute total.



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

def total
  @total
end