Class: RipeDbClient::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/ripe_db_client/query_client.rb,
lib/ripe_db_client/query_and_parse.rb

Overview

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

Author:

  • Mike Simkins

Instance Method Summary collapse

Constructor Details

#initialize(api_key = nil, api_environment = nil, base_query_path = 'apps.db.ripe.net/whois') ⇒ Object



21
22
23
24
25
26
27
# 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

Instance Method Details

#get_supported_data_sourcesHash

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



82
83
84
85
86
# 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) ⇒ Hash

Look up the exact value of the key/value pair

Examples:

lookup(“mntner”,“RIPE-DBM-MNT”)


lookup(“person”,“RIPE-DBM-MNT”)




102
103
104
105
106
107
108
109
110
111
112
113
114
115
# 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) ⇒ Hash

Look up the exact value of the key/value pair

Examples:

lookup_person(“MPS31-RIPE”)




16
17
18
19
20
21
22
23
24
# 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?Boolean

Check tp see if we are performing queries over https



72
73
74
# File 'lib/ripe_db_client/query_client.rb', line 72

def secure_queries?
  @base_query_uri.include? 'https://'
end

#set_data_source(sourceid) ⇒ String

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



37
38
39
40
41
42
43
# 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) ⇒ String

As standard, queries are performed over the HTTP protocol. If you pass a true value to this function, it will use queries over HTTPS



60
61
62
63
64
65
66
67
# 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?String

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



50
51
52
# File 'lib/ripe_db_client/query_client.rb', line 50

def source_registry?
  @source_registry
end