Class: RestClient::Payload::Base

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

Direct Known Subclasses

Multipart, Streamed, UrlEncoded

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Base

Returns a new instance of Base.



46
47
48
# File 'lib/restclient/payload.rb', line 46

def initialize(params)
  build_stream(params)
end

Instance Method Details

#build_stream(params) ⇒ Object



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

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

#closeObject



75
76
77
# File 'lib/restclient/payload.rb', line 75

def close
  @stream.close unless @stream.closed?
end

#headersObject



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

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

#read(*args) ⇒ Object



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

def read(*args)
  @stream.read(*args)
end

#short_inspectObject



83
84
85
# File 'lib/restclient/payload.rb', line 83

def short_inspect
  (size > 500 ? "#{size} byte(s) length" : to_s_inspect)
end

#sizeObject Also known as: length



69
70
71
# File 'lib/restclient/payload.rb', line 69

def size
  @stream.size
end

#to_sObject



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

def to_s
  result = read
  @stream.seek(0)
  result
end

#to_s_inspectObject



79
80
81
# File 'lib/restclient/payload.rb', line 79

def to_s_inspect
  to_s.inspect
end