# Load SystemTimer for implementing request timeouts
gem "SystemTimer", ">= 1.1.3", :require => "system_timer", :platforms => :ruby_18
+# Load faraday for mockable HTTP client
+gem "faraday"
+
# Load httpclient and soap4r for SOAP support for Quova GeoIP queries
gem "httpclient"
gem "soap4r-ruby1.9"
crass (~> 1.0.1)
nokogiri (>= 1.4.4)
nokogumbo (= 1.2.0)
- sass (3.4.12)
+ sass (3.4.13)
sass-rails (5.0.1)
railties (>= 4.0.0, < 5.0)
sass (~> 3.1)
tins (1.3.4)
tzinfo (1.2.2)
thread_safe (~> 0.1)
- uglifier (2.7.0)
+ uglifier (2.7.1)
execjs (>= 0.3.0)
json (>= 1.8.0)
validates_email_format_of (1.6.2)
dalli
deadlock_retry (>= 1.2.0)
dynamic_form
+ faraday
htmlentities
http_accept_language (~> 2.0.0)
httpclient
def self.ip_to_country(ip_address)
Timer.timeout(4) do
- ipinfo = Quova::IpInfo.new(ip_address)
+ ipinfo = Quova::IpInfo.new(ip_address) if defined?(QUOVA_USERNAME)
- if ipinfo.status == Quova::SUCCESS
+ if ipinfo && ipinfo.status == Quova::SUCCESS
country = ipinfo.country_code
else
- Net::HTTP.start("api.hostip.info") do |http|
- country = http.get("/country.php?ip=#{ip_address}").body
- country = "GB" if country == "UK"
- end
+ country = http_client.get("http://api.hostip.info/country.php?ip=#{ip_address}").body
+ country = "GB" if country == "UK"
end
return country.upcase
"AND #{prefix}longitude BETWEEN #{bbox.min_lon} AND #{bbox.max_lon}"
end
+ # Return the terms and conditions text for a given country
def self.legal_text_for_country(country_code)
file_name = File.join(Rails.root, "config", "legales", country_code.to_s + ".yml")
file_name = File.join(Rails.root, "config", "legales", DEFAULT_LEGALE + ".yml") unless File.exist? file_name
YAML.load_file(file_name)
end
+
+ # Return the HTTP client to use
+ def self.http_client
+ @http_client ||= Faraday.new
+ end
+
+ # Set the HTTP client to use
+ def self.http_client=(client)
+ @http_client = client
+ end
end