35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/http_client.rb', line 35
def HttpClient.internal_do_request(method, url, parameters = nil, content_type = nil, response_type = nil, authentication_handlers = nil)
httpResponse = nil;
= {}
if parameters == nil
parameters = {}
end
authentication_handlers.each do |handler|
if handler.kind_of? Mashape::HeaderAuthentication
= .merge(handler.handleHeader)
elsif handler.kind_of? Mashape::QueryAuthentication
parameters = parameters.merge(handler.handleParams)
elsif handler.kind_of? Mashape::OAuth10aAuthentication
if url.end_with?("/oauth_url") == false && (handler.handleParams[:access_token] == nil || handler.handleParams[:access_secret] == nil)
raise Mashape::JsonException.new("Before consuming OAuth endpoint, invoke authorize('access_token','access_secret') with not null values")
end
["x-mashape-oauth-consumerkey"] = handler.handleParams[:consumer_key]
["x-mashape-oauth-consumersecret"] = handler.handleParams[:consumer_secret]
["x-mashape-oauth-accesstoken"] = handler.handleParams[:access_token]
["x-mashape-oauth-accesssecret"] = handler.handleParams[:access_secret]
elsif handler.kind_of? Mashape::OAuth2Authentication
if url.end_with?("/oauth_url") == false && handler.handleParams[:access_token] == nil
raise Mashape::JsonException.new("Before consuming OAuth endpoint, invoke authorize('access_token') with a not null value")
end
parameters = parameters.merge({"access_token" => handler.handleParams[:access_token]})
end
end
Mashape::HttpUtils.(content_type, response_type, )
if(content_type == :json)
unless parameters[:json_param_body] == nil
parameters = JSON(parameters[:json_param_body])
else
parameters = {}
end
end
begin
case method
when :get
uri = Addressable::URI.new
uri.query_values = parameters
httpResponse = RestClient.get url + "?" + uri.query,
when :post
httpResponse = RestClient.post url, parameters,
when :put
httpResponse = RestClient.put url, parameters,
when :delete
httpResponse = RestClient.delete url, parameters,
when :patch
httpResponse = RestClient.patch url, parameters,
end
rescue => e
httpResponse = e.response
end
response = HttpResponse.new
response.code = httpResponse.code
response. = httpResponse.
response.raw_body = httpResponse
Mashape::HttpUtils.setResponse(response_type, response)
return response
end
|