Class: Easemob::BaseMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/easemob/message/base_message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response) ⇒ BaseMessage

Returns a new instance of BaseMessage.



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
# File 'lib/easemob/message/base_message.rb', line 23

def initialize(http_response)
  @raw_http_response = http_response
  @code = http_response.code
  @body = http_response.body

  return unless http_response.headers['Content-Type'].index('application/json')

  @body_hash = JSON.parse(@body)

  @timestamp = @body_hash['timestamp']
  @duration = @body_hash['duration']

  if http_response.code == 200
    @action = @body_hash['action']
    @application = @body_hash['application']
    @params = @body_hash['params']
    @uri = @body_hash['uri']
    @entities = @body_hash['entities']
    @data = @body_hash['data']
    @organization = @body_hash['organization']
    @application_name = @body_hash['applicationName']
    @cursor = @body_hash['cursor']
    @count = @body_hash['count']
  else
    @error = @body_hash['error']
    @exception = @body_hash['exception']
    @error_description = @body_hash['error_description']
  end
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



8
9
10
# File 'lib/easemob/message/base_message.rb', line 8

def action
  @action
end

#applicationObject (readonly)

Returns the value of attribute application.



9
10
11
# File 'lib/easemob/message/base_message.rb', line 9

def application
  @application
end

#application_nameObject (readonly)

Returns the value of attribute application_name.



15
16
17
# File 'lib/easemob/message/base_message.rb', line 15

def application_name
  @application_name
end

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/easemob/message/base_message.rb', line 3

def body
  @body
end

#body_hashObject (readonly)

Returns the value of attribute body_hash.



3
4
5
# File 'lib/easemob/message/base_message.rb', line 3

def body_hash
  @body_hash
end

#codeObject (readonly)

Returns the value of attribute code.



3
4
5
# File 'lib/easemob/message/base_message.rb', line 3

def code
  @code
end

#countObject (readonly)

Returns the value of attribute count.



17
18
19
# File 'lib/easemob/message/base_message.rb', line 17

def count
  @count
end

#cursorObject (readonly)

Returns the value of attribute cursor.



16
17
18
# File 'lib/easemob/message/base_message.rb', line 16

def cursor
  @cursor
end

#dataObject (readonly)

Returns the value of attribute data.



13
14
15
# File 'lib/easemob/message/base_message.rb', line 13

def data
  @data
end

#durationObject (readonly)

Returns the value of attribute duration.



6
7
8
# File 'lib/easemob/message/base_message.rb', line 6

def duration
  @duration
end

#entitiesObject (readonly)

Returns the value of attribute entities.



12
13
14
# File 'lib/easemob/message/base_message.rb', line 12

def entities
  @entities
end

#errorObject (readonly)

Returns the value of attribute error.



19
20
21
# File 'lib/easemob/message/base_message.rb', line 19

def error
  @error
end

#error_descriptionObject (readonly)

Returns the value of attribute error_description.



21
22
23
# File 'lib/easemob/message/base_message.rb', line 21

def error_description
  @error_description
end

#exceptionObject (readonly)

Returns the value of attribute exception.



20
21
22
# File 'lib/easemob/message/base_message.rb', line 20

def exception
  @exception
end

#organizationObject (readonly)

Returns the value of attribute organization.



14
15
16
# File 'lib/easemob/message/base_message.rb', line 14

def organization
  @organization
end

#paramsObject (readonly)

Returns the value of attribute params.



10
11
12
# File 'lib/easemob/message/base_message.rb', line 10

def params
  @params
end

#raw_http_responseObject (readonly)

Returns the value of attribute raw_http_response.



3
4
5
# File 'lib/easemob/message/base_message.rb', line 3

def raw_http_response
  @raw_http_response
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



5
6
7
# File 'lib/easemob/message/base_message.rb', line 5

def timestamp
  @timestamp
end

#uriObject (readonly)

Returns the value of attribute uri.



11
12
13
# File 'lib/easemob/message/base_message.rb', line 11

def uri
  @uri
end

Instance Method Details

#inspectObject



57
58
59
60
61
62
# File 'lib/easemob/message/base_message.rb', line 57

def inspect
  "#{self.class.name}(code: #{@code}, body: #{@body}, action: #{@action},
   application: #{@application}, params: #{@params}, uri: #{@uri}, entities: #{@entities},
   data: #{@data}, timestamp: #{@timestamp}, duration: #{@duration}, organization: #{@organization},
   applicationName: #{@applicationName}, cursor: #{@cursor}, count: #{@count})"
end

#to_sObject



53
54
55
# File 'lib/easemob/message/base_message.rb', line 53

def to_s
  @body.to_s
end