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.



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

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.



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

def method
  @method
end

#paramsObject (readonly)

Returns the value of attribute params.



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

def params
  @params
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#cancelObject



46
47
48
49
50
# File 'lib/under_os/http/request.rb', line 46

def cancel
  @connection.cancel

  return self
end

#cookiesObject



63
64
65
# File 'lib/under_os/http/request.rb', line 63

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

#encodingObject



71
72
73
# File 'lib/under_os/http/request.rb', line 71

def encoding
  @options[:encoding] || 'utf-8'
end

#headersObject



59
60
61
# File 'lib/under_os/http/request.rb', line 59

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

#on(*args, &block) ⇒ Object



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

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

#sendObject



37
38
39
40
41
42
43
44
# File 'lib/under_os/http/request.rb', line 37

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

  return self
end