Class: FlowChat::BackgroundRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_chat/async_job.rb

Overview

Request object for background jobs Reconstructed from serialized webhook request data

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_data) ⇒ BackgroundRequest

Returns a new instance of BackgroundRequest.



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/flow_chat/async_job.rb', line 109

def initialize(request_data)
  @params = (request_data[:params] || {}).with_indifferent_access
  @method = request_data[:method] || "POST"
  @headers = OpenStruct.new(request_data[:headers] || {})
  @host = request_data[:host]
  @path = request_data[:path]
  @body_content = request_data[:body]
  @remote_ip = request_data[:remote_ip]

  FlowChat.logger.debug { "BackgroundRequest: Initialized with method=#{@method}, params keys=#{@params.keys.inspect}" }
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



107
108
109
# File 'lib/flow_chat/async_job.rb', line 107

def headers
  @headers
end

#hostObject (readonly)

Returns the value of attribute host.



107
108
109
# File 'lib/flow_chat/async_job.rb', line 107

def host
  @host
end

#methodObject (readonly)

Returns the value of attribute method.



107
108
109
# File 'lib/flow_chat/async_job.rb', line 107

def method
  @method
end

#paramsObject (readonly)

Returns the value of attribute params.



107
108
109
# File 'lib/flow_chat/async_job.rb', line 107

def params
  @params
end

#pathObject (readonly)

Returns the value of attribute path.



107
108
109
# File 'lib/flow_chat/async_job.rb', line 107

def path
  @path
end

#remote_ipObject (readonly)

Returns the value of attribute remote_ip.



107
108
109
# File 'lib/flow_chat/async_job.rb', line 107

def remote_ip
  @remote_ip
end

Instance Method Details

#bodyObject



147
148
149
150
# File 'lib/flow_chat/async_job.rb', line 147

def body
  # Return StringIO-like object if body content exists
  @body_content ? BackgroundRequestBody.new(@body_content) : nil
end

#cookiesObject



152
153
154
155
# File 'lib/flow_chat/async_job.rb', line 152

def cookies
  # Background jobs don't have cookies
  {}
end

#get?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/flow_chat/async_job.rb', line 139

def get?
  method.upcase == "GET"
end

#head?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/flow_chat/async_job.rb', line 143

def head?
  method.upcase == "HEAD"
end

#post?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/flow_chat/async_job.rb', line 135

def post?
  method.upcase == "POST"
end

#request_methodObject

Rails request interface compatibility



122
123
124
# File 'lib/flow_chat/async_job.rb', line 122

def request_method
  method.upcase
end

#ssl?Boolean

Returns:

  • (Boolean)


130
131
132
133
# File 'lib/flow_chat/async_job.rb', line 130

def ssl?
  # Background jobs don't have SSL context
  false
end

#user_agentObject



126
127
128
# File 'lib/flow_chat/async_job.rb', line 126

def user_agent
  @headers["User-Agent"]
end