Class: HttpRequest

Inherits:
BaseRequest show all
Defined in:
lib/libisi/request/http.rb

Instance Attribute Summary

Attributes inherited from BaseRequest

#environment, #task

Class Method Summary collapse

Methods inherited from BaseRequest

#execute, #initialize

Constructor Details

This class inherits a constructor from BaseRequest

Class Method Details

.from_uri(uri, options = {}) ⇒ Object

Splits a ordinary http url into

  • HttpEnvironment

  • Task(Function and Parameters)



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/libisi/request/http.rb', line 32

def HttpRequest.from_uri(uri, options = {})
  raise "Unexpected uri provided #{uri.parse}" unless uri.class == URI::HTTP
  options = {
    :root => URI::HTTP.build(:scheme => uri.scheme,
       :userinfo => uri.userinfo,
       :host => uri.host,
       :port => uri.port,
       :path => "/")
  }.merge(options)
      
  unless uri.to_s.starts_with?(options[:root].to_s)
    raise "URI #{uri.to_s} does not start with root #{options[:root].to_s}"
  end

  # take the rest of the path as context, function name and arguments
  path_rest = uri.path[options[:root].path.length..-1]
  
  # environment
  env = HttpEnvironment.new(options[:root])

  # task
  task = HttpTask.from_path_with_parameters(path_rest + "?" + uri.query)

  HttpRequest.new(env, task)
end