Class: ConstantContact::Components::ResultSet

Inherits:
Object
  • Object
show all
Defined in:
lib/constantcontact/components/result_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(results, meta, component = nil, method = :create_summary) ⇒ ResultSet

Constructor to create a ResultSet from the results/meta response when performing a get on a collection



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/constantcontact/components/result_set.rb', line 16

def initialize(results, meta, component = nil, method = :create_summary)
  @results = results
  if component.present?
    @component = component
  end
  if method.present?
    @method = method
  end

  if meta.has_key?('pagination') and meta['pagination'].has_key?('next_link')
    @next_link = meta['pagination']['next_link']
    @next = @next_link[@next_link.index('?'), @next_link.length]
  end
end

Instance Attribute Details

#nextObject

Returns the value of attribute next.



10
11
12
# File 'lib/constantcontact/components/result_set.rb', line 10

def next
  @next
end

#resultsObject

Returns the value of attribute results.



10
11
12
# File 'lib/constantcontact/components/result_set.rb', line 10

def results
  @results
end

Instance Method Details

#next_resultsObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/constantcontact/components/result_set.rb', line 31

def next_results
  if @next_link.present? and @component.present?
    url = Util::Config.get('endpoints.api_url') + @next_link
    url = url.gsub(@next, "")
    url = Services::BaseService.build_url(url, {
      :next => @next.split("next=")[1]
    })
    response = RestClient.get(url, Services::BaseService.get_headers())
    body = JSON.parse(response.body)

    events = body['results'].collect do |event|
      @component.send(@method, event)
    end

    return Components::ResultSet.new(events, body['meta'], @component)
  else
    return nil
  end
end