Class: Satori::RTM::SubscriptionContext
- Inherits:
-
Object
- Object
- Satori::RTM::SubscriptionContext
- Defined in:
- lib/satori-rtm-sdk/model.rb
Overview
Context with initial subscription settings and current subscription state.
Instance Attribute Summary collapse
-
#fn ⇒ Proc
readonly
RTM subscription yield block used to create the subscription.
-
#position ⇒ String
readonly
Current subscription position.
-
#req_opts ⇒ Hash
readonly
Additional options for
rtm/subscribe
request used to create the subscription. -
#state ⇒ :init, ...
readonly
Subscription state.
-
#subscription_id ⇒ String
readonly
Subscription identifier.
Instance Method Summary collapse
-
#initialize(sid, opts, fn) ⇒ SubscriptionContext
constructor
A new instance of SubscriptionContext.
Constructor Details
#initialize(sid, opts, fn) ⇒ SubscriptionContext
Returns a new instance of SubscriptionContext
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
#fn ⇒ Proc (readonly)
Returns 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 |
#position ⇒ String (readonly)
Returns 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_opts ⇒ Hash (readonly)
Returns 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
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_id ⇒ String (readonly)
Returns 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 |