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

Returns a new instance of Result.



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

def initialize(body, headers, status)
  @contents = parse(body)
  @raw_headers = headers
  @status = status
  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

#next_pageObject (readonly)

Returns the value of attribute next_page.



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

def next_page
  @next_page
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

#prev_pageObject (readonly)

Returns the value of attribute prev_page.



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

def prev_page
  @prev_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

#total_pagesObject (readonly)

Returns the value of attribute total_pages.



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

def total_pages
  @total_pages
end

Instance Method Details

#is_error?Boolean

Returns:

  • (Boolean)


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

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