Class: RequestBody
- Inherits:
-
Object
- Object
- RequestBody
- Defined in:
- lib/primate/request_body.rb,
sig/primate.rbs
Instance Method Summary collapse
- #binary ⇒ Primate::Readable
- #blob ⇒ Object
- #files ⇒ Array[Primate::UploadedFile]
- #form ⇒ Hash[String, untyped]
-
#initialize(body, helpers) ⇒ RequestBody
constructor
A new instance of RequestBody.
- #json ⇒ Hash[String, untyped]
- #multipart ⇒ Object
- #text ⇒ String
Constructor Details
#initialize(body, helpers) ⇒ RequestBody
Returns a new instance of RequestBody.
17 18 19 20 |
# File 'lib/primate/request_body.rb', line 17 def initialize(body, helpers) @body = body @helpers = helpers end |
Instance Method Details
#binary ⇒ Primate::Readable
54 |
# File 'sig/primate.rbs', line 54
def binary: () -> Primate::Readable
|
#blob ⇒ Object
50 51 52 |
# File 'lib/primate/request_body.rb', line 50 def blob Primate::Readable.new(@body.blobSync, @body.blobTypeSync.to_s) end |
#files ⇒ Array[Primate::UploadedFile]
53 |
# File 'sig/primate.rbs', line 53
def files: () -> Array[Primate::UploadedFile]
|
#form ⇒ Hash[String, untyped]
30 31 32 |
# File 'lib/primate/request_body.rb', line 30 def form JSON.parse(@body.formSync.to_s) end |
#json ⇒ Hash[String, untyped]
22 23 24 |
# File 'lib/primate/request_body.rb', line 22 def json JSON.parse(@body.jsonSync.to_s) end |
#multipart ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/primate/request_body.rb', line 34 def multipart form = JSON.parse(@body.formSync.to_s) files_js = @body.filesSync files = Array.new(files_js[:length].to_i) do |i| f = files_js[i] Primate::UploadedFile.new( field: f['field'].to_s, name: f['name'].to_s, type: f['type'].to_s, size: f['size'].to_i, bytes: f['bytes'] ) end Multipart.new(form, files) end |
#text ⇒ String
26 27 28 |
# File 'lib/primate/request_body.rb', line 26 def text @body.textSync.to_s end |