Class: Strobe::Connection::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/strobe/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, method, path, body, headers) ⇒ Request

Returns a new instance of Request.



144
145
146
147
# File 'lib/strobe/connection.rb', line 144

def initialize(connection, method, path, body, headers)
  @connection, @path, @body, @headers = connection, path, body, headers
  @method = method
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



142
143
144
# File 'lib/strobe/connection.rb', line 142

def body
  @body
end

#connectionObject (readonly)

Returns the value of attribute connection.



142
143
144
# File 'lib/strobe/connection.rb', line 142

def connection
  @connection
end

#headersObject (readonly)

Returns the value of attribute headers.



142
143
144
# File 'lib/strobe/connection.rb', line 142

def headers
  @headers
end

#methodObject (readonly)

Returns the value of attribute method.



142
143
144
# File 'lib/strobe/connection.rb', line 142

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



142
143
144
# File 'lib/strobe/connection.rb', line 142

def path
  @path
end

Instance Method Details

#hostObject



149
# File 'lib/strobe/connection.rb', line 149

def host; connection.host end

#portObject



150
# File 'lib/strobe/connection.rb', line 150

def port; connection.port end

#sendObject



152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/strobe/connection.rb', line 152

def send
  http    = build_http
  request = Net::HTTPGenericRequest.new(method, !!body, true, path, headers)

  body = self.body
  if body.respond_to?(:read)
    request.body_stream = body
    body = nil
  end

  http.request(request, body)
end

#to_hashObject



165
166
167
168
169
170
171
172
# File 'lib/strobe/connection.rb', line 165

def to_hash
  {
    :method => method,
    :path => path,
    :body => body,
    :headers => headers
  }
end