Class: CollectionSpace::Response
- Inherits:
-
Object
- Object
- CollectionSpace::Response
- Defined in:
- lib/collectionspace/client/response.rb
Overview
CollectionSpace response
Instance Attribute Summary collapse
-
#parsed ⇒ Object
readonly
Returns the value of attribute parsed.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
-
#xml ⇒ Object
readonly
Returns the value of attribute xml.
Instance Method Summary collapse
- #find(list_type, item_type, property, value) ⇒ Object
-
#initialize(result) ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize(result) ⇒ Response
Returns a new instance of Response.
8 9 10 11 12 13 14 |
# File 'lib/collectionspace/client/response.rb', line 8 def initialize(result) @result = result @parsed = result.parsed_response @status_code = result.code.to_i body = result.body @xml = (@result.success? && body =~ /<?xml/) ? Nokogiri::XML(body) : nil end |
Instance Attribute Details
#parsed ⇒ Object (readonly)
Returns the value of attribute parsed.
6 7 8 |
# File 'lib/collectionspace/client/response.rb', line 6 def parsed @parsed end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
6 7 8 |
# File 'lib/collectionspace/client/response.rb', line 6 def result @result end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
6 7 8 |
# File 'lib/collectionspace/client/response.rb', line 6 def status_code @status_code end |
#xml ⇒ Object (readonly)
Returns the value of attribute xml.
6 7 8 |
# File 'lib/collectionspace/client/response.rb', line 6 def xml @xml end |
Instance Method Details
#find(list_type, item_type, property, value) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/collectionspace/client/response.rb', line 16 def find(list_type, item_type, property, value) total = parsed[list_type]["totalItems"].to_i return unless total.positive? list = parsed[list_type][item_type] list = [list] if total == 1 # wrap if single item list.find { |i| i[property] == value } end |