Class: Pubnub::Response

Inherits:
Object show all
Defined in:
lib/pubnub/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Response

Creates Pubnub::Response object based on options hash

Sets @message, @channel, @timetoken, @status_code, :response attributes To properly init new response object it need :http, :response, :channel options While you pass :index option it will treat :response as array which size is greater than one In case you want create your custom error response, you have to pass :error_init option with true value and :message with your message



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
# File 'lib/pubnub/response.rb', line 19

def initialize(options = {})
  @path  = options[:path]
  @query = options[:query]

  if options[:error_init]
    @message = options[:message]
    @response = options[:message]
    @timetoken = 0
  else
    if options[:http].respond_to?(:body) && options[:http].respond_to?(:code) && options[:http].respond_to?(:message) && options[:http].respond_to?(:headers)
      httparty = true
    else
      httparty = false
    end

    if httparty
      case options[:operation]
        when 'publish'
          set_for_httparty(options)
        when 'subscribe'
          set_for_httparty(options)
        when 'presence'
          set_for_httparty(options)
        when 'history'
          set_for_httparty(options)
        when 'leave'
          set_for_httparty(options)
        when 'here_now'
          set_for_httparty(options)
        when 'time'
          set_for_httparty(options)
      end
    else # EM.http_request
      case options[:operation]
        when 'publish'
          set_for_em_http_request(options)
        when 'subscribe'
          set_for_em_http_request(options)
        when 'presence'
          set_for_em_http_request(options)
        when 'history'
          set_for_em_http_request(options)
        when 'leave'
          set_for_em_http_request(options)
        when 'here_now'
          set_for_em_http_request(options)
        when 'time'
          set_for_em_http_request(options)
      end
    end
  end
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



2
3
4
# File 'lib/pubnub/response.rb', line 2

def channel
  @channel
end

#messageObject (readonly) Also known as: msg

Returns the value of attribute message.



2
3
4
# File 'lib/pubnub/response.rb', line 2

def message
  @message
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/pubnub/response.rb', line 3

def path
  @path
end

#queryObject (readonly)

Returns the value of attribute query.



3
4
5
# File 'lib/pubnub/response.rb', line 3

def query
  @query
end

#responseObject (readonly)

Returns the value of attribute response.



3
4
5
# File 'lib/pubnub/response.rb', line 3

def response
  @response
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



2
3
4
# File 'lib/pubnub/response.rb', line 2

def status_code
  @status_code
end

#timetokenObject (readonly)

Returns the value of attribute timetoken.



2
3
4
# File 'lib/pubnub/response.rb', line 2

def timetoken
  @timetoken
end

Instance Method Details

#==(other) ⇒ Object

Simple compare to other object basing on string representation of response (see #to_s)



74
75
76
# File 'lib/pubnub/response.rb', line 74

def ==(other)
  @response == other.to_s
end