module ProxyCheck::API::Util
Constants
- ROOT_URL
Public Instance Methods
build_url(path, api_version)
click to toggle source
# File lib/proxycheck/api/util.rb, line 36 def build_url(path, api_version) "#{ File.join(ROOT_URL, api_version, path) }" end
call(path, api_version = "v1", type = :get, params = {})
click to toggle source
# File lib/proxycheck/api/util.rb, line 12 def call(path, api_version = "v1", type = :get, params = {}) params.merge!({key: api_key}) if !api_key.blank? _path = path + "&" + URI.encode_www_form(params) uri = URI.parse(build_url(_path, api_version)) #uri.query = _ip + "&" + URI.encode_www_form(params) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true if uri.scheme.upcase == "HTTPS" http.verify_mode = OpenSSL::SSL::VERIFY_NONE if uri.scheme.upcase == "HTTPS" case type when :get request = Net::HTTP::Get.new(uri.request_uri) when :post request = Net::HTTP::Post.new(uri.request_uri) end response = http.request(request) JSON.parse(response.body) end