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.



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

def initialize(params)
  build_stream(params)
end

Instance Method Details

#build_stream(params) ⇒ Object



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

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

#closeObject



89
90
91
# File 'lib/restclient/payload.rb', line 89

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

#closed?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/restclient/payload.rb', line 93

def closed?
  @stream.closed?
end

#headersObject



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

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

#read(*args) ⇒ Object



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

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

#short_inspectObject



101
102
103
104
105
106
107
# File 'lib/restclient/payload.rb', line 101

def short_inspect
  if size && size > 500
    "#{size} byte(s) length"
  else
    to_s_inspect
  end
end

#sizeObject Also known as: length



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

def size
  @stream.size
end

#to_sObject



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

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

#to_s_inspectObject



97
98
99
# File 'lib/restclient/payload.rb', line 97

def to_s_inspect
  to_s.inspect
end