Class: Yajl::HttpStream

Inherits:
Object show all
Defined in:
lib/yajl/http_stream.rb

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

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

Instance Method Summary collapse

Class Method Details

.delete(uri, opts = {}, &block) ⇒ Object

Makes a basic HTTP DELETE request to the URI provided



69
70
71
# File 'lib/yajl/http_stream.rb', line 69

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



30
31
32
# File 'lib/yajl/http_stream.rb', line 30

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



43
44
45
# File 'lib/yajl/http_stream.rb', line 43

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



56
57
58
# File 'lib/yajl/http_stream.rb', line 56

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



74
75
76
77
78
79
# File 'lib/yajl/http_stream.rb', line 74

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



35
36
37
38
39
40
# File 'lib/yajl/http_stream.rb', line 35

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



48
49
50
51
52
53
# File 'lib/yajl/http_stream.rb', line 48

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



61
62
63
64
65
66
# File 'lib/yajl/http_stream.rb', line 61

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

#terminateObject

Terminate a running HTTPStream instance



82
83
84
85
# File 'lib/yajl/http_stream.rb', line 82

def terminate
  @intentional_termination = true
  @socket.close
end