Class: Cortex::Result

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, headers, status) ⇒ Result



6
7
8
9
10
11
12
13
# File 'lib/cortex/result.rb', line 6

def initialize(body, headers, status)
  @contents = parse(body)
  @raw_headers = headers
  @status = status
  @total_items = headers['x-total-items'] unless headers['x-total-items'].nil?
  parse_headers(headers)
  @errors = find_errors
end

Instance Attribute Details

#contentsObject (readonly)

Returns the value of attribute contents.



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

def contents
  @contents
end

#errorsObject (readonly)

Returns the value of attribute errors.



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

def errors
  @errors
end

#pageObject (readonly)

Returns the value of attribute page.



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

def page
  @page
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



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

def per_page
  @per_page
end

#rangeObject (readonly)

Returns the value of attribute range.



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

def range
  @range
end

#range_endObject (readonly)

Returns the value of attribute range_end.



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

def range_end
  @range_end
end

#range_startObject (readonly)

Returns the value of attribute range_start.



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

def range_start
  @range_start
end

#raw_headersObject (readonly)

Returns the value of attribute raw_headers.



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

def raw_headers
  @raw_headers
end

#statusObject (readonly)

Returns the value of attribute status.



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

def status
  @status
end

#total_itemsObject (readonly)

Returns the value of attribute total_items.



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

def total_items
  @total_items
end

Instance Method Details

#is_error?Boolean



15
16
17
# File 'lib/cortex/result.rb', line 15

def is_error?
  @status >= 400 || (@contents.is_a?(Hash) && @contents.has_key?('errors'))
end