Class: Rufus::Jig::HttpCore
- Inherits:
-
Object
- Object
- Rufus::Jig::HttpCore
- Defined in:
- lib/rufus/jig/http.rb
Overview
The base for the Rufus::Jig::Http class.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#_fragment ⇒ Object
Sometimes a URI is passed for initialization, if the URI contained a path, it is stored in @_path (and not used).
-
#_path ⇒ Object
Sometimes a URI is passed for initialization, if the URI contained a path, it is stored in @_path (and not used).
-
#_query ⇒ Object
Sometimes a URI is passed for initialization, if the URI contained a path, it is stored in @_path (and not used).
-
#cache ⇒ Object
readonly
the path => [ etag, decoded_body] client cache.
-
#error_class ⇒ Object
The class of the error that should be raised when a request is not 2xx.
-
#host ⇒ Object
readonly
scheme, host and port, vanilla.
-
#last_response ⇒ Object
readonly
mostly for debugging purposes.
-
#options ⇒ Object
readonly
the options for the http client.
-
#port ⇒ Object
readonly
scheme, host and port, vanilla.
-
#scheme ⇒ Object
readonly
scheme, host and port, vanilla.
Instance Method Summary collapse
- #delete(path, opts = {}) ⇒ Object
- #get(path, opts = {}) ⇒ Object
-
#initialize(*args) ⇒ HttpCore
constructor
A new instance of HttpCore.
- #post(path, data, opts = {}) ⇒ Object
- #put(path, data, opts = {}) ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(*args) ⇒ HttpCore
Returns a new instance of HttpCore.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/rufus/jig/http.rb', line 217 def initialize(*args) @options = args.last.is_a?(Hash) ? args.pop.dup : {} if args[1].is_a?(Fixnum) # host, port[, path] @scheme = 'http' @host, @port, @_path = args else # uri u = Rufus::Jig.parse_uri(args.first) @scheme = u.scheme @host = u.host @port = u.port @options[:basic_auth] ||= [ u.username, u.password ] if u.username if args[1] uu = Rufus::Jig.parse_uri(args[1]) @_path = uu.path @_query = uu.query @_fragment = uu.fragment else @_path = u.path @_query = u.query @_fragment = u.fragment end end @_path ||= '' @cache = LruHash.new((@options[:cache_size] || 35).to_i) if pf = @options[:prefix] @options[:prefix] = "/#{pf}" if (not pf.match(/^\//)) end @error_class = @options[:error_class] || HttpError end |
Instance Attribute Details
#_fragment ⇒ Object
Sometimes a URI is passed for initialization, if the URI contained a path, it is stored in @_path (and not used). Rufus::Jig::Couch uses it though.
215 216 217 |
# File 'lib/rufus/jig/http.rb', line 215 def _fragment @_fragment end |
#_path ⇒ Object
Sometimes a URI is passed for initialization, if the URI contained a path, it is stored in @_path (and not used). Rufus::Jig::Couch uses it though.
215 216 217 |
# File 'lib/rufus/jig/http.rb', line 215 def _path @_path end |
#_query ⇒ Object
Sometimes a URI is passed for initialization, if the URI contained a path, it is stored in @_path (and not used). Rufus::Jig::Couch uses it though.
215 216 217 |
# File 'lib/rufus/jig/http.rb', line 215 def _query @_query end |
#cache ⇒ Object (readonly)
the path => [ etag, decoded_body] client cache
197 198 199 |
# File 'lib/rufus/jig/http.rb', line 197 def cache @cache end |
#error_class ⇒ Object
The class of the error that should be raised when a request is not 2xx.
209 210 211 |
# File 'lib/rufus/jig/http.rb', line 209 def error_class @error_class end |
#host ⇒ Object (readonly)
scheme, host and port, vanilla
205 206 207 |
# File 'lib/rufus/jig/http.rb', line 205 def host @host end |
#last_response ⇒ Object (readonly)
mostly for debugging purposes
193 194 195 |
# File 'lib/rufus/jig/http.rb', line 193 def last_response @last_response end |
#options ⇒ Object (readonly)
the options for the http client
201 202 203 |
# File 'lib/rufus/jig/http.rb', line 201 def @options end |
#port ⇒ Object (readonly)
scheme, host and port, vanilla
205 206 207 |
# File 'lib/rufus/jig/http.rb', line 205 def port @port end |
#scheme ⇒ Object (readonly)
scheme, host and port, vanilla
205 206 207 |
# File 'lib/rufus/jig/http.rb', line 205 def scheme @scheme end |
Instance Method Details
#delete(path, opts = {}) ⇒ Object
279 280 281 282 |
# File 'lib/rufus/jig/http.rb', line 279 def delete(path, opts={}) request(:delete, path, nil, opts) end |
#get(path, opts = {}) ⇒ Object
264 265 266 267 |
# File 'lib/rufus/jig/http.rb', line 264 def get(path, opts={}) request(:get, path, nil, opts) end |
#post(path, data, opts = {}) ⇒ Object
269 270 271 272 |
# File 'lib/rufus/jig/http.rb', line 269 def post(path, data, opts={}) request(:post, path, data, opts) end |
#put(path, data, opts = {}) ⇒ Object
274 275 276 277 |
# File 'lib/rufus/jig/http.rb', line 274 def put(path, data, opts={}) request(:put, path, data, opts) end |