Class: ZammadAPI::ListBase

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/zammad_api/list_base.rb

Direct Known Subclasses

ListAll, ListSearch

Instance Method Summary collapse

Constructor Details

#initialize(resource, transport, parameter = {}) ⇒ ListBase

Returns a new instance of ListBase.



5
6
7
8
9
10
11
12
13
14
# File 'lib/zammad_api/list_base.rb', line 5

def initialize(resource, transport, parameter = {})
  @resource  = resource
  @url       = @resource.get_url
  @transport = transport
  @parameter = {
    page:     1,
    per_page: 10,
    expand:   'true',
  }.merge(parameter)
end

Instance Method Details

#[](position) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/zammad_api/list_base.rb', line 16

def [](position)

  local_parameter = @parameter.merge(
    page:     position + 1,
    per_page: 1
  )
  perform_request(local_parameter)[0]
end

#each(&block) ⇒ Object



42
43
44
# File 'lib/zammad_api/list_base.rb', line 42

def each(&block)
  fetch_and_yield_each(&block)
end

#page(page, per_page, &block) ⇒ Object



25
26
27
28
29
30
# File 'lib/zammad_api/list_base.rb', line 25

def page(page, per_page, &block)

  @parameter[:page]     = page
  @parameter[:per_page] = per_page
  fetch_and_yield_each(&block)
end

#page_next(&block) ⇒ Object



32
33
34
35
# File 'lib/zammad_api/list_base.rb', line 32

def page_next(&block)
  @parameter[:page] += 1
  fetch_and_yield_each(&block)
end

#page_prev(&block) ⇒ Object



37
38
39
40
# File 'lib/zammad_api/list_base.rb', line 37

def page_prev(&block)
  @parameter[:page] -= 1
  fetch_and_yield_each(&block)
end