class RipeDbClient::Query

Query: The class encapsulating all query methods on the RIPE REST Database service

@author Mike Simkins

Public Class Methods

new(api_key = nil, api_environment = nil ,base_query_path = 'apps.db.ripe.net/whois') click to toggle source

@param api_key API Key generated from the RIPE DB Portal @param api_environment [String] Either ‘production’ or ‘test’ @param base_query_path [String] URI Path (do not include http:// or https:// )

@return [Object] Returns the Client Instance

# File lib/ripe_db_client/query_client.rb, line 21
def initialize(api_key = nil, api_environment = nil ,base_query_path = 'apps.db.ripe.net/whois')
        @auth_key = api_key
        @app_environment = api_environment || 'test'
        @base_query_path = base_query_path
        self.set_secure_queries(false)
        self.set_data_source('ripe')
end

Public Instance Methods

get_supported_data_sources() click to toggle source

Returns a hash of all the data sources supported by the REST Client Interface

@return [Hash] The Raw Hash of supported data sources

# File lib/ripe_db_client/query_client.rb, line 82
def get_supported_data_sources
        service_url = "#{@base_query_uri}/sources.json"
        response = HTTParty.get(service_url)
        response
end
lookup(lookup_key, lookup_value, lookup_source = nil) click to toggle source

Look up the exact value of the key/value pair @param lookup_key [String]

This is the object type you are looking for. This should be currently one of the RIPE
database supported types ('person', 'mntner','abuse-c'....)

@param lookup_value [String] The actual key you are looking for (‘RIPE-DBM-MNT’) @param lookup_source [String] The optional registry to use if it is not the default, or current registry

@example lookup(“mntner”,“RIPE-DBM-MNT”) @example lookup(“person”,“RIPE-DBM-MNT”)

@return [Hash] The Hash of values for the returned object

# File lib/ripe_db_client/query_client.rb, line 102
def lookup(lookup_key, lookup_value, lookup_source = nil)
        if lookup_key.nil? || lookup_key.empty?
                raise RipeDbClient::BadParameter.new('lookup_key cannot be empty, or nil', 'lookup')
        end
        if lookup_value.nil? || lookup_value.empty?
                raise RipeDbClient::BadParameter.new('lookup_value cannot be empty, or nil', 'lookup')
        end
        if  lookup_source.nil? || lookup_source.empty?
                lookup_source = @source_registry
        end
        service_url = "#{@base_query_uri}/lookup/#{lookup_source.downcase}/#{lookup_key.downcase}/#{lookup_value}.json"
        response = HTTParty.get(service_url)
        response
end
lookup_person(lookup_key,return_raw = false) click to toggle source

Look up the exact value of the key/value pair @param lookup_key [String]

This is the name of the person you are doing the lookup for

@param return_raw [Boolean]

Set this to true to return the RAW(Unparsed) Hash

@example lookup_person(“MPS31-RIPE”)

@return [Hash] The Hash of values for the returned object

# File lib/ripe_db_client/query_and_parse.rb, line 16
def lookup_person(lookup_key,return_raw = false)
  local_result = self.lookup('person', "#{lookup_key}")
  if return_raw
    return local_result
  else
    return person_parser(local_result)
  end

end
secure_queries?() click to toggle source

Check tp see if we are performing queries over https @return [Boolean] - If we are currently using https

# File lib/ripe_db_client/query_client.rb, line 72
def secure_queries?
        @base_query_uri.include? 'https://'
end
set_data_source(sourceid) click to toggle source

The set_data_source function allows you to manually set a database source to query for the object.

@param sourceid [String] The Registry source to query - Currently supports RIPE, AFriNic, and APnic

@return [String] The new Source Registry

If the passed parameters are invalid, then the method throws a RipeDbClient::Unsupported
exception
# File lib/ripe_db_client/query_client.rb, line 37
def set_data_source(sourceid)
        if %w(ripe afrinic apnic).include? sourceid.downcase
                @source_registry = sourceid
        else
                raise RipeDbClient::Unsupported.new('The only Supported registries are RIPE, AFRINIC, and APNIC', 'set_data_source')
        end
end
set_secure_queries(secure_mode) click to toggle source

As standard, queries are performed over the HTTP protocol. If you pass a true value to this function, it will use queries over HTTPS @param secure_mode [Boolean] Enable queries over HTTPS @return [String] - The current access URI

# File lib/ripe_db_client/query_client.rb, line 60
def set_secure_queries(secure_mode)
        if secure_mode
                @base_query_uri = 'https://' + @base_query_path
        else
                @base_query_uri = 'http://' + @base_query_path
        end
        @base_query_uri
end
source_registry?() click to toggle source

The source_registry? function allows you to manually set a database source to query for the object.

@return [String] The new Source Registry

If the passed parameters are invalid, then the method throws a RipeDbClient::Unsupported
exception
# File lib/ripe_db_client/query_client.rb, line 50
def source_registry?
        @source_registry
end

Private Instance Methods

person_parser(returned_hash) click to toggle source
# File lib/ripe_db_client/query_and_parse.rb, line 30
def person_parser(returned_hash)

end