Module: Pubnub::Client::PagedHistory

Included in:
Pubnub::Client
Defined in:
lib/pubnub/client/paged_history.rb

Overview

Module that holds paged_history event logic

Instance Method Summary collapse

Instance Method Details

#all_history_messages(options = {}, &block) ⇒ Object

Fetch messages as long as one of criteria won't be met. Messages returned as single envelope.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pubnub/client/paged_history.rb', line 11

def all_history_messages(options = {}, &block)
  channel = options.fetch(:channel)
  # Time frame between which messages should be fetched.
  start_tt = options.fetch(:start, nil)
  end_tt = options.fetch(:end, nil)
  page_size = options.fetch(:page_size, 100)          # How many messages per-request should be fetched.
  reverse = options.fetch(:reverse, false)            # Order in which messages should be retrieved if :end not set.
  include_token = options.fetch(:include_token, true) # Whether timetoken should be included with message or not.
  maximum = options.fetch(:max, 500)                  # Maximum number of messages which should be fetched.
  callback = options.fetch(:callback, block)

  reverse = false unless end_tt.nil? # Disable revers if closed time interval specified.
  maximum = nil unless end_tt.nil? # Disable maximum messages count if closed time interval specified.

  if options[:http_sync]
    sync_all_history_messages(channel, include_token, page_size, reverse, maximum, callback, start: start_tt, end: end_tt)
  else
    async_all_history_messages(options)
  end
end

#paged_history(options = {}, &block) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pubnub/client/paged_history.rb', line 32

def paged_history(options = {}, &block)
  channel = options.fetch(:channel)
  page = options.fetch(:page, 1)                      # How many mages should be fetched with specified limit.
  limit = options.fetch(:limit, 100)                  # How many messages per page should be fetched.
  include_token = options.fetch(:include_token, false) # Whether timetoken should be included with message or not.
  callback = options.fetch(:callback, block)
  # Time frame between which messages should be fetched.
  start_tt = options.fetch(:start, nil)
  end_tt = options.fetch(:end, nil)

  if options[:http_sync]
    sync_paged_history(channel, page, limit, include_token, callback, start: start_tt, end: end_tt)
  else
    async_paged_history(options)
  end
end