module FreegeoipRuby

Constants

VERSION

Public Class Methods

configuration() click to toggle source
# File lib/freegeoip_ruby.rb, line 20
def self.configuration
  @configuration ||= Configuration.new
end
configure() { |configuration| ... } click to toggle source
# File lib/freegeoip_ruby.rb, line 24
def self.configure
  yield(configuration) if block_given?
end
ip_for(ip) click to toggle source
# File lib/freegeoip_ruby.rb, line 28
def self.ip_for(ip)
  connection.get do |req|
    req.url "/json/#{ip}"
    req.headers = headers_json
  end
end

Private Class Methods

connection() click to toggle source
# File lib/freegeoip_ruby.rb, line 37
def self.connection
  @connection ||= Faraday.new(url: configuration.endpoint) do |faraday|
    faraday.request  :url_encoded
    faraday.adapter  Faraday.default_adapter
  end
end
headers_json() click to toggle source
# File lib/freegeoip_ruby.rb, line 44
def self.headers_json
  {
    'User-Agent'        => 'Freegeoip Ruby SDK',
    'Content-Type'      => 'application/json'
  }
end