Module: RestMan::Request::Init

Includes:
ActiveMethod
Included in:
RestMan::Request
Defined in:
lib/restman/request/init.rb,
lib/restman/request/init/url.rb,
lib/restman/request/init/ssl_opts.rb,
lib/restman/request/init/cookie_jar.rb,
lib/restman/request/init/url/normalize_url.rb,
lib/restman/request/init/url/add_query_from_headers.rb

Defined Under Namespace

Classes: CookieJar, SSLOpts, Url

Class Method Summary collapse

Class Method Details

.auth(uri, args) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/restman/request/init.rb', line 40

def auth(uri, args)
  user = CGI.unescape(uri.user) if uri.user
  password = CGI.unescape(uri.password) if uri.password

  if !user && !password
    user, password = Netrc.read[uri.hostname]
  end

  user = args[:user] if args.include?(:user)
  password = args[:password] if args.include?(:password)

  [user, password]
end

.headers(args) ⇒ Object



24
25
26
# File 'lib/restman/request/init.rb', line 24

def headers(args)
  (args[:headers] || {}).dup
end

.http_method(args) ⇒ Object

:include: _doc/lib/restman/request/init/http_method.rdoc

Raises:

  • (ArgumentError)


17
18
19
20
21
22
# File 'lib/restman/request/init.rb', line 17

def http_method(args)
  method = args[:method]
  raise ArgumentError.new('must pass :method') unless method

  method.to_s.downcase
end

.keep_alive_timeout(args) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/restman/request/init.rb', line 86

def keep_alive_timeout(args)
  if args.key?(:keep_alive_timeout)
    yield args[:keep_alive_timeout] 
  else
    2
  end
end

.open_timeout(args) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/restman/request/init.rb', line 76

def open_timeout(args)
  if args.key?(:open_timeout)
    yield args[:open_timeout] 
  elsif args.key?(:timeout)
    yield args[:timeout]
  else
    60
  end
end

.read_timeout(args) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/restman/request/init.rb', line 56

def read_timeout(args)
  if args.key?(:read_timeout)
    yield args[:read_timeout] 
  elsif args.key?(:timeout)
    yield args[:timeout]
  else
    60
  end
end

.stream_log_percent(args) ⇒ Object



94
95
96
97
98
99
100
# File 'lib/restman/request/init.rb', line 94

def stream_log_percent(args)
  percent = args[:stream_log_percent] || 10
  if percent <= 0 || percent > 100
    raise ArgumentError.new("Invalid :stream_log_percent #{@stream_log_percent.inspect}")
  end
  percent
end

.uri(url) ⇒ Object



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

def uri(url)
  uri = URI.parse(url)

  if uri.hostname.nil? || uri.hostname == ''
    raise URI::InvalidURIError.new("bad URI(no host provided): #{url}")
  end

  uri
end

.write_timeout(args) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/restman/request/init.rb', line 66

def write_timeout(args)
  if args.key?(:write_timeout)
    yield args[:write_timeout] 
  elsif args.key?(:timeout)
    yield args[:timeout]
  else
    60
  end
end