openkvk-wrapper 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d980713a9ba9556e9f19c60b1966c38602a8068
4
- data.tar.gz: 1337f301113f259b57596f07e9913591fa93d151
3
+ metadata.gz: 8f0716eb4c0615f2cf614302b6cbd2d8d92735c4
4
+ data.tar.gz: d50dd0574852cd5a8f6e56116806ee3eedf288fe
5
5
  SHA512:
6
- metadata.gz: 6343dc38cd6582fb75f17b06b3034e613431dd203706edda103becc8d732147135f6151210482df84d595d9099af080d732b78f580c69265686febfd22533020
7
- data.tar.gz: 20fa1a9550598e423b0007effbcf0f755c3d6e229b9a25389d14e7d328d3ea8ae1dcc7b538d33e9dc0833ef0e445b052edc46a43faed86c844a2e7b03eb937fc
6
+ metadata.gz: c2925d0d180c781498a7d0b8e90a8a5263d36664b1f3050230f9d1f55aa121f68b6c2310671b9933b7104e08f53263128ccb7d48477c55934ef1b1a534668eac
7
+ data.tar.gz: 28a27c6a06a81b476d6fd61d18ca08e128c1eea8524714812dd963e9098c95df3d4a4c37a346e7cd2cf5a8f0fe72ca78ec153c5db43c42300e81f961c3912ab6
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/openkvk.rb CHANGED
@@ -2,70 +2,5 @@ require 'net/http'
2
2
  require 'json'
3
3
  require 'cgi'
4
4
 
5
- ##
6
- # This module represents a wrapper for the Openkvk.nl API.
7
- module OpenKVK
8
-
9
- ##
10
- # Custom HTTP Client Error.
11
- #
12
- # Throw this if HTTP STATUS CODE indicates an error. (>= 400)
13
- class HTTPClientError < StandardError; end
14
-
15
- ##
16
- # Request a list with companies using the string +query+.
17
- # +query+ contains the keywords to search with.
18
- #
19
- # This function requests all companies according to the keywords in the strings +query+,
20
- # and returns a hash.
21
- #
22
- # * *Args* :
23
- # - +query+ -> keywords to search with in the OpenKVK API
24
- # * *Returns* :
25
- # - search results (with type Hash)
26
- # * *Raises* :
27
- # - +SocketError+ -> if OpenKVK changed their hostname without telling people
28
- # - +HTTPClientError+ -> if HTTP STATUS CODE equals or is higher than 400
29
- def search(query)
30
- JSON.parse(get(query))
31
- end
32
-
33
- private
34
-
35
- ##
36
- # Magic happens here. This function requests a JSON document, and returns it.
37
- #
38
- # * *Args* :
39
- # - +query+ -> keywords to search with in the OpenKVK API
40
- # - +protocol+ -> protocol to use, currently only support for HTTP
41
- # - +host+ -> hostname of our API, might change once in a while
42
- # * *Returns* :
43
- # - String with searchresults in JSON
44
- # * *Raises* :
45
- # - +SocketError+ -> if OpenKVK changed their hostname without telling people
46
- # - +HTTPClientError+ -> if HTTP STATUS CODE equals or is higher than 400
47
- def get(query, protocol="http", host="officieel.openkvk.nl")
48
- # Use 'net/http' to request. Avoid as many depencies as possible.
49
- url = URI.parse(
50
- protocol +
51
- "://" +
52
- host +
53
- "/" +
54
- CGI::escape(query)
55
- )
56
-
57
- # HTTP magic happens here.
58
- req = Net::HTTP::Get.new(url.to_s)
59
- res = Net::HTTP.start(url.host, url.port) do |http|
60
- http.request(req)
61
- end
62
-
63
- # If HTTP STATUS not OK (STATUS >= 400), raise error.
64
- raise(HTTPClientError, "Status code " + res.code) if res.code.to_i >= 400
65
-
66
- res.body
67
- end
68
-
69
- module_function :search, :get
70
-
71
- end
5
+ require 'simple_gem/version'
6
+ require 'simple_gem/gem'
@@ -0,0 +1,67 @@
1
+ ##
2
+ # This module represents a wrapper for the Openkvk.nl API.
3
+ module OpenKVK
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))
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="officieel.openkvk.nl")
44
+ # Use 'net/http' to request. Avoid as many depencies as possible.
45
+ url = URI.parse(
46
+ protocol +
47
+ "://" +
48
+ host +
49
+ "/" +
50
+ CGI::escape(query)
51
+ )
52
+
53
+ # HTTP magic happens here.
54
+ req = Net::HTTP::Get.new(url.to_s)
55
+ res = Net::HTTP.start(url.host, url.port) do |http|
56
+ http.request(req)
57
+ end
58
+
59
+ # If HTTP STATUS not OK (STATUS >= 400), raise error.
60
+ raise(HTTPClientError, "Status code " + res.code) if res.code.to_i >= 400
61
+
62
+ res.body
63
+ end
64
+
65
+ module_function :search, :get
66
+
67
+ end
@@ -0,0 +1,11 @@
1
+ module OpenKVK
2
+ def version
3
+ major = 0
4
+ minor = 0
5
+ tiny = 2
6
+
7
+ [major, minor, tiny].join('.')
8
+ end
9
+
10
+ module_function :version
11
+ end
metadata CHANGED
@@ -1,23 +1,26 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openkvk-wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
- - StephanMeijer
7
+ - Stephan Meijer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-13 00:00:00.000000000 Z
11
+ date: 2015-03-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: A simple wrapper for the OpenKVK API.
13
+ description: " Simple OpenKVK API wrapper.\n"
14
14
  email: me@stephanmeijer.com
15
15
  executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
+ - LICENSE
19
20
  - lib/openkvk.rb
20
- homepage: http://rubygems.org/gems/openkvk-wrapper
21
+ - lib/openkvk/gem.rb
22
+ - lib/openkvk/version.rb
23
+ homepage: http://github.com/StephanMeijer/openkvk-wrapper
21
24
  licenses:
22
25
  - MIT
23
26
  metadata: {}
@@ -37,8 +40,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
37
40
  version: '0'
38
41
  requirements: []
39
42
  rubyforge_project:
40
- rubygems_version: 2.4.6
43
+ rubygems_version: 2.4.5
41
44
  signing_key:
42
45
  specification_version: 4
43
- summary: Wrapper for openkvk.nl
46
+ summary: A simple OpenKVK wrapper.
44
47
  test_files: []