Class: PDC::Http::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/pdc/http/result.rb

Overview

encapsulates http response

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Result

Returns a new instance of Result.



6
7
8
9
10
# File 'lib/pdc/http/result.rb', line 6

def initialize(response)
  @body = HashWithIndifferentAccess.new(response.body)
  @status = response.status
  @url = response.env.url
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



4
5
6
# File 'lib/pdc/http/result.rb', line 4

def body
  @body
end

#statusObject (readonly)

Returns the value of attribute status.



4
5
6
# File 'lib/pdc/http/result.rb', line 4

def status
  @status
end

#urlObject (readonly)

Returns the value of attribute url.



4
5
6
# File 'lib/pdc/http/result.rb', line 4

def url
  @url
end

Instance Method Details

#dataObject



12
13
14
# File 'lib/pdc/http/result.rb', line 12

def data
  body[:data]
end

#errorsObject



24
25
26
# File 'lib/pdc/http/result.rb', line 24

def errors
  body[:errors] || []
end

#metadataObject



16
17
18
# File 'lib/pdc/http/result.rb', line 16

def 
  body[:metadata] || {}
end

#paginationObject



20
21
22
# File 'lib/pdc/http/result.rb', line 20

def pagination
  [PDC::Resource::PAGINATION] || {}
end