firmenwissen 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6499228c4827e93416dd1c35718fb4ecd483c67e5ef14f1bd35be6596a6b8acd
4
- data.tar.gz: 990c0a68b091c84e7d7046ee8606705c01ab8c67753afac1809621f2a94ba794
3
+ metadata.gz: 4b79d5acc8cdbc3936a046219302466d3fb782668787787dae2116f39c9bfa0c
4
+ data.tar.gz: 01d7fcf4001c1a13308819d248ec8752a746f9451d0fbbdc025e742ee0233aa7
5
5
  SHA512:
6
- metadata.gz: f242d64753d4dd251562c8550b5e7b0547579acb8d53f338d42fa6e42ad5d48655d607925e3bcfb855b9c9d15f02e7b59ca09f24eb295b0e1fc63edfe0be3c9a
7
- data.tar.gz: 55c3ca5f9fed873de5570fb0e80e70bee788bbbdf5e88372d365380ab67bca61af6d561a7513237aa6300f8043c7b312454024be16c74e3181dd46fdc18e6cf4
6
+ metadata.gz: 9a9075c20026a58be30af77fd1df06596eff00a60970ea83d060ecfa73ef938c0a7d0e165785ab6ded7e99f894494936770a8bbfe833325469ce2a2e4c33697b
7
+ data.tar.gz: af6eee45a08cd89d9f5cd3b085977bd6eeabb150e87d4e36a2a1ac01a98285530758cbbdfdb107855e9ed2b407a33d36802ced4701f82caa9c433d860c5efa90
data/README.md CHANGED
@@ -48,9 +48,10 @@ suggestion.to_h # => { crefo_id: '1234567890', name: 'COMPEON GmbH', ... }
48
48
  ### Configuration
49
49
  ```ruby
50
50
  Firmenwissen.configure do |config|
51
- config.user = 'username' # Username for Firmenwissen basic auth (required)
52
- config.password = 'password' # Password for Firmenwissen basic auth (required)
53
- config.timeout = 5 # Request timeout in seconds
51
+ config.user = 'username' # Username for Firmenwissen basic auth (required)
52
+ config.password = 'password' # Password for Firmenwissen basic auth (required)
53
+ config.timeout = 5 # Request timeout in seconds
54
+ config.persistent_session = false # Whether to store/use session information for subsequent requests
54
55
 
55
56
  # Configure the endpoint yourself. %s will be replaced by the actual query
56
57
  config.endpoint = 'https://example.com/search?query={query}'
@@ -93,5 +94,8 @@ end
93
94
  ```
94
95
  **Note:** All configuration options can be overridden on a per-request basis by passing an options hash to the `search` method.
95
96
 
97
+ ### On sessions
98
+ Session information is stored globally and used for _all_ subsequent requests made via the Firmenwissen gem if `persistent_session` is active.
99
+
96
100
  ## License
97
101
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/lib/firmenwissen.rb CHANGED
@@ -6,6 +6,7 @@ require 'firmenwissen/configuration'
6
6
  require 'firmenwissen/http_request'
7
7
  require 'firmenwissen/key_mapper'
8
8
  require 'firmenwissen/request'
9
+ require 'firmenwissen/session'
9
10
  require 'firmenwissen/suggestion'
10
11
  require 'firmenwissen/uri_decorator'
11
12
  require 'firmenwissen/version'
@@ -10,12 +10,13 @@ module Firmenwissen
10
10
  end
11
11
  end
12
12
 
13
- SETTINGS = %i[endpoint password mock_data mock_requests timeout user]
13
+ SETTINGS = %i[endpoint password mock_data mock_requests persistent_session timeout user]
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
+ persistent_session: false,
19
20
  timeout: 5
20
21
  }.freeze
21
22
 
@@ -46,5 +47,9 @@ module Firmenwissen
46
47
  def mock_requests?
47
48
  mock_requests
48
49
  end
50
+
51
+ def persistent_session?
52
+ persistent_session
53
+ end
49
54
  end
50
55
  end
@@ -8,7 +8,7 @@ module Firmenwissen
8
8
  def execute
9
9
  http = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.use_ssl?)
10
10
  http.read_timeout = config.timeout
11
- http.request(request)
11
+ http.request(request, &method(:extract_session))
12
12
  ensure
13
13
  http.finish
14
14
  http
@@ -22,6 +22,7 @@ module Firmenwissen
22
22
  @request ||= begin
23
23
  Net::HTTP::Get.new(uri).tap do |req|
24
24
  req.basic_auth(config.user, config.password)
25
+ req.add_field('Cookie', session_cookie) if config.persistent_session? && !session_cookie.empty?
25
26
  end
26
27
  end
27
28
  end
@@ -29,5 +30,15 @@ module Firmenwissen
29
30
  def config
30
31
  @config ||= Firmenwissen.configuration.merge(options)
31
32
  end
33
+
34
+ def extract_session(response)
35
+ return unless config.persistent_session?
36
+
37
+ Firmenwissen::Session.update_from_set_cookie_headers(response.get_fields('Set-Cookie'))
38
+ end
39
+
40
+ def session_cookie
41
+ @session_cookie ||= Firmenwissen::Session.to_cookie_string
42
+ end
32
43
  end
33
44
  end
@@ -0,0 +1,26 @@
1
+ module Firmenwissen
2
+ module Session
3
+ module_function
4
+
5
+ def cookies
6
+ @cookies ||= {}
7
+ end
8
+
9
+ def update_from_set_cookie_headers(set_cookie_headers)
10
+ return if set_cookie_headers.nil?
11
+
12
+ set_cookie_headers.each do |header|
13
+ name_and_value, _other_attrs = header.split(/;\s?/)
14
+ name, value = name_and_value.split('=', 2)
15
+
16
+ next if name.empty? || value.nil? || value.empty?
17
+
18
+ cookies[name] = value
19
+ end
20
+ end
21
+
22
+ def to_cookie_string
23
+ cookies.map { |entry| [entry].join('=') }.join('; ')
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module Firmenwissen
2
- VERSION = '1.0.3'
2
+ VERSION = '1.1.0'
3
3
  end
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.0.3
4
+ version: 1.1.0
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: 2018-02-07 00:00:00.000000000 Z
11
+ date: 2021-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +94,7 @@ dependencies:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
- description:
97
+ description:
84
98
  email:
85
99
  - gerrit.seger@gmail.com
86
100
  executables: []
@@ -101,14 +115,15 @@ files:
101
115
  - lib/firmenwissen/request/mock.rb
102
116
  - lib/firmenwissen/response/base.rb
103
117
  - lib/firmenwissen/response/mock.rb
118
+ - lib/firmenwissen/session.rb
104
119
  - lib/firmenwissen/suggestion.rb
105
120
  - lib/firmenwissen/uri_decorator.rb
106
121
  - lib/firmenwissen/version.rb
107
- homepage:
122
+ homepage:
108
123
  licenses:
109
124
  - MIT
110
125
  metadata: {}
111
- post_install_message:
126
+ post_install_message:
112
127
  rdoc_options: []
113
128
  require_paths:
114
129
  - lib
@@ -123,9 +138,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
138
  - !ruby/object:Gem::Version
124
139
  version: '0'
125
140
  requirements: []
126
- rubyforge_project:
127
- rubygems_version: 2.7.3
128
- signing_key:
141
+ rubygems_version: 3.0.3
142
+ signing_key:
129
143
  specification_version: 4
130
144
  summary: Ruby client for the FirmenWissen API
131
145
  test_files: []