Class: RestClient::Payload::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/restclient/payload.rb

Direct Known Subclasses

Multipart, UrlEncoded

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Base

Returns a new instance of Base.



34
35
36
# File 'lib/restclient/payload.rb', line 34

def initialize(params)
  build_stream(params)
end

Instance Method Details

#build_stream(params) ⇒ Object



38
39
40
41
# File 'lib/restclient/payload.rb', line 38

def build_stream(params)
  @stream = StringIO.new(params)
  @stream.seek(0)
end

#closeObject



61
62
63
# File 'lib/restclient/payload.rb', line 61

def close
  @stream.close
end

#escape(v) ⇒ Object



48
49
50
# File 'lib/restclient/payload.rb', line 48

def escape(v)
  URI.escape(v.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
end

#headersObject



52
53
54
# File 'lib/restclient/payload.rb', line 52

def headers
  { 'Content-Length' => size.to_s }
end

#inspectObject



65
66
67
68
# File 'lib/restclient/payload.rb', line 65

def inspect
  to_s.inspect
  @stream.seek(0)
end

#read(bytes = nil) ⇒ Object Also known as: to_s



43
44
45
# File 'lib/restclient/payload.rb', line 43

def read(bytes=nil)
  @stream.read(bytes)
end

#sizeObject Also known as: length



56
57
58
# File 'lib/restclient/payload.rb', line 56

def size
  @stream.size
end