Class: EventbriteSDK::ResourceList

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/eventbrite_sdk/resource_list.rb

Direct Known Subclasses

Lists::OwnedEventOrdersList

Instance Method Summary collapse

Constructor Details

#initialize(url_base: nil, object_class: nil, key: nil, query: {}, request: EventbriteSDK) ⇒ ResourceList

Returns a new instance of ResourceList.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/eventbrite_sdk/resource_list.rb', line 8

def initialize(
  url_base: nil,
  object_class: nil,
  key: nil,
  query: {},
  request: EventbriteSDK
)
  @key = key
  @object_class = object_class
  @objects = []
  @query = query
  @request = request
  @url_base = url_base
end

Instance Method Details

#concat(other) ⇒ Object



23
24
25
# File 'lib/eventbrite_sdk/resource_list.rb', line 23

def concat(other)
  other.concat(to_ary)
end

#continue(continuation_token: nil, api_token: nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/eventbrite_sdk/resource_list.rb', line 27

def continue(continuation_token: nil, api_token: nil)
  continuation_token ||= continuation

  return unless continuation_token || has_more_items

  retrieve(
    api_token: api_token,
    query: {continuation: continuation_token}
  )
end

#next_page(api_token: nil) ⇒ Object



52
53
54
55
56
# File 'lib/eventbrite_sdk/resource_list.rb', line 52

def next_page(api_token: nil)
  return if page_number >= (page_count || 1)

  page(page_number + 1, api_token: api_token)
end

#page(num, api_token: nil) ⇒ Object



45
46
47
48
49
50
# File 'lib/eventbrite_sdk/resource_list.rb', line 45

def page(num, api_token: nil)
  retrieve(
    api_token: api_token,
    query: { page: num },
  )
end

#prev_page(api_token: nil) ⇒ Object



58
59
60
61
62
# File 'lib/eventbrite_sdk/resource_list.rb', line 58

def prev_page(api_token: nil)
  return if page_number <= 1

  page(page_number - 1, api_token: api_token)
end

#retrieve(query: {}, api_token: nil) ⇒ Object



38
39
40
41
42
43
# File 'lib/eventbrite_sdk/resource_list.rb', line 38

def retrieve(query: {}, api_token: nil)
  @query.merge!(query)
  load_response(api_token)

  self
end

#to_aryObject



75
76
77
# File 'lib/eventbrite_sdk/resource_list.rb', line 75

def to_ary
  objects
end

#to_json(opts = {}) ⇒ Object



79
80
81
# File 'lib/eventbrite_sdk/resource_list.rb', line 79

def to_json(opts = {})
  { key => objects.map(&:to_h), 'pagination' => @pagination }.to_json(opts)
end

#with_expansion(*args) ⇒ Object



83
84
85
86
87
88
89
90
91
# File 'lib/eventbrite_sdk/resource_list.rb', line 83

def with_expansion(*args)
  if args.first
    @query[:expand] = args.join(',')
  else
    @query.delete(:expand)
  end

  self
end