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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

def terminate
  @intentional_termination = true
  @socket.close
end