Sha256: 3a41d172fe456b48eb9e9610d1ac8f5c98258f2e1b4c3a7f15da33ae9941c824
Contents?: true
Size: 1.14 KB
Versions: 10
Compression:
Stored size: 1.14 KB
Contents
module Pubnub module Formatter # Formats channels as array of channels as strings def format_channels(channels, should_encode = true) channel_array = case channels.class.to_s when 'String' channels.split(',') when 'Array' channels.map { |channel| channel.to_s } else [channels.to_s] end channel_array = channel_array.map { |channel| encode_channel(channel) } if should_encode channel_array end def encode_channel(channel) URI.encode_www_form_component(channel).gsub('+', '%20') end def format_message(message) if @cipher_key pc = Pubnub::Crypto.new(@cipher_key) begin message = pc.encrypt(message) URI.escape(message.to_json) rescue => error @error_callback.call 'bug' end else URI.encode_www_form_component(message.to_json).gsub('+', '%20') end end def params_hash_to_url_params(hash) params = String.new hash.each do |key, value| params << "#{key}=#{value}&" end params.chop! if params[-1] == '&' params end end end
Version data entries
10 entries across 10 versions & 1 rubygems