Class: Ably::Rest::Presence

Inherits:
Object
  • Object
show all
Includes:
Modules::Conversions
Defined in:
lib/ably/rest/presence.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, channel) ⇒ Presence

Initialize a new Presence object

Parameters:


19
20
21
22
# File 'lib/ably/rest/presence.rb', line 19

def initialize(client, channel)
  @client  = client
  @channel = channel
end

Instance Attribute Details

#channelAbly::Rest::Channel (readonly)

Channel this Presence object is associated with

Returns:


13
14
15
# File 'lib/ably/rest/presence.rb', line 13

def channel
  @channel
end

#clientAbly::Rest::Client (readonly)

Client for this Presence object

Returns:


9
10
11
# File 'lib/ably/rest/presence.rb', line 9

def client
  @client
end

Instance Method Details

#get(options = {}) ⇒ Ably::Models::PaginatedResult<Ably::Models::PresenceMessage>

Obtain the set of members currently present for a channel

Parameters:

  • options (Hash) (defaults to: {})

    the options for the set of members present

Options Hash (options):

  • :limit (Integer)

    Maximum number of members to retrieve up to 1,000, defaults to 100

  • :client_id (String)

    optional client_id filter for the member

  • :connection_id (String)

    optional connection_id filter for the member

Returns:


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ably/rest/presence.rb', line 33

def get(options = {})
  options = options = {
    :limit     => 100
  }.merge(options)

  paginated_options = {
    coerce_into: 'Ably::Models::PresenceMessage',
    async_blocking_operations: options.delete(:async_blocking_operations),
  }

  response = client.get(base_path, options)

  Ably::Models::PaginatedResult.new(response, base_path, client, paginated_options) do |presence_message|
    presence_message.tap do |message|
      decode_message message
    end
  end
end

#history(options = {}) ⇒ Ably::Models::PaginatedResult<Ably::Models::PresenceMessage>

Return the presence messages history for the channel

Parameters:

  • options (Hash) (defaults to: {})

    the options for the message history request

Options Hash (options):

  • :start (Integer, Time)

    Ensure earliest time or millisecond since epoch for any presence messages retrieved is :start

  • :end (Integer, Time)

    Ensure latest time or millisecond since epoch for any presence messages retrieved is :end

  • :direction (Symbol)

    :forwards or :backwards, defaults to :backwards

  • :limit (Integer)

    Maximum number of messages to retrieve up to 1,000, defaults to 100

Returns:

Raises:

  • (ArgumentError)

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/ably/rest/presence.rb', line 62

def history(options = {})
  url = "#{base_path}/history"
  options = options = {
    :direction => :backwards,
    :limit     => 100
  }.merge(options)

  [:start, :end].each { |option| options[option] = as_since_epoch(options[option]) if options.has_key?(option) }
  raise ArgumentError, ":end must be equal to or after :start" if options[:start] && options[:end] && (options[:start] > options[:end])

  paginated_options = {
    coerce_into: 'Ably::Models::PresenceMessage',
    async_blocking_operations: options.delete(:async_blocking_operations),
  }

  response = client.get(url, options)

  Ably::Models::PaginatedResult.new(response, url, client, paginated_options) do |presence_message|
    presence_message.tap do |message|
      decode_message message
    end
  end
end