firmenwissen 1.1.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -1
- data/lib/firmenwissen/configuration.rb +7 -2
- data/lib/firmenwissen/errors/api_key_error.rb +7 -0
- data/lib/firmenwissen/errors/authentication_strategy_error.rb +7 -0
- data/lib/firmenwissen/http_request.rb +2 -1
- data/lib/firmenwissen/request/base.rb +8 -1
- data/lib/firmenwissen/uri_decorator.rb +2 -0
- data/lib/firmenwissen/version.rb +1 -1
- metadata +24 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42e291ddf7bad7c2089c96877b831d5ab022482cd002018ded618e3a82be2f5a
|
4
|
+
data.tar.gz: 3448ce23abb5250d597f99c8fba7617ab98b7a2c51ca28df0b5f1778f239a4d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ba9040ccff5e27f74c7329e32e1e40e0fb4ef7a394ceb9afca0db95f91928928ef1d7839ebecbc51d7a40c4cec1187e97d1ad8a4a8bfd6a49134e07e1593067
|
7
|
+
data.tar.gz: 58478133681a39f6c479a981463351e88a019d197b5989ed89d55b9ad20364a7ed450cdda012d56a70ada0e845ce8ae7d4851f3cad96c0721ca9fe6c037c401c
|
data/README.md
CHANGED
@@ -45,9 +45,10 @@ suggestion.address # => 'Louise-Dumon-Straße 5'
|
|
45
45
|
|
46
46
|
suggestion.to_h # => { crefo_id: '1234567890', name: 'COMPEON GmbH', ... }
|
47
47
|
```
|
48
|
-
### Configuration
|
48
|
+
### Basic Auth Configuration
|
49
49
|
```ruby
|
50
50
|
Firmenwissen.configure do |config|
|
51
|
+
config.authentication_strategy = 'basic' # This is set to 'basic' by default, eliminating the need for explicit configuration.
|
51
52
|
config.user = 'username' # Username for Firmenwissen basic auth (required)
|
52
53
|
config.password = 'password' # Password for Firmenwissen basic auth (required)
|
53
54
|
config.timeout = 5 # Request timeout in seconds
|
@@ -57,6 +58,19 @@ Firmenwissen.configure do |config|
|
|
57
58
|
config.endpoint = 'https://example.com/search?query={query}'
|
58
59
|
end
|
59
60
|
```
|
61
|
+
### Api Key Configuration
|
62
|
+
```ruby
|
63
|
+
Firmenwissen.configure do |config|
|
64
|
+
config.authentication_strategy = 'api_key' # Mandatory for all options except 'basic' (required)
|
65
|
+
config.api_key = 'your api key' # API Key for Firmenwissen API Key authentication (required)
|
66
|
+
config.timeout = 5 # Request timeout in seconds
|
67
|
+
config.persistent_session = false # Whether to store/use session information for subsequent requests
|
68
|
+
|
69
|
+
# Configure the endpoint yourself. %s will be replaced by the actual query
|
70
|
+
config.endpoint = 'https://example.com/search?query={query}'
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
60
74
|
### Mocking results
|
61
75
|
In a non production-like environment you will not want to perform real requests to the API. Thus you can configure the gem to respond with mocked data.
|
62
76
|
|
@@ -10,14 +10,15 @@ module Firmenwissen
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
SETTINGS = %i[endpoint password mock_data mock_requests persistent_session timeout user]
|
13
|
+
SETTINGS = %i[endpoint password mock_data mock_requests persistent_session timeout user authentication_strategy api_key]
|
14
14
|
|
15
15
|
DEFAULT_SETTINGS = {
|
16
16
|
endpoint: 'https://www.firmenwissen.de/search/suggest/companywithaddress/{query}{?country}',
|
17
17
|
mock_requests: false,
|
18
18
|
mock_data: [],
|
19
19
|
persistent_session: false,
|
20
|
-
timeout: 5
|
20
|
+
timeout: 5,
|
21
|
+
authentication_strategy: "basic"
|
21
22
|
}.freeze
|
22
23
|
|
23
24
|
SETTINGS.each do |setting|
|
@@ -51,5 +52,9 @@ module Firmenwissen
|
|
51
52
|
def persistent_session?
|
52
53
|
persistent_session
|
53
54
|
end
|
55
|
+
|
56
|
+
def api_key_present?
|
57
|
+
api_key.is_a?(String) && !api_key.empty?
|
58
|
+
end
|
54
59
|
end
|
55
60
|
end
|
@@ -21,7 +21,8 @@ module Firmenwissen
|
|
21
21
|
def request
|
22
22
|
@request ||= begin
|
23
23
|
Net::HTTP::Get.new(uri).tap do |req|
|
24
|
-
req.basic_auth(config.user, config.password)
|
24
|
+
req.basic_auth(config.user, config.password) if config.authentication_strategy == "basic"
|
25
|
+
req.add_field('API-KEY', config.api_key) if config.authentication_strategy == "api_key"
|
25
26
|
req.add_field('Cookie', session_cookie) if config.persistent_session? && !session_cookie.empty?
|
26
27
|
end
|
27
28
|
end
|
@@ -6,7 +6,14 @@ module Firmenwissen
|
|
6
6
|
@options = options
|
7
7
|
@params = options.fetch(:params, {})
|
8
8
|
|
9
|
-
|
9
|
+
case config.authentication_strategy
|
10
|
+
when "basic"
|
11
|
+
raise CredentialsError unless config.credentials_present?
|
12
|
+
when "api_key"
|
13
|
+
raise ApiKeyError unless config.api_key_present?
|
14
|
+
else
|
15
|
+
raise AuthenticationStrategyError
|
16
|
+
end
|
10
17
|
end
|
11
18
|
|
12
19
|
def execute
|
data/lib/firmenwissen/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: firmenwissen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerrit Seger
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rexml
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rspec
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,7 +108,7 @@ dependencies:
|
|
94
108
|
- - ">="
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '0'
|
97
|
-
description:
|
111
|
+
description:
|
98
112
|
email:
|
99
113
|
- gerrit.seger@gmail.com
|
100
114
|
executables: []
|
@@ -106,6 +120,8 @@ files:
|
|
106
120
|
- Rakefile
|
107
121
|
- lib/firmenwissen.rb
|
108
122
|
- lib/firmenwissen/configuration.rb
|
123
|
+
- lib/firmenwissen/errors/api_key_error.rb
|
124
|
+
- lib/firmenwissen/errors/authentication_strategy_error.rb
|
109
125
|
- lib/firmenwissen/errors/credentials_error.rb
|
110
126
|
- lib/firmenwissen/errors/unprocessable_response_error.rb
|
111
127
|
- lib/firmenwissen/http_request.rb
|
@@ -119,11 +135,11 @@ files:
|
|
119
135
|
- lib/firmenwissen/suggestion.rb
|
120
136
|
- lib/firmenwissen/uri_decorator.rb
|
121
137
|
- lib/firmenwissen/version.rb
|
122
|
-
homepage:
|
138
|
+
homepage:
|
123
139
|
licenses:
|
124
140
|
- MIT
|
125
141
|
metadata: {}
|
126
|
-
post_install_message:
|
142
|
+
post_install_message:
|
127
143
|
rdoc_options: []
|
128
144
|
require_paths:
|
129
145
|
- lib
|
@@ -138,8 +154,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
154
|
- !ruby/object:Gem::Version
|
139
155
|
version: '0'
|
140
156
|
requirements: []
|
141
|
-
rubygems_version: 3.
|
142
|
-
signing_key:
|
157
|
+
rubygems_version: 3.1.4
|
158
|
+
signing_key:
|
143
159
|
specification_version: 4
|
144
160
|
summary: Ruby client for the FirmenWissen API
|
145
161
|
test_files: []
|