firmenwissen 1.0.0 → 1.0.1

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: 479f8a1bea375d5c4af1c8980981c1fc2f0d4d0bfe7c8b7ac60cf17821b76672
4
- data.tar.gz: e4aa6079c3be8d66819ff0d49e8f7c8fef9261c61f4b5353174c4227788593c2
3
+ metadata.gz: 6adfb097f5362cf6c61da4ab5a1b49501d8bb280c7686a8245478482156b2d5c
4
+ data.tar.gz: 65a1fc2c1a83192992aff5ed5345b596129e6cb233266f9a39878815833d5a97
5
5
  SHA512:
6
- metadata.gz: c877c1e82ffde13a74f956d72d94d5b7eb7106e27dabb66e377c40d7983076706a34276be83bb0c325d7fa3dde0b735f5164b62a86666c380e31d20851fb2acb
7
- data.tar.gz: '095e5255d2bb6c45cea6151bd5acafeba67fc07fa074db666c56e06c0c7c9748690bded252489748ed23c0f913c038af9e3e6be7a4258e02712735c96f2cbc5e'
6
+ metadata.gz: f5e6dc634c6a65a9bcb5913b7d854767b89f9378831897044cd36f5792bd451e17dbef4bfb28342e7b64a4c119bee46be78cc69ecab37d643046a96063bda084
7
+ data.tar.gz: ab9d35487f11cb5d1086d681d931322e17abbc6a55dd3d52017b30db72aa3518d97a6fa41f30990ca7747dd7fde8aefbc995b165a53931d4b6fe450cae022270
data/lib/firmenwissen.rb CHANGED
@@ -10,6 +10,7 @@ require 'firmenwissen/suggestion'
10
10
  require 'firmenwissen/version'
11
11
 
12
12
  require 'firmenwissen/errors/credentials_error'
13
+ require 'firmenwissen/errors/unprocessable_response_error'
13
14
 
14
15
  require 'firmenwissen/request/base'
15
16
  require 'firmenwissen/request/mock'
@@ -0,0 +1,7 @@
1
+ module Firmenwissen
2
+ class UnprocessableResponseError < RuntimeError
3
+ def initialize(message = 'The response from Firmenwissen could not be processed')
4
+ super
5
+ end
6
+ end
7
+ end
@@ -1,18 +1,17 @@
1
1
  module Firmenwissen
2
2
  module Response
3
3
  class Base
4
+ attr_reader :suggestions
5
+
4
6
  def initialize(http_response)
5
7
  @http_response = http_response
6
- end
7
-
8
- def suggestions
9
- @suggestions ||= data.map { |suggestion| Suggestion.new(suggestion) }
8
+ @suggestions = build_suggestions
10
9
  end
11
10
 
12
11
  def data
13
- api_response = JSON.parse(http_response.body).fetch('companyNameSuggestions', [])
14
-
15
- map_response(api_response)
12
+ @data ||= parsed_response.map { |hash| map_keys(hash) }
13
+ rescue JSON::ParserError
14
+ raise UnprocessableResponseError, "The response from Firmenwissen could not be processed:\n#{body}"
16
15
  end
17
16
 
18
17
  def status_code
@@ -27,10 +26,20 @@ module Firmenwissen
27
26
 
28
27
  attr_reader :http_response
29
28
 
30
- def map_response(api_response)
31
- api_response.map do |hash|
32
- KeyMapper.from_api(hash)
33
- end
29
+ def body
30
+ http_response.body
31
+ end
32
+
33
+ def build_suggestions
34
+ data.map { |suggestion| Suggestion.new(suggestion) }
35
+ end
36
+
37
+ def map_keys(hash)
38
+ KeyMapper.from_api(hash)
39
+ end
40
+
41
+ def parsed_response
42
+ JSON.parse(body).fetch('companyNameSuggestions', [])
34
43
  end
35
44
  end
36
45
  end
@@ -5,6 +5,7 @@ module Firmenwissen
5
5
  @mock_data = mock_data
6
6
  @query = query
7
7
  @params = params
8
+ @suggestions = build_suggestions
8
9
 
9
10
  raise ArgumentError, 'mock data must either be an array, a hash or respond to `call`' unless mock_data_valid?
10
11
  end
@@ -1,3 +1,3 @@
1
1
  module Firmenwissen
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
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.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerrit Seger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-30 00:00:00.000000000 Z
11
+ date: 2017-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -93,6 +93,7 @@ files:
93
93
  - lib/firmenwissen.rb
94
94
  - lib/firmenwissen/configuration.rb
95
95
  - lib/firmenwissen/errors/credentials_error.rb
96
+ - lib/firmenwissen/errors/unprocessable_response_error.rb
96
97
  - lib/firmenwissen/http_request.rb
97
98
  - lib/firmenwissen/key_mapper.rb
98
99
  - lib/firmenwissen/request.rb