Class: Satori::RTM::SubscriptionContext

Inherits:
Object
  • Object
show all
Defined in:
lib/satori-rtm-sdk/model.rb

Overview

Context with initial subscription settings and current subscription state.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sid, opts, fn) ⇒ SubscriptionContext

Returns a new instance of SubscriptionContext

Raises:

  • (ArgumentError)

147
148
149
150
151
152
153
154
155
# File 'lib/satori-rtm-sdk/model.rb', line 147

def initialize(sid, opts, fn)
  raise ArgumentError, 'subscription callback function should be specified' if fn.nil?

  @subscription_id = sid
  @fn = fn
  @req_opts = opts
  @position = nil
  @state = :init
end

Instance Attribute Details

#fnProc (readonly)

Returns RTM subscription yield block used to create the subscription

Returns:

  • (Proc)

    RTM subscription yield block used to create the subscription


144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/satori-rtm-sdk/model.rb', line 144

class SubscriptionContext
  attr_reader :subscription_id, :req_opts, :fn, :position, :state

  def initialize(sid, opts, fn)
    raise ArgumentError, 'subscription callback function should be specified' if fn.nil?

    @subscription_id = sid
    @fn = fn
    @req_opts = opts
    @position = nil
    @state = :init
  end

  # @!visibility private
  def handle_data(status, data)
    data[:subscription_id] = @subscription_id if status == :disconnect
    reply = SubscriptionEvent.new(status, data)
    handle_reply(reply)
    reply
  end

  # @!visibility private
  def handle_reply(reply)
    @position = reply.data[:position] if reply.data.key?(:position)
    case reply.type
    when :subscribed, :unsubscribed, :error, :disconnect
      @state = reply.type
    end
  end

  # @!visibility private
  def mark_as_resubscribed
    @state = :resubscribed
  end
end

#positionString (readonly)

Returns current subscription position. Updated automatically after each RTM reply

Returns:

  • (String)

    current subscription position. Updated automatically after each RTM reply


144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/satori-rtm-sdk/model.rb', line 144

class SubscriptionContext
  attr_reader :subscription_id, :req_opts, :fn, :position, :state

  def initialize(sid, opts, fn)
    raise ArgumentError, 'subscription callback function should be specified' if fn.nil?

    @subscription_id = sid
    @fn = fn
    @req_opts = opts
    @position = nil
    @state = :init
  end

  # @!visibility private
  def handle_data(status, data)
    data[:subscription_id] = @subscription_id if status == :disconnect
    reply = SubscriptionEvent.new(status, data)
    handle_reply(reply)
    reply
  end

  # @!visibility private
  def handle_reply(reply)
    @position = reply.data[:position] if reply.data.key?(:position)
    case reply.type
    when :subscribed, :unsubscribed, :error, :disconnect
      @state = reply.type
    end
  end

  # @!visibility private
  def mark_as_resubscribed
    @state = :resubscribed
  end
end

#req_optsHash (readonly)

Returns additional options for rtm/subscribe request used to create the subscription

Returns:

  • (Hash)

    additional options for rtm/subscribe request used to create the subscription


144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/satori-rtm-sdk/model.rb', line 144

class SubscriptionContext
  attr_reader :subscription_id, :req_opts, :fn, :position, :state

  def initialize(sid, opts, fn)
    raise ArgumentError, 'subscription callback function should be specified' if fn.nil?

    @subscription_id = sid
    @fn = fn
    @req_opts = opts
    @position = nil
    @state = :init
  end

  # @!visibility private
  def handle_data(status, data)
    data[:subscription_id] = @subscription_id if status == :disconnect
    reply = SubscriptionEvent.new(status, data)
    handle_reply(reply)
    reply
  end

  # @!visibility private
  def handle_reply(reply)
    @position = reply.data[:position] if reply.data.key?(:position)
    case reply.type
    when :subscribed, :unsubscribed, :error, :disconnect
      @state = reply.type
    end
  end

  # @!visibility private
  def mark_as_resubscribed
    @state = :resubscribed
  end
end

#state:init, ... (readonly)

Subscription state

Returns:

  • (:init)

    not established

  • (:subscribed)

    subscribed

  • (:unsubscribed)

    unsubscribed with rtm/unsubscribe request

  • (:disconnect)

    unsubscribed because connection is lost

  • (:resubscribed)

    unsubscribed because new subscription replaces it with force flag


144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/satori-rtm-sdk/model.rb', line 144

class SubscriptionContext
  attr_reader :subscription_id, :req_opts, :fn, :position, :state

  def initialize(sid, opts, fn)
    raise ArgumentError, 'subscription callback function should be specified' if fn.nil?

    @subscription_id = sid
    @fn = fn
    @req_opts = opts
    @position = nil
    @state = :init
  end

  # @!visibility private
  def handle_data(status, data)
    data[:subscription_id] = @subscription_id if status == :disconnect
    reply = SubscriptionEvent.new(status, data)
    handle_reply(reply)
    reply
  end

  # @!visibility private
  def handle_reply(reply)
    @position = reply.data[:position] if reply.data.key?(:position)
    case reply.type
    when :subscribed, :unsubscribed, :error, :disconnect
      @state = reply.type
    end
  end

  # @!visibility private
  def mark_as_resubscribed
    @state = :resubscribed
  end
end

#subscription_idString (readonly)

Returns subscription identifier

Returns:

  • (String)

    subscription identifier


144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/satori-rtm-sdk/model.rb', line 144

class SubscriptionContext
  attr_reader :subscription_id, :req_opts, :fn, :position, :state

  def initialize(sid, opts, fn)
    raise ArgumentError, 'subscription callback function should be specified' if fn.nil?

    @subscription_id = sid
    @fn = fn
    @req_opts = opts
    @position = nil
    @state = :init
  end

  # @!visibility private
  def handle_data(status, data)
    data[:subscription_id] = @subscription_id if status == :disconnect
    reply = SubscriptionEvent.new(status, data)
    handle_reply(reply)
    reply
  end

  # @!visibility private
  def handle_reply(reply)
    @position = reply.data[:position] if reply.data.key?(:position)
    case reply.type
    when :subscribed, :unsubscribed, :error, :disconnect
      @state = reply.type
    end
  end

  # @!visibility private
  def mark_as_resubscribed
    @state = :resubscribed
  end
end