kvk 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +19 -0
- data/lib/kvk/gem.rb +69 -0
- data/lib/kvk/version.rb +11 -0
- data/lib/kvk.rb +6 -0
- metadata +47 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 16a53a6958e633c18b014d6200d7cbadfbeece75
|
|
4
|
+
data.tar.gz: 78705643d2f5e83ddbe665f4d3286077a611d4ed
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 55f567bc4c6e0524615f7b5491c17e4b0ca003d74d694628035397feb511c444840f1e5a9f3b4a57d3c24e2a99e06f8d5ae212b6d9321e7f37b5ac9c9d843c21
|
|
7
|
+
data.tar.gz: 62dbecb977a4b388f373e763167ae30423d7e93829818f940bb33e703f626cb0fe9e84e3c113742c9cca318d6fced214043e17ef175924cdc1ad99e6b983c1dc
|
data/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2015 Stephan Meijer
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
data/lib/kvk/gem.rb
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
##
|
|
2
|
+
# This module represents a wrapper for the KVK API.
|
|
3
|
+
module KVK
|
|
4
|
+
|
|
5
|
+
##
|
|
6
|
+
# Custom HTTP Client Error.
|
|
7
|
+
#
|
|
8
|
+
# Throw this if HTTP STATUS CODE indicates an error. (>= 400)
|
|
9
|
+
class HTTPClientError < StandardError; end
|
|
10
|
+
|
|
11
|
+
##
|
|
12
|
+
# Request a list with companies using the string +query+.
|
|
13
|
+
# +query+ contains the keywords to search with.
|
|
14
|
+
#
|
|
15
|
+
# This function requests all companies according to the keywords in the strings +query+,
|
|
16
|
+
# and returns a hash.
|
|
17
|
+
#
|
|
18
|
+
# * *Args* :
|
|
19
|
+
# - +query+ -> keywords to search with in the OpenKVK API
|
|
20
|
+
# * *Returns* :
|
|
21
|
+
# - search results (with type Hash)
|
|
22
|
+
# * *Raises* :
|
|
23
|
+
# - +SocketError+ -> if OpenKVK changed their hostname without telling people
|
|
24
|
+
# - +HTTPClientError+ -> if HTTP STATUS CODE equals or is higher than 400
|
|
25
|
+
def search(query)
|
|
26
|
+
JSON.parse(get(query))["resultatenHR"]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
##
|
|
32
|
+
# Magic happens here. This function requests a JSON document, and returns it.
|
|
33
|
+
#
|
|
34
|
+
# * *Args* :
|
|
35
|
+
# - +query+ -> keywords to search with in the OpenKVK API
|
|
36
|
+
# - +protocol+ -> protocol to use, currently only support for HTTP
|
|
37
|
+
# - +host+ -> hostname of our API, might change once in a while
|
|
38
|
+
# * *Returns* :
|
|
39
|
+
# - String with searchresults in JSON
|
|
40
|
+
# * *Raises* :
|
|
41
|
+
# - +SocketError+ -> if OpenKVK changed their hostname without telling people
|
|
42
|
+
# - +HTTPClientError+ -> if HTTP STATUS CODE equals or is higher than 400
|
|
43
|
+
def get(query, protocol="http", host="zoeken.kvk.nl",
|
|
44
|
+
file="Address.ashx?q=")
|
|
45
|
+
# Use 'net/http' to request. Avoid as many depencies as possible.
|
|
46
|
+
url = URI.parse(
|
|
47
|
+
protocol +
|
|
48
|
+
"://" +
|
|
49
|
+
host +
|
|
50
|
+
"/" +
|
|
51
|
+
file +
|
|
52
|
+
CGI::escape(query)
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
# HTTP magic happens here.
|
|
56
|
+
req = Net::HTTP::Get.new(url.to_s)
|
|
57
|
+
res = Net::HTTP.start(url.host, url.port) do |http|
|
|
58
|
+
http.request(req)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# If HTTP STATUS not OK (STATUS >= 400), raise error.
|
|
62
|
+
raise(HTTPClientError, "Status code " + res.code) if res.code.to_i >= 400
|
|
63
|
+
|
|
64
|
+
res.body
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
module_function :search, :get
|
|
68
|
+
|
|
69
|
+
end
|
data/lib/kvk/version.rb
ADDED
data/lib/kvk.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: kvk
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Stephan Meijer
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-03-14 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: " Simple KVK API wrapper.\n"
|
|
14
|
+
email: me@stephanmeijer.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- LICENSE
|
|
20
|
+
- lib/kvk.rb
|
|
21
|
+
- lib/kvk/gem.rb
|
|
22
|
+
- lib/kvk/version.rb
|
|
23
|
+
homepage: http://github.com/StephanMeijer/kvk-ruby
|
|
24
|
+
licenses:
|
|
25
|
+
- MIT
|
|
26
|
+
metadata: {}
|
|
27
|
+
post_install_message:
|
|
28
|
+
rdoc_options: []
|
|
29
|
+
require_paths:
|
|
30
|
+
- lib
|
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
32
|
+
requirements:
|
|
33
|
+
- - ">="
|
|
34
|
+
- !ruby/object:Gem::Version
|
|
35
|
+
version: '0'
|
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
requirements: []
|
|
42
|
+
rubyforge_project:
|
|
43
|
+
rubygems_version: 2.4.5
|
|
44
|
+
signing_key:
|
|
45
|
+
specification_version: 4
|
|
46
|
+
summary: A simple KVK wrapper.
|
|
47
|
+
test_files: []
|