Module: OpenKVK
- Defined in:
- lib/openkvk/gem.rb,
lib/openkvk/version.rb
Overview
This module represents a wrapper for the Openkvk.nl API.
Defined Under Namespace
Classes: HTTPClientError
Class Method Summary collapse
-
.get(query, protocol = "http", host = "officieel.openkvk.nl") ⇒ Object
Magic happens here.
-
.search(query) ⇒ Object
Request a list with companies using the string
query. - .version ⇒ Object
Class Method Details
.get(query, protocol = "http", host = "officieel.openkvk.nl") ⇒ Object
Magic happens here. This function requests a JSON document, and returns it.
-
Args :
-
query-> keywords to search with in the OpenKVK API -
protocol-> protocol to use, currently only support for HTTP -
host-> hostname of our API, might change once in a while
-
-
Returns :
-
String with searchresults in JSON
-
-
Raises :
-
SocketError-> if OpenKVK changed their hostname without telling people -
HTTPClientError-> if HTTP STATUS CODE equals or is higher than 400
-
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/openkvk/gem.rb', line 43 def get(query, protocol="http", host="officieel.openkvk.nl") # Use 'net/http' to request. Avoid as many depencies as possible. url = URI.parse( protocol + "://" + host + "/" + CGI::escape(query) ) # HTTP magic happens here. req = Net::HTTP::Get.new(url.to_s) res = Net::HTTP.start(url.host, url.port) do |http| http.request(req) end # If HTTP STATUS not OK (STATUS >= 400), raise error. raise(HTTPClientError, "Status code " + res.code) if res.code.to_i >= 400 res.body end |
.search(query) ⇒ Object
Request a list with companies using the string query. query contains the keywords to search with.
This function requests all companies according to the keywords in the strings query, and returns a hash.
-
Args :
-
query-> keywords to search with in the OpenKVK API
-
-
Returns :
-
search results (with type Hash)
-
-
Raises :
-
SocketError-> if OpenKVK changed their hostname without telling people -
HTTPClientError-> if HTTP STATUS CODE equals or is higher than 400
-
25 26 27 |
# File 'lib/openkvk/gem.rb', line 25 def search(query) JSON.parse(get(query)) end |
.version ⇒ Object
2 3 4 5 6 7 8 |
# File 'lib/openkvk/version.rb', line 2 def version major = 0 minor = 0 tiny = 3 [major, minor, tiny].join('.') end |