13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/gw2/https.rb', line 13
def request(end_point = "", attr = {})
attr = DEFAULT_REQUEST.merge(attr)
if V1_ENDPOINTS.any? { |word| end_point.include?(word) }
uri = URI.parse(BASE_URL_V1 + end_point + query_string(attr[:query] || {}))
else
uri = URI.parse(BASE_URL_V2 + end_point + query_string(attr[:query] || {}))
end
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = attr[:ssl]
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if attr[:ssl]
request = Net::HTTP.const_get(attr[:action]).new(uri.request_uri)
attr[:headers].each { |key, value| request[key.to_s] = value } if attr[:headers]
request.set_form_data(attr[:form_data]) if attr[:form_data]
http.request(request)
end
|