-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into get_address_1.8.2-sma1970
- Loading branch information
Showing
25 changed files
with
703 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
require 'geocoder/lookups/base' | ||
require 'geocoder/results/ip2location_io' | ||
|
||
module Geocoder::Lookup | ||
class Ip2locationIo < Base | ||
|
||
def name | ||
"IP2LocationIOApi" | ||
end | ||
|
||
def required_api_key_parts | ||
['key'] | ||
end | ||
|
||
def supported_protocols | ||
[:http, :https] | ||
end | ||
|
||
private # ---------------------------------------------------------------- | ||
|
||
def base_query_url(query) | ||
"#{protocol}://api.ip2location.io/?" | ||
end | ||
|
||
def query_url_params(query) | ||
super.merge( | ||
key: configuration.api_key, | ||
ip: query.sanitized_text, | ||
) | ||
end | ||
|
||
def results(query) | ||
# don't look up a loopback or private address, just return the stored result | ||
return [reserved_result(query.text)] if query.internal_ip_address? | ||
return [] unless doc = fetch_data(query) | ||
if doc["response"] == "INVALID ACCOUNT" | ||
raise_error(Geocoder::InvalidApiKey) || Geocoder.log(:warn, "INVALID ACCOUNT") | ||
return [] | ||
else | ||
return [doc] | ||
end | ||
end | ||
|
||
def reserved_result(query) | ||
{ | ||
"ip" => "-", | ||
"country_code" => "-", | ||
"country_name" => "-", | ||
"region_name" => "-", | ||
"city_name" => "-", | ||
"latitude" => null, | ||
"longitude" => null, | ||
"zip_code" => "-", | ||
"time_zone" => "-", | ||
"asn" => "-", | ||
"as" => "-", | ||
"is_proxy" => false | ||
} | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require 'geocoder/lookups/base' | ||
require 'geocoder/results/ip2location_lite' | ||
|
||
module Geocoder | ||
module Lookup | ||
class Ip2locationLite < Base | ||
attr_reader :gem_name | ||
|
||
def initialize | ||
unless configuration[:file].nil? | ||
begin | ||
@gem_name = 'ip2location_ruby' | ||
require @gem_name | ||
rescue LoadError | ||
raise "Could not load IP2Location DB dependency. To use the IP2LocationLite lookup you must add the #{@gem_name} gem to your Gemfile or have it installed in your system." | ||
end | ||
end | ||
super | ||
end | ||
|
||
def name | ||
'IP2LocationLite' | ||
end | ||
|
||
def required_api_key_parts | ||
[] | ||
end | ||
|
||
private | ||
|
||
def results(query) | ||
return [] unless configuration[:file] | ||
|
||
i2l = Ip2location.new.open(configuration[:file].to_s) | ||
result = i2l.get_all(query.to_s) | ||
result.nil? ? [] : [result] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'geocoder/lookups/base' | ||
require "geocoder/results/pdok_nl" | ||
|
||
module Geocoder::Lookup | ||
class PdokNl < Base | ||
|
||
def name | ||
'pdok NL' | ||
end | ||
|
||
def supported_protocols | ||
[:https] | ||
end | ||
|
||
private # --------------------------------------------------------------- | ||
|
||
def cache_key(query) | ||
base_query_url(query) + hash_to_query(query_url_params(query)) | ||
end | ||
|
||
def base_query_url(query) | ||
"#{protocol}://api.pdok.nl/bzk/locatieserver/search/v3_1/free?" | ||
end | ||
|
||
def valid_response?(response) | ||
json = parse_json(response.body) | ||
super(response) if json | ||
end | ||
|
||
def results(query) | ||
return [] unless doc = fetch_data(query) | ||
return doc['response']['docs'] | ||
end | ||
|
||
def query_url_params(query) | ||
{ | ||
fl: '*', | ||
q: query.text, | ||
wt: 'json' | ||
}.merge(super) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'geocoder/results/base' | ||
|
||
module Geocoder::Result | ||
class Ip2locationIo < Base | ||
|
||
def address(format = :full) | ||
"#{city_name} #{zip_code}, #{country_name}".sub(/^[ ,]*/, '') | ||
end | ||
|
||
def self.response_attributes | ||
%w[ip country_code country_name region_name city_name latitude longitude | ||
zip_code time_zone asn as is_proxy] | ||
end | ||
|
||
response_attributes.each do |attr| | ||
define_method attr do | ||
@data[attr] || "" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require 'geocoder/results/base' | ||
|
||
module Geocoder::Result | ||
class Ip2locationLite < Base | ||
|
||
def coordinates | ||
[@data[:latitude], @data[:longitude]] | ||
end | ||
|
||
def city | ||
@data[:city] | ||
end | ||
|
||
def state | ||
@data[:region] | ||
end | ||
|
||
def state_code | ||
"" # Not available in Maxmind's database | ||
end | ||
|
||
def country | ||
@data[:country_long] | ||
end | ||
|
||
def country_code | ||
@data[:country_short] | ||
end | ||
|
||
def postal_code | ||
@data[:zipcode] | ||
end | ||
|
||
def self.response_attributes | ||
%w[country_short country_long region latitude longitude isp | ||
domain netspeed areacode iddcode timezone zipcode weatherstationname | ||
weatherstationcode mcc mnc mobilebrand elevation usagetype addresstype | ||
category district asn as] | ||
end | ||
|
||
response_attributes.each do |a| | ||
define_method a do | ||
@data[a] || "" | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.