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)


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)


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)


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


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)


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