Class: Nestful::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/monkey_patch/nestful_decode.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#buffer_binmodeObject

Returns the value of attribute buffer_binmode.



3
4
5
# File 'lib/monkey_patch/nestful_decode.rb', line 3

def buffer_binmode
  @buffer_binmode
end

Instance Method Details

#decoded(result) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/monkey_patch/nestful_decode.rb', line 5

def decoded(result)
  if buffer
    data  = Tempfile.new("nfr.#{rand(1000)}")
    data.binmode if buffer_binmode
    size  = 0
    total = result.content_length
    
    result.read_body do |chunk|
      callback(:progress, self, total, size += chunk.size)
      data.write(chunk)
    end
    
    data.rewind
    data
  else
    return result if raw
    data = result.body
    format ? format.decode(data) : data
  end
end