Class: Ritsudo::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/ritsudo/request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_id, messages) ⇒ Request

Returns a new instance of Request.



16
17
18
19
# File 'lib/ritsudo/request.rb', line 16

def initialize(request_id, messages)
  @request_id = request_id
  @messages = messages
end

Instance Attribute Details

#messagesObject (readonly)

Returns the value of attribute messages.



3
4
5
# File 'lib/ritsudo/request.rb', line 3

def messages
  @messages
end

#request_idObject (readonly)

Returns the value of attribute request_id.



4
5
6
# File 'lib/ritsudo/request.rb', line 4

def request_id
  @request_id
end

Class Method Details

.grouping(raw_messages) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/ritsudo/request.rb', line 6

def self.grouping(raw_messages)
  messages = Ritsudo::Message.wrap(raw_messages)
  requests = messages.group_by { |message|
    message.param('requestId')
  }.map { |request_id, messages|
    Ritsudo::Request.new(request_id, messages)
  }
  requests
end

Instance Method Details

#processing?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/ritsudo/request.rb', line 35

def processing?
  sent_message && !finished_message
end

#timeObject



21
22
23
24
# File 'lib/ritsudo/request.rb', line 21

def time
  return nil unless received_message && sent_message
  ((received_message.timestamp - sent_message.timestamp) * 1000) # msec
end

#typeObject



54
55
56
# File 'lib/ritsudo/request.rb', line 54

def type
  sent_message&.param("type") || 'etc'
end

#urlObject



26
27
28
29
30
31
32
33
# File 'lib/ritsudo/request.rb', line 26

def url
  if _url = sent_message&.url
    url = URI.parse(_url)
    url.to_s.sub(url.query.to_s, '')
  else
    nil
  end
end