File: raw_response.rb

package info (click to toggle)
librestclient-ruby 1.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 276 kB
  • ctags: 133
  • sloc: ruby: 1,994; makefile: 5
file content (34 lines) | stat: -rw-r--r-- 832 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module RestClient
  # The response from RestClient on a raw request looks like a string, but is
  # actually one of these.  99% of the time you're making a rest call all you
  # care about is the body, but on the occassion you want to fetch the
  # headers you can:
  #
  #   RestClient.get('http://example.com').headers[:content_type]
  #
  # In addition, if you do not use the response as a string, you can access
  # a Tempfile object at res.file, which contains the path to the raw
  # downloaded request body.
  class RawResponse

    include AbstractResponse

    attr_reader :file

    def initialize tempfile, net_http_res, args
      @net_http_res = net_http_res
      @args = args
      @file = tempfile
    end

    def to_s
      @file.open
      @file.read
    end

    def size
      File.size file
    end

  end
end