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.



119
120
121
122
123
124
125
126
127
128
129
# File 'lib/flow_chat/async_job.rb', line 119

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.



117
118
119
# File 'lib/flow_chat/async_job.rb', line 117

def headers
  @headers
end

#hostObject (readonly)

Returns the value of attribute host.



117
118
119
# File 'lib/flow_chat/async_job.rb', line 117

def host
  @host
end

#methodObject (readonly)

Returns the value of attribute method.



117
118
119
# File 'lib/flow_chat/async_job.rb', line 117

def method
  @method
end

#paramsObject (readonly)

Returns the value of attribute params.



117
118
119
# File 'lib/flow_chat/async_job.rb', line 117

def params
  @params
end

#pathObject (readonly)

Returns the value of attribute path.



117
118
119
# File 'lib/flow_chat/async_job.rb', line 117

def path
  @path
end

#remote_ipObject (readonly)

Returns the value of attribute remote_ip.



117
118
119
# File 'lib/flow_chat/async_job.rb', line 117

def remote_ip
  @remote_ip
end

Instance Method Details

#bodyObject



157
158
159
160
# File 'lib/flow_chat/async_job.rb', line 157

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

#cookiesObject



162
163
164
165
# File 'lib/flow_chat/async_job.rb', line 162

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

#get?Boolean

Returns:

  • (Boolean)


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

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

#head?Boolean

Returns:

  • (Boolean)


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

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

#post?Boolean

Returns:

  • (Boolean)


145
146
147
# File 'lib/flow_chat/async_job.rb', line 145

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

#request_methodObject

Rails request interface compatibility



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

def request_method
  method.upcase
end

#ssl?Boolean

Returns:

  • (Boolean)


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

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

#user_agentObject



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

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