Class: UnderOs::HTTP::Request::Receiver

Inherits:
Object
  • Object
show all
Defined in:
lib/under_os/http/receiver.rb

Instance Method Summary collapse

Constructor Details

#initialize(request, stream = false) ⇒ Receiver

Returns a new instance of Receiver.



6
7
8
9
10
# File 'lib/under_os/http/receiver.rb', line 6

def initialize(request, stream=false)
  @request = request
  @stream  = stream
  @data    = NSMutableData.dataWithCapacity(0)
end

Instance Method Details

#connection(connection, didFailWithError: error) ⇒ Object

def connection(connection, willCacheResponse:cachedResponse)

return nil # don't cache

end



29
30
31
32
33
34
# File 'lib/under_os/http/receiver.rb', line 29

def connection(connection, didReceiveResponse:response)
  @data.setLength(0)
  @response = UnderOs::HTTP::Response.new(response, @data)

  emit(:response)
end

#connectionDidFinishLoading(connection) ⇒ Object



35
36
37
# File 'lib/under_os/http/receiver.rb', line 35

def connectionDidFinishLoading(connection)
  emit(:success)
end

#emit(event) ⇒ Object



39
40
41
42
# File 'lib/under_os/http/receiver.rb', line 39

def emit(event)
  @request.emit(event, response: @response)
  @request.emit(:complete, response: @response) if event == :failure || event == :success
end