Class: HTTParty::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-crowdflower/patches/httparty.rb

Instance Method Summary collapse

Instance Method Details

#handle_response(response) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ruby-crowdflower/patches/httparty.rb', line 3

def handle_response(response)
  case response
    when Net::HTTPRedirection
      options[:limit] -= 1
    
      self.http_method = Net::HTTP::Get
      self.path = response['location']
      
      #Remove post data
      options[:body] = ""
      options[:headers].delete('content-type')
      @message = parse_response(response.body.to_s) rescue nil
      perform
    else
      parsed_response = parse_response(response.body.to_s)
      Response.new(parsed_response, response.body.to_s, response.code, @message || response.message, response.to_hash)
    end
rescue
  puts response.body.to_s
end