Class: Yajl::HttpStream
Overview
This module is for making HTTP requests to which the response bodies (and possibly requests in the near future) are streamed directly into Yajl.
Defined Under Namespace
Classes: HttpError, InvalidContentType
Constant Summary collapse
- ALLOWED_MIME_TYPES =
The mime-type we expect the response to be. If it’s anything else, we can’t parse it and an InvalidContentType is raised.
["application/json", "text/plain"]
Class Method Summary collapse
-
.delete(uri, opts = {}, &block) ⇒ Object
Makes a basic HTTP DELETE request to the URI provided.
-
.get(uri, opts = {}, &block) ⇒ Object
Makes a basic HTTP GET request to the URI provided.
-
.post(uri, body, opts = {}, &block) ⇒ Object
Makes a basic HTTP POST request to the URI provided.
-
.put(uri, body, opts = {}, &block) ⇒ Object
Makes a basic HTTP PUT request to the URI provided.
Instance Method Summary collapse
-
#delete(uri, opts = {}, &block) ⇒ Object
Makes a basic HTTP DELETE request to the URI provided allowing the user to terminate the connection.
-
#get(uri, opts = {}, &block) ⇒ Object
Makes a basic HTTP GET request to the URI provided allowing the user to terminate the connection.
-
#post(uri, body, opts = {}, &block) ⇒ Object
Makes a basic HTTP POST request to the URI provided allowing the user to terminate the connection.
-
#put(uri, body, opts = {}, &block) ⇒ Object
Makes a basic HTTP PUT request to the URI provided allowing the user to terminate the connection.
-
#terminate ⇒ Object
Terminate a running HTTPStream instance.
Class Method Details
.delete(uri, opts = {}, &block) ⇒ Object
Makes a basic HTTP DELETE request to the URI provided
71 72 73 |
# File 'lib/yajl/http_stream.rb', line 71 def self.delete(uri, opts = {}, &block) request("DELETE", uri, opts, &block) end |
.get(uri, opts = {}, &block) ⇒ Object
Makes a basic HTTP GET request to the URI provided
32 33 34 |
# File 'lib/yajl/http_stream.rb', line 32 def self.get(uri, opts = {}, &block) request("GET", uri, opts, &block) end |
.post(uri, body, opts = {}, &block) ⇒ Object
Makes a basic HTTP POST request to the URI provided
45 46 47 |
# File 'lib/yajl/http_stream.rb', line 45 def self.post(uri, body, opts = {}, &block) request("POST", uri, opts.merge({:body => body}), &block) end |
.put(uri, body, opts = {}, &block) ⇒ Object
Makes a basic HTTP PUT request to the URI provided
58 59 60 |
# File 'lib/yajl/http_stream.rb', line 58 def self.put(uri, body, opts = {}, &block) request("PUT", uri, opts.merge({:body => body}), &block) end |
Instance Method Details
#delete(uri, opts = {}, &block) ⇒ Object
Makes a basic HTTP DELETE request to the URI provided allowing the user to terminate the connection
76 77 78 79 80 81 |
# File 'lib/yajl/http_stream.rb', line 76 def delete(uri, opts = {}, &block) initialize_socket(uri, opts) HttpStream::delete(uri, opts, &block) rescue IOError => e raise e unless @intentional_termination end |
#get(uri, opts = {}, &block) ⇒ Object
Makes a basic HTTP GET request to the URI provided allowing the user to terminate the connection
37 38 39 40 41 42 |
# File 'lib/yajl/http_stream.rb', line 37 def get(uri, opts = {}, &block) initialize_socket(uri, opts) HttpStream::get(uri, opts, &block) rescue IOError => e raise e unless @intentional_termination end |
#post(uri, body, opts = {}, &block) ⇒ Object
Makes a basic HTTP POST request to the URI provided allowing the user to terminate the connection
50 51 52 53 54 55 |
# File 'lib/yajl/http_stream.rb', line 50 def post(uri, body, opts = {}, &block) initialize_socket(uri, opts) HttpStream::post(uri, body, opts, &block) rescue IOError => e raise e unless @intentional_termination end |
#put(uri, body, opts = {}, &block) ⇒ Object
Makes a basic HTTP PUT request to the URI provided allowing the user to terminate the connection
63 64 65 66 67 68 |
# File 'lib/yajl/http_stream.rb', line 63 def put(uri, body, opts = {}, &block) initialize_socket(uri, opts) HttpStream::put(uri, body, opts, &block) rescue IOError => e raise e unless @intentional_termination end |
#terminate ⇒ Object
Terminate a running HTTPStream instance
84 85 86 87 |
# File 'lib/yajl/http_stream.rb', line 84 def terminate @intentional_termination = true @socket.close end |