Class: Mashape::HttpUtils

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

Class Method Summary collapse

Class Method Details

.setRequestHeaders(content_type, response_type, headers) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/http_utils.rb', line 14

def HttpUtils.setRequestHeaders(content_type, response_type, headers)
  headers["User-Agent"] = "mashape-ruby/2.0"
   
   case content_type
    when :json
     headers["Content-Type"] = "application/json"
    when :form
     headers["Content-Type"] = "application/x-www-form-urlencoded"
    when :binary
     headers["Content-Type"] = "multipart/form-data"
   end
   
   case response_type
     when :json
      headers["Accept"] = "application/json"
   end
end

.setResponse(response_type, output_response) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/http_utils.rb', line 32

def HttpUtils.setResponse(response_type, output_response)
    case response_type
      when :json
       begin
         output_response.body = JSON.parse(output_response.raw_body)
       rescue StandardError
         raise Mashape::JsonException.new("Can't parse the following response into JSON: " + output_response.raw_body)
       end
      else
       output_response.body = output_response.raw_body
    end
end

.uriEncode(value) ⇒ Object



10
11
12
# File 'lib/http_utils.rb', line 10

def HttpUtils.uriEncode(value)
  return URI.escape(value)
end