Class: UnderOs::HTTP::Request

Inherits:
Object
  • Object
show all
Includes:
Events
Defined in:
lib/under_os/http/request.rb,
lib/under_os/http/receiver.rb

Overview

A little wrap to handle iOS HTTP requests receiving

Defined Under Namespace

Classes: Receiver

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Events

#emit, #off

Constructor Details

#initialize(url, options = {}, &block) ⇒ Request

Returns a new instance of Request.



21
22
23
24
25
26
# File 'lib/under_os/http/request.rb', line 21

def initialize(url, options={}, &block)
  @url     = url
  @options = options

  on :complete, &block if block_given?
end

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



19
20
21
# File 'lib/under_os/http/request.rb', line 19

def method
  @method
end

#paramsObject (readonly)

Returns the value of attribute params.



19
20
21
# File 'lib/under_os/http/request.rb', line 19

def params
  @params
end

#urlObject (readonly)

Returns the value of attribute url.



19
20
21
# File 'lib/under_os/http/request.rb', line 19

def url
  @url
end

Instance Method Details

#cancelObject



42
43
44
# File 'lib/under_os/http/request.rb', line 42

def cancel
  @connection.cancel
end

#cookiesObject



57
58
59
# File 'lib/under_os/http/request.rb', line 57

def cookies
  @options[:cookies] || {}
end

#headersObject



53
54
55
# File 'lib/under_os/http/request.rb', line 53

def headers
  @options[:headers] || {}
end

#on(*args, &block) ⇒ Object



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

def on(*args, &block)
  super *args do |event|
    args = block.arity == 0 ? [] : [event.params[:response]]
    block.call *args
  end
end

#sendObject



35
36
37
38
39
40
# File 'lib/under_os/http/request.rb', line 35

def send
  @request    = build_request
  @receiver   = Receiver.new(self, @options[:stream])
  @connection = NSURLConnection.alloc.initWithRequest(@request, delegate:@receiver)
  @connection.start
end