Class: HalOpenscience::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, resource_class) ⇒ Response

Returns a new instance of Response.



5
6
7
8
9
10
# File 'lib/hal_openscience/response.rb', line 5

def initialize(body, resource_class)
  @body = body
  @data = JSON.parse(@body)['response']
  @results = @data['docs'].map { |result| resource_class.new(result) }
  @total_count = @data.fetch('numFound', @results.size)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

#responseObject (readonly)

Returns the value of attribute response.



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

def response
  @response
end

#resultsObject (readonly)

Returns the value of attribute results.



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

def results
  @results
end

#total_countObject (readonly)

Returns the value of attribute total_count.



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

def total_count
  @total_count
end