Module: HTTP::Chainable

Included in:
HTTP, Client
Defined in:
lib/http/chainable.rb

Instance Method Summary collapse

Instance Method Details

#accept(type) ⇒ Object

Accept the given MIME type(s)



94
95
96
# File 'lib/http/chainable.rb', line 94

def accept(type)
  with :accept => MimeType.normalize(type)
end

#auth(*args) ⇒ Object

Make a request with the given Authorization header



99
100
101
102
103
104
105
106
107
# File 'lib/http/chainable.rb', line 99

def auth(*args)
  value = case args.count
          when 1 then args.first
          when 2 then AuthorizationHeader.build(*args)
          else fail ArgumentError, "wrong number of arguments (#{args.count} for 1..2)"
          end

  with :authorization => value.to_s
end

#connect(uri, options = {}) ⇒ Object

Convert to a transparent TCP/IP tunnel



41
42
43
# File 'lib/http/chainable.rb', line 41

def connect(uri, options = {})
  request :connect, uri, options
end

#default_callbacksObject



127
128
129
# File 'lib/http/chainable.rb', line 127

def default_callbacks
  default_options.callbacks
end

#default_callbacks=(callbacks) ⇒ Object



131
132
133
134
135
# File 'lib/http/chainable.rb', line 131

def default_callbacks=(callbacks)
  @default_options = default_options.dup do |opts|
    opts.callbacks = callbacks
  end
end

#default_headersObject



117
118
119
# File 'lib/http/chainable.rb', line 117

def default_headers
  default_options.headers
end

#default_headers=(headers) ⇒ Object



121
122
123
124
125
# File 'lib/http/chainable.rb', line 121

def default_headers=(headers)
  @default_options = default_options.dup do |opts|
    opts.headers = headers
  end
end

#default_optionsObject



109
110
111
# File 'lib/http/chainable.rb', line 109

def default_options
  @default_options ||= HTTP::Options.new
end

#default_options=(opts) ⇒ Object



113
114
115
# File 'lib/http/chainable.rb', line 113

def default_options=(opts)
  @default_options = HTTP::Options.new(opts)
end

#delete(uri, options = {}) ⇒ Object

Delete a resource



26
27
28
# File 'lib/http/chainable.rb', line 26

def delete(uri, options = {})
  request :delete, uri, options
end

#follow(opts = true) ⇒ HTTP::Client Also known as: with_follow

Make client follow redirects.

Returns:



79
80
81
# File 'lib/http/chainable.rb', line 79

def follow(opts = true)
  branch default_options.with_follow opts
end

#get(uri, options = {}) ⇒ Object

Get a resource



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

def get(uri, options = {})
  request :get, uri, options
end

#head(uri, options = {}) ⇒ Object

Request a get sans response body



6
7
8
# File 'lib/http/chainable.rb', line 6

def head(uri, options = {})
  request :head, uri, options
end

#options(uri, options = {}) ⇒ Object

Return the methods supported on the given URI



36
37
38
# File 'lib/http/chainable.rb', line 36

def options(uri, options = {})
  request :options, uri, options
end

#patch(uri, options = {}) ⇒ Object

Apply partial modifications to a resource



46
47
48
# File 'lib/http/chainable.rb', line 46

def patch(uri, options = {})
  request :patch, uri, options
end

#post(uri, options = {}) ⇒ Object

Post to a resource



16
17
18
# File 'lib/http/chainable.rb', line 16

def post(uri, options = {})
  request :post, uri, options
end

#put(uri, options = {}) ⇒ Object

Put to a resource



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

def put(uri, options = {})
  request :put, uri, options
end

#request(verb, uri, options = {}) ⇒ Object

Make an HTTP request with the given verb



51
52
53
# File 'lib/http/chainable.rb', line 51

def request(verb, uri, options = {})
  branch(options).request verb, uri
end

#streamObject

Alias for with_response(:object)



72
73
74
# File 'lib/http/chainable.rb', line 72

def stream
  with_response(:object)
end

#trace(uri, options = {}) ⇒ Object

Echo the request back to the client



31
32
33
# File 'lib/http/chainable.rb', line 31

def trace(uri, options = {})
  request :trace, uri, options
end

#via(*proxy) ⇒ Object Also known as: through

Make a request through an HTTP proxy



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/http/chainable.rb', line 56

def via(*proxy)
  proxy_hash = {}
  proxy_hash[:proxy_address]  = proxy[0] if proxy[0].is_a?(String)
  proxy_hash[:proxy_port]     = proxy[1] if proxy[1].is_a?(Integer)
  proxy_hash[:proxy_username] = proxy[2] if proxy[2].is_a?(String)
  proxy_hash[:proxy_password] = proxy[3] if proxy[3].is_a?(String)

  if [2, 4].include?(proxy_hash.keys.size)
    branch default_options.with_proxy(proxy_hash)
  else
    fail(RequestError, "invalid HTTP proxy: #{proxy_hash}")
  end
end

#with_headers(headers) ⇒ Object Also known as: with

Make a request with the given headers



88
89
90
# File 'lib/http/chainable.rb', line 88

def with_headers(headers)
  branch default_options.with_headers(headers)
end