Class: CarrierWave::TrueVault::Parser

Inherits:
HTTParty::Parser
  • Object
show all
Defined in:
lib/carrierwave/truevault/client.rb

Overview

Custom parser class for TrueVault API

Instance Method Summary collapse

Instance Method Details

#parseObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/carrierwave/truevault/client.rb', line 10

def parse
  case format
    when :html
      body
    when :json
      JSON.parse(body)
    when :octet_stream
      # TODO find a better way of doing this
      # The issue is that no matter what it gets frmo TV
      # the ContentType is always octet_stream
      begin
        JSON.parse(Base64.decode64(body))
      rescue JSON::ParserError
        file = Tempfile.new('blob')
        file.binmode
        file.write(body)
        file.rewind
        file
      end
    else
      body
  end
end