Class: Pubnub::Client
- Includes:
- Configuration
- Defined in:
- lib/pubnub/client.rb
Constant Summary collapse
- DEFAULT_CONNECT_CALLBACK =
lambda { |msg| $log.info "CONNECTED: #{msg}" }
- DEFAULT_ERROR_CALLBACK =
lambda { |msg| $log.error "AN ERROR OCCURRED: #{msg}" }
Constants included from Configuration
Pubnub::Configuration::DEFAULT_AUTO_RECONNECT, Pubnub::Configuration::DEFAULT_CALLBACK, Pubnub::Configuration::DEFAULT_CHANNEL, Pubnub::Configuration::DEFAULT_CONTENT_TYPE, Pubnub::Configuration::DEFAULT_ENCODING, Pubnub::Configuration::DEFAULT_HEADERS, Pubnub::Configuration::DEFAULT_METHOD, Pubnub::Configuration::DEFAULT_ORIGIN, Pubnub::Configuration::DEFAULT_PARAMS, Pubnub::Configuration::DEFAULT_PATH, Pubnub::Configuration::DEFAULT_PORT, Pubnub::Configuration::DEFAULT_PUBLISH_KEY, Pubnub::Configuration::DEFAULT_SECRET_KEY, Pubnub::Configuration::DEFAULT_SSL_SET, Pubnub::Configuration::DEFAULT_SUBSCRIBE_KEY, Pubnub::Configuration::DEFAULT_TIMEOUT, Pubnub::Configuration::DEFAULT_TIMETOKEN, Pubnub::Configuration::DEFAULT_USER_AGENT, Pubnub::Configuration::MAX_RETRIES, Pubnub::Configuration::PERIODIC_TIMER
Instance Attribute Summary collapse
-
#callback ⇒ Object
Returns the value of attribute callback.
-
#channel ⇒ Object
Returns the value of attribute channel.
-
#cipher_key ⇒ Object
Returns the value of attribute cipher_key.
-
#close_connection ⇒ Object
Returns the value of attribute close_connection.
-
#error ⇒ Object
Returns the value of attribute error.
-
#history_count ⇒ Object
Returns the value of attribute history_count.
-
#history_end ⇒ Object
Returns the value of attribute history_end.
-
#history_limit ⇒ Object
Returns the value of attribute history_limit.
-
#history_reverse ⇒ Object
Returns the value of attribute history_reverse.
-
#history_start ⇒ Object
Returns the value of attribute history_start.
-
#host ⇒ Object
Returns the value of attribute host.
-
#jsonp ⇒ Object
Returns the value of attribute jsonp.
-
#last_timetoken ⇒ Object
Returns the value of attribute last_timetoken.
-
#message ⇒ Object
Returns the value of attribute message.
-
#operation ⇒ Object
Returns the value of attribute operation.
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#port ⇒ Object
Returns the value of attribute port.
-
#publish_key ⇒ Object
Returns the value of attribute publish_key.
-
#query ⇒ Object
Returns the value of attribute query.
-
#response ⇒ Object
Returns the value of attribute response.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
-
#session_uuid ⇒ Object
Returns the value of attribute session_uuid.
-
#ssl ⇒ Object
Returns the value of attribute ssl.
-
#subscribe_key ⇒ Object
Returns the value of attribute subscribe_key.
-
#timetoken ⇒ Object
Returns the value of attribute timetoken.
-
#url ⇒ Object
Returns the value of attribute url.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
Instance Method Summary collapse
- #active_subscriptions ⇒ Object
- #here_now(options = {}, &block) ⇒ Object
- #history(options = {}, &block) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #leave(options = {}, &block) ⇒ Object (also: #unsubscribe)
- #presence(options = {}, &block) ⇒ Object
- #publish(options = {}, &block) ⇒ Object
- #subscribe(options = {}, &block) ⇒ Object
- #subscription_running? ⇒ Boolean
- #time(options = {}, &block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/pubnub/client.rb', line 38 def initialize( = {}) $log = [:logger] $log = Logger.new('pubnub.log', 0, 100 * 1024 * 1024) unless $log @subscriptions = Array.new @subscription_request = nil @retry = true @retry_count = 0 @callback = [:callback] @error_callback = [:error_callback] @error_callback = DEFAULT_ERROR_CALLBACK unless @error_callback @connect_callback = [:connect_callback] @connect_callback = DEFAULT_CONNECT_CALLBACK unless @connect_callback @cipher_key = [:cipher_key] @publish_key = [:publish_key] || DEFAULT_PUBLISH_KEY @subscribe_key = [:subscribe_key] || DEFAULT_SUBSCRIBE_KEY @channel = [:channel] || DEFAULT_CHANNEL @message = [:message] @ssl = [:ssl] @secret_key = [:secret_key] @timetoken = [:timetoken] @session_uuid = [:uuid] || [:session_uuid] || UUID.new.generate @history_count = [:count] @history_start = [:start] @history_end = [:end] @history_reverse = [:reverse] @port = [:port] @url = [:url] @origin = [:origin] @origin = DEFAULT_ORIGIN unless @origin @query = [:query] @http_sync = [:http_sync] @max_retries = [:max_retries] @max_retries = MAX_RETRIES unless @max_retries @non_subscribe_timeout = [:non_subscribe_timeout] @non_subscribe_timeout = 5 unless @non_subscribe_timeout @reconnect_max_attempts = [:reconnect_max_attempts] @reconnect_max_attempts = 60 unless @reconnect_max_attempts @reconnect_retry_interval = [:reconnect_retry_interval] @reconnect_retry_interval = 5 unless @reconnect_retry_interval @reconnect_response_timeout = [:reconnect_response_timeout] @reconnect_response_timeout = 5 unless @reconnect_response_timeout @sync_connection_sub = Pubnub::PubNubHTTParty.new @sync_connection = Pubnub::PubNubHTTParty.new @pause_subscribe = false end |
Instance Attribute Details
#callback ⇒ Object
Returns the value of attribute callback.
31 32 33 |
# File 'lib/pubnub/client.rb', line 31 def callback @callback end |
#channel ⇒ Object
Returns the value of attribute channel.
31 32 33 |
# File 'lib/pubnub/client.rb', line 31 def channel @channel end |
#cipher_key ⇒ Object
Returns the value of attribute cipher_key.
31 32 33 |
# File 'lib/pubnub/client.rb', line 31 def cipher_key @cipher_key end |
#close_connection ⇒ Object
Returns the value of attribute close_connection.
32 33 34 |
# File 'lib/pubnub/client.rb', line 32 def close_connection @close_connection end |
#error ⇒ Object
Returns the value of attribute error.
32 33 34 |
# File 'lib/pubnub/client.rb', line 32 def error @error end |
#history_count ⇒ Object
Returns the value of attribute history_count.
32 33 34 |
# File 'lib/pubnub/client.rb', line 32 def history_count @history_count end |
#history_end ⇒ Object
Returns the value of attribute history_end.
32 33 34 |
# File 'lib/pubnub/client.rb', line 32 def history_end @history_end end |
#history_limit ⇒ Object
Returns the value of attribute history_limit.
32 33 34 |
# File 'lib/pubnub/client.rb', line 32 def history_limit @history_limit end |
#history_reverse ⇒ Object
Returns the value of attribute history_reverse.
32 33 34 |
# File 'lib/pubnub/client.rb', line 32 def history_reverse @history_reverse end |
#history_start ⇒ Object
Returns the value of attribute history_start.
32 33 34 |
# File 'lib/pubnub/client.rb', line 32 def history_start @history_start end |
#host ⇒ Object
Returns the value of attribute host.
31 32 33 |
# File 'lib/pubnub/client.rb', line 31 def host @host end |
#jsonp ⇒ Object
Returns the value of attribute jsonp.
31 32 33 |
# File 'lib/pubnub/client.rb', line 31 def jsonp @jsonp end |
#last_timetoken ⇒ Object
Returns the value of attribute last_timetoken.
32 33 34 |
# File 'lib/pubnub/client.rb', line 32 def last_timetoken @last_timetoken end |
#message ⇒ Object
Returns the value of attribute message.
31 32 33 |
# File 'lib/pubnub/client.rb', line 31 def @message end |
#operation ⇒ Object
Returns the value of attribute operation.
31 32 33 |
# File 'lib/pubnub/client.rb', line 31 def operation @operation end |
#origin ⇒ Object
Returns the value of attribute origin.
32 33 34 |
# File 'lib/pubnub/client.rb', line 32 def origin @origin end |
#port ⇒ Object
Returns the value of attribute port.
31 32 33 |
# File 'lib/pubnub/client.rb', line 31 def port @port end |
#publish_key ⇒ Object
Returns the value of attribute publish_key.
31 32 33 |
# File 'lib/pubnub/client.rb', line 31 def publish_key @publish_key end |
#query ⇒ Object
Returns the value of attribute query.
31 32 33 |
# File 'lib/pubnub/client.rb', line 31 def query @query end |
#response ⇒ Object
Returns the value of attribute response.
31 32 33 |
# File 'lib/pubnub/client.rb', line 31 def response @response end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
31 32 33 |
# File 'lib/pubnub/client.rb', line 31 def secret_key @secret_key end |
#session_uuid ⇒ Object
Returns the value of attribute session_uuid.
32 33 34 |
# File 'lib/pubnub/client.rb', line 32 def session_uuid @session_uuid end |
#ssl ⇒ Object
Returns the value of attribute ssl.
31 32 33 |
# File 'lib/pubnub/client.rb', line 31 def ssl @ssl end |
#subscribe_key ⇒ Object
Returns the value of attribute subscribe_key.
31 32 33 |
# File 'lib/pubnub/client.rb', line 31 def subscribe_key @subscribe_key end |
#timetoken ⇒ Object
Returns the value of attribute timetoken.
31 32 33 |
# File 'lib/pubnub/client.rb', line 31 def timetoken @timetoken end |
#url ⇒ Object
Returns the value of attribute url.
31 32 33 |
# File 'lib/pubnub/client.rb', line 31 def url @url end |
Instance Method Details
#active_subscriptions ⇒ Object
167 168 169 |
# File 'lib/pubnub/client.rb', line 167 def active_subscriptions @subscription_request end |
#here_now(options = {}, &block) ⇒ Object
149 150 151 152 153 154 |
# File 'lib/pubnub/client.rb', line 149 def here_now( = {}, &block) [:callback] = block if block_given? = (, 'here_now') verify_operation('here_now', ) start_request end |
#history(options = {}, &block) ⇒ Object
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/pubnub/client.rb', line 120 def history( = {}, &block) [:callback] = block if block_given? = (, 'history') verify_operation('history', ) [:params].merge!({:count => [:count]}) [:params].merge!({:start => [:start]}) unless [:start].nil? [:params].merge!({:end => [:end]}) unless [:end].nil? [:params].merge!({:reverse => 'true'}) if [:reverse] start_request end |
#leave(options = {}, &block) ⇒ Object Also known as: unsubscribe
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/pubnub/client.rb', line 131 def leave( = {}, &block) [:callback] = block if block_given? = (, 'leave') verify_operation('leave', ) return false unless get_channels_for_subscription.include? [:channel] remove_from_subscription [:channel] if @subscriptions.empty? @timetoken = 0 @subscription_request.timetoken = 0 @subscribe_connection.close @wait_for_response = false end start_request end |
#presence(options = {}, &block) ⇒ Object
113 114 115 116 117 118 |
# File 'lib/pubnub/client.rb', line 113 def presence( = {}, &block) [:callback] = block if block_given? = (, 'presence') verify_operation('presence', ) start_request end |
#publish(options = {}, &block) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/pubnub/client.rb', line 96 def publish( = {}, &block) [:callback] = block if block_given? = (, 'publish') verify_operation('publish', ) start_request end |
#subscribe(options = {}, &block) ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'lib/pubnub/client.rb', line 104 def subscribe( = {}, &block) [:callback] = block if block_given? = (, 'subscribe') verify_operation('subscribe', ) @error_callback.call 'YOU ARE ALREADY SUBSCRIBED TO THAT CHANNEL' if get_channels_for_subscription.include? [:channel] $log.error 'YOU ARE ALREADY SUBSCRIBED TO THAT CHANNEL' if get_channels_for_subscription.include? [:channel] start_request end |
#subscription_running? ⇒ Boolean
163 164 165 |
# File 'lib/pubnub/client.rb', line 163 def subscription_running? @subscription_running end |
#time(options = {}, &block) ⇒ Object
156 157 158 159 160 161 |
# File 'lib/pubnub/client.rb', line 156 def time( = {}, &block) [:callback] = block if block_given? = (, 'time') verify_operation('time', ) start_request end |