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.



137
138
139
140
# File 'lib/strobe/connection.rb', line 137

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.



135
136
137
# File 'lib/strobe/connection.rb', line 135

def body
  @body
end

#connectionObject (readonly)

Returns the value of attribute connection.



135
136
137
# File 'lib/strobe/connection.rb', line 135

def connection
  @connection
end

#headersObject (readonly)

Returns the value of attribute headers.



135
136
137
# File 'lib/strobe/connection.rb', line 135

def headers
  @headers
end

#methodObject (readonly)

Returns the value of attribute method.



135
136
137
# File 'lib/strobe/connection.rb', line 135

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



135
136
137
# File 'lib/strobe/connection.rb', line 135

def path
  @path
end

Instance Method Details

#hostObject



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

def host; connection.host end

#portObject



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

def port; connection.port end

#sendObject



145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/strobe/connection.rb', line 145

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



158
159
160
161
162
163
164
165
# File 'lib/strobe/connection.rb', line 158

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