Class: Taleo::Cursor

Inherits:
Object
  • Object
show all
Defined in:
lib/taleo/cursor.rb

Overview

Pages through results of a search query

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pagination, results, resource, klass, client) ⇒ Cursor

Returns a new instance of Cursor.



8
9
10
11
12
13
14
# File 'lib/taleo/cursor.rb', line 8

def initialize(pagination, results, resource, klass, client)
  @pagination = pagination
  @results = results
  @resource = resource
  @klass = klass
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/taleo/cursor.rb', line 6

def client
  @client
end

#klassObject (readonly)

Returns the value of attribute klass.



6
7
8
# File 'lib/taleo/cursor.rb', line 6

def klass
  @klass
end

#paginationObject (readonly)

Returns the value of attribute pagination.



6
7
8
# File 'lib/taleo/cursor.rb', line 6

def pagination
  @pagination
end

#resourceObject (readonly)

Returns the value of attribute resource.



6
7
8
# File 'lib/taleo/cursor.rb', line 6

def resource
  @resource
end

#resultsObject (readonly)

Returns the value of attribute results.



6
7
8
# File 'lib/taleo/cursor.rb', line 6

def results
  @results
end

Instance Method Details

#has_next?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/taleo/cursor.rb', line 22

def has_next?
  pagination.key?('next')
end

#has_previous?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/taleo/cursor.rb', line 26

def has_previous?
  pagination.key?('previous')
end

#has_self?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/taleo/cursor.rb', line 30

def has_self?
  pagination.key?('self')
end

#itemsObject



16
17
18
19
20
# File 'lib/taleo/cursor.rb', line 16

def items
  results.map do |i|
    klass.new(i.fetch(resource), client)
  end
end

#next_pageObject

Raises:



42
43
44
45
46
47
48
49
50
# File 'lib/taleo/cursor.rb', line 42

def next_page
  raise Taleo::Error.new('No further results') unless has_next?

  res = client.connection.get do |req|
    req.url pagination.fetch('next')
  end

  new_cursor(res)
end

#previous_pageObject

Raises:



52
53
54
55
56
57
58
59
60
# File 'lib/taleo/cursor.rb', line 52

def previous_page
  raise Taleo::Error.new('No prior results') unless has_previous?

  res = client.connection.get do |req|
    req.url pagination.fetch('previous')
  end

  new_cursor(res)
end

#self_pageObject



34
35
36
37
38
39
40
# File 'lib/taleo/cursor.rb', line 34

def self_page
  res = client.connection.get do |req|
    req.url pagination.fetch('self')
  end

  new_cursor(res)
end