Class: SMG::HTTP::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/smg/http/request.rb

Constant Summary collapse

DEFAULT_LIMIT =
5
VERBS =
[Net::HTTP::Get, Net::HTTP::Post, Net::HTTP::Put, Net::HTTP::Delete, Net::HTTP::Head]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(verb, uri, options = {}) ⇒ Request

Returns a new instance of Request.



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/smg/http/request.rb', line 17

def initialize(verb, uri, options = {})
  raise "unknown verb: #{verb}" unless VERBS.include?(verb)

  @verb     = verb
  @uri      = Addressable::URI.parse(uri)
  @proxy    = options[:proxy] ? Addressable::URI.parse(options[:proxy]) : nil
  @headers  = options[:headers] ? options[:headers].to_hash : {}
  @limit    = options[:no_follow] ? 1 : options[:limit] || DEFAULT_LIMIT
  @body     = options[:body]
  @timeout  = options[:timeout] ? options[:timeout].to_i : nil
  @pem      = options[:pem]
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



11
12
13
# File 'lib/smg/http/request.rb', line 11

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



11
12
13
# File 'lib/smg/http/request.rb', line 11

def headers
  @headers
end

#limitObject (readonly)

Returns the value of attribute limit.



11
12
13
# File 'lib/smg/http/request.rb', line 11

def limit
  @limit
end

#proxyObject (readonly)

Returns the value of attribute proxy.



11
12
13
# File 'lib/smg/http/request.rb', line 11

def proxy
  @proxy
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



11
12
13
# File 'lib/smg/http/request.rb', line 11

def timeout
  @timeout
end

#uriObject (readonly)

Returns the value of attribute uri.



11
12
13
# File 'lib/smg/http/request.rb', line 11

def uri
  @uri
end

#verbObject (readonly)

Returns the value of attribute verb.



11
12
13
# File 'lib/smg/http/request.rb', line 11

def verb
  @verb
end

Instance Method Details

#performObject



30
31
32
33
34
35
36
37
38
# File 'lib/smg/http/request.rb', line 30

def perform
  setup
  response = http.request(@request)
  handle_response(response)
rescue Timeout::Error => e
  raise TimeoutError, e.message
rescue OpenSSL::SSL::SSLError => e
  raise SSLError, e.message
end