hawkei 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +48 -0
  5. data/.ruby-version +1 -0
  6. data/.tool-versions +1 -0
  7. data/.travis.yml +11 -0
  8. data/Gemfile +12 -0
  9. data/LICENCE +21 -0
  10. data/Makefile +9 -0
  11. data/README.md +17 -0
  12. data/Rakefile +4 -0
  13. data/hawkei.gemspec +28 -0
  14. data/lib/hawkei/api_operation/delete.rb +38 -0
  15. data/lib/hawkei/api_operation/save.rb +57 -0
  16. data/lib/hawkei/api_resource.rb +130 -0
  17. data/lib/hawkei/batch.rb +18 -0
  18. data/lib/hawkei/config.rb +123 -0
  19. data/lib/hawkei/errors.rb +41 -0
  20. data/lib/hawkei/formated_logger.rb +45 -0
  21. data/lib/hawkei/hawkei_object.rb +179 -0
  22. data/lib/hawkei/library_name.rb +3 -0
  23. data/lib/hawkei/message.rb +79 -0
  24. data/lib/hawkei/plugins/rack/middleware.rb +139 -0
  25. data/lib/hawkei/plugins/rails/data.rb +19 -0
  26. data/lib/hawkei/plugins/rails/middleware_data.rb +28 -0
  27. data/lib/hawkei/plugins/rails/railtie.rb +23 -0
  28. data/lib/hawkei/plugins/sidekiq/client_middleware.rb +19 -0
  29. data/lib/hawkei/plugins/sidekiq/load.rb +14 -0
  30. data/lib/hawkei/plugins/sidekiq/server_middleware.rb +48 -0
  31. data/lib/hawkei/plugins.rb +17 -0
  32. data/lib/hawkei/processor/async.rb +50 -0
  33. data/lib/hawkei/processor/batch.rb +84 -0
  34. data/lib/hawkei/processor/worker.rb +113 -0
  35. data/lib/hawkei/request.rb +134 -0
  36. data/lib/hawkei/store.rb +49 -0
  37. data/lib/hawkei/util.rb +180 -0
  38. data/lib/hawkei/version.rb +3 -0
  39. data/lib/hawkei/watcher.rb +15 -0
  40. data/lib/hawkei.rb +170 -0
  41. data/spec/lib/hawkei/api_resource_spec.rb +109 -0
  42. data/spec/lib/hawkei/batch_spec.rb +14 -0
  43. data/spec/lib/hawkei/config_spec.rb +36 -0
  44. data/spec/lib/hawkei/formated_logger_spec.rb +99 -0
  45. data/spec/lib/hawkei/hawkei_object_spec.rb +123 -0
  46. data/spec/lib/hawkei/message_spec.rb +178 -0
  47. data/spec/lib/hawkei/plugins/rack/middleware_spec.rb +88 -0
  48. data/spec/lib/hawkei/plugins/rails/data_spec.rb +22 -0
  49. data/spec/lib/hawkei/plugins/rails/middleware_data_spec.rb +46 -0
  50. data/spec/lib/hawkei/plugins/sidekiq/client_middleware_spec.rb +15 -0
  51. data/spec/lib/hawkei/plugins/sidekiq/server_middleware_spec.rb +58 -0
  52. data/spec/lib/hawkei/processor/async_spec.rb +36 -0
  53. data/spec/lib/hawkei/processor/batch_spec.rb +51 -0
  54. data/spec/lib/hawkei/processor/worker_spec.rb +100 -0
  55. data/spec/lib/hawkei/store_spec.rb +82 -0
  56. data/spec/lib/hawkei/util_spec.rb +132 -0
  57. data/spec/lib/hawkei/watcher_spec.rb +25 -0
  58. data/spec/lib/hawkei_spec.rb +175 -0
  59. data/spec/spec_helper.rb +33 -0
  60. data/spec/support/rack_app.rb +12 -0
  61. metadata +206 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 519333f18c5cd49c3f527ccdcd32aab016ed0cab420b34fd6beea68846894da0
4
+ data.tar.gz: 3ab8e90d94b056ea8c9e9193de8d43111263628e0c0435d4f12fb897af0e7831
5
+ SHA512:
6
+ metadata.gz: da169662f01c97bfadb06c1058803e6f63e9036301c94b7bf90a6728a24cc2c7b29368b97f706b791989554b3b916822d404c169560cf64e3f30041d3ad8e9ea
7
+ data.tar.gz: ea4d6c964a1620361e7cfcbd5692a88d5f20cbb72494d13e637a08534d077822633517072c34240ea41da72d857fa9f5057030e525a4ed0643bae704306e647b
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ doc
2
+ *.gem
3
+ Gemfile.lock
4
+ todo.md
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,48 @@
1
+ Metrics/AbcSize:
2
+ Max: 24
3
+ Metrics/LineLength:
4
+ Max: 120
5
+ Metrics/ClassLength:
6
+ CountComments: false
7
+ Max: 120
8
+ Metrics/MethodLength:
9
+ CountComments: false
10
+ Max: 20
11
+ Metrics/CyclomaticComplexity:
12
+ Max: 7
13
+ Metrics/ModuleLength:
14
+ Enabled: false
15
+
16
+ Layout/EmptyLinesAroundClassBody:
17
+ Enabled: false
18
+ Layout/EmptyLinesAroundModuleBody:
19
+ Enabled: false
20
+ Layout/EmptyLinesAroundBlockBody:
21
+ Enabled: false
22
+
23
+ Style/FrozenStringLiteralComment:
24
+ Enabled: false
25
+ Style/MissingRespondToMissing:
26
+ Enabled: false
27
+ Style/TrailingCommaInHashLiteral:
28
+ EnforcedStyleForMultiline: comma
29
+ Style/TrailingCommaInArrayLiteral:
30
+ EnforcedStyleForMultiline: comma
31
+ Style/TrailingCommaInArguments:
32
+ Enabled: false
33
+
34
+ Documentation:
35
+ Enabled: false
36
+
37
+ Bundler/DuplicatedGem:
38
+ Enabled: false
39
+
40
+ AllCops:
41
+ TargetRubyVersion: 2.2
42
+ Exclude:
43
+ - 'spec/**/*'
44
+ Exclude:
45
+ - bin/**/*
46
+ - vendor/**/*
47
+ - tmp/**/*
48
+ - spec/**/*
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.3
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 2.6.3
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ cache: bundler
2
+ language: ruby
3
+ rvm:
4
+ - 2.2
5
+ - 2.3
6
+ - 2.4
7
+ - 2.5
8
+ - 2.6
9
+ script:
10
+ - make test
11
+ - make lint
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ if RUBY_VERSION > '2.1.0' && RUBY_VERSION < '2.2.2'
4
+ gem 'sidekiq', '>= 2.13.0', '< 5.0'
5
+ else
6
+ gem 'sidekiq', '>= 2.13.0'
7
+ end
8
+
9
+ gem 'rack'
10
+ gem 'rails'
11
+
12
+ gemspec
data/LICENCE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2019- hawkei-io Pty Ltd. (https://hawkei.io)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/Makefile ADDED
@@ -0,0 +1,9 @@
1
+ export FORCE_COLOR = true
2
+
3
+ .PHONY: lint test
4
+
5
+ test:
6
+ @bundle exec rspec spec/
7
+
8
+ lint:
9
+ @bundle exec rubocop .
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # Hawkei
2
+
3
+ [Hawkei](https://hawkei.io) Ruby library
4
+
5
+ Interact easily with our API using our Ruby library.
6
+
7
+ [![Build Status](https://travis-ci.org/hawkei-io/hawkei-ruby.svg?branch=master)](https://travis-ci.org/hawkei-io/hawkei-ruby)
8
+
9
+ ## Setup
10
+
11
+ - [Start by creating an account](https://app.hawkei.io/registration)
12
+ - Follow the [Quick Start Guide](https://hawkei.atlassian.net/wiki/spaces/HAW/pages/4915206/Getting+started+in+4+steps) to get set up
13
+ - Use our [Ruby Library](https://hawkei.atlassian.net/wiki/spaces/HAW/pages/7110690/Ruby) to install and configure Hawkei for your platform.
14
+
15
+ ## Documentation & Usage
16
+
17
+ Documentation is available at [hawkei.atlassian.net/wiki/spaces/HAW/pages/7110690/Ruby](https://hawkei.atlassian.net/wiki/spaces/HAW/pages/7110690/Ruby)
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'rspec/core/rake_task'
2
+ RSpec::Core::RakeTask.new(:spec)
3
+
4
+ task default: :spec
data/hawkei.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'hawkei/version'
4
+ require 'hawkei/library_name'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = Hawkei::LIBRARY_NAME
8
+ s.version = Hawkei::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ['Hawkei']
11
+ s.email = ['support@hawkei.io']
12
+ s.homepage = 'https://github.com/hawkei-io/hawkei-ruby'
13
+ s.summary = 'Hawkei ruby integration'
14
+ s.description = 'Hawkei ruby integration'
15
+
16
+ s.license = 'MIT'
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- spec/*`.split("\n")
20
+
21
+ s.add_dependency 'concurrent-ruby', '~> 1.1.3'
22
+
23
+ s.add_development_dependency 'faker', '~> 1.9.1'
24
+ s.add_development_dependency 'pry'
25
+ s.add_development_dependency 'rake', '>= 0.9.0'
26
+ s.add_development_dependency 'rspec', '~> 3.8'
27
+ s.add_development_dependency 'rubocop', '= 0.61.1'
28
+ end
@@ -0,0 +1,38 @@
1
+ module Hawkei
2
+ class APIOperation
3
+ ##
4
+ # == Delete a resource for the API
5
+ #
6
+ module Delete
7
+ module ClassMethods
8
+ ##
9
+ # Delete an API Resource
10
+ #
11
+ # @param [String] id for the request
12
+ # @param [Hash] Additional options for the request
13
+ #
14
+ # @return [Hawkei::Object] response from the API
15
+ def delete(id, options = {})
16
+ response = request(:delete, "#{resource_path}/#{id}", options)
17
+ initialize_from(response)
18
+ end
19
+ end
20
+
21
+ ##
22
+ # Delete an API Resources
23
+ #
24
+ # @param [Hash] Additional options for the request
25
+ #
26
+ # @return [Hawkei::Object] response from the API
27
+ def destroy(options = {})
28
+ response = request(:delete, "#{resource_path}/#{id}", {}, options)
29
+ update_from(response)
30
+ end
31
+
32
+ def self.included(base)
33
+ base.extend(ClassMethods)
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,57 @@
1
+ module Hawkei
2
+ class APIOperation
3
+ ##
4
+ # == Save (create or update) a resource for the API
5
+ #
6
+ module Save
7
+ module ClassMethods
8
+ ##
9
+ # Create an API Resource and validate the params for the API.
10
+ #
11
+ # @param [Hash] params for the request
12
+ # @param [Hash] Additional options for the request
13
+ #
14
+ # @return [Hawkei::Object] response from the API
15
+ def create(params = {}, options = {})
16
+ response = request(:post, resource_path, params, options)
17
+ initialize_from(response)
18
+ end
19
+
20
+ ##
21
+ # Update an API Resource and validate params for the API
22
+ #
23
+ # @param [String] id for the request
24
+ # @param [Hash] params for the request
25
+ # @param [Hash] Additional options for the request
26
+ #
27
+ # @return [Hawkei::Object] response from the API
28
+ def update(id, params = {}, options = {})
29
+ response = request(:put, "#{resource_path}/#{id}", params, options)
30
+ initialize_from(response)
31
+ end
32
+
33
+ end
34
+
35
+ ##
36
+ # Create or Update an API Resource
37
+ #
38
+ # @param [Hash] params for the request
39
+ # @param [Hash] Additional options for the request
40
+ #
41
+ # @return [Hawkei::Object] response from the API
42
+ def save(params = {}, options = {})
43
+ path = singleton_methods.include?(:id) ? "#{resource_path}/#{id}" : resource_path
44
+ method = singleton_methods.include?(:id) ? :put : :post
45
+
46
+ response = request(method, path, to_hash.merge(params), options)
47
+ update_from(response)
48
+ end
49
+ alias update save
50
+
51
+ def self.included(base)
52
+ base.extend(ClassMethods)
53
+ end
54
+
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,130 @@
1
+ module Hawkei
2
+ ##
3
+ # == Hawkei \API \Resource
4
+ #
5
+ # Define the API requests methods
6
+ class APIResource < HawkeiObject
7
+ ##
8
+ # @return [String] resource name
9
+ def resource_name
10
+ self.class.resource_name
11
+ end
12
+
13
+ ##
14
+ # @return [String] resource path
15
+ def resource_path(path = nil)
16
+ self.class.resource_path(path)
17
+ end
18
+
19
+ ##
20
+ # Send a request to the API
21
+ #
22
+ # @param [Symbol] method for the request
23
+ # @param [String] endpoint for the request
24
+ # @param [Hash] options
25
+ # @param [Hash] Payload
26
+ #
27
+ # @return [Hash] response
28
+ # @raise [Hawkei::RequestError] if the request is invalid
29
+ def request(method, resource_path, payload = {}, options = {})
30
+ self.class.request(method, resource_path, payload, options)
31
+ end
32
+
33
+ class << self
34
+
35
+ ##
36
+ # @return [String] resource path
37
+ def resource_path(path = nil)
38
+ "/api/#{configurations.api_version}/#{path || @resource_name || CGI.escape(resource_name)}"
39
+ end
40
+
41
+ ##
42
+ # @return [String] resource name
43
+ def resource_name
44
+ Util.underscore("#{class_name}s")
45
+ end
46
+
47
+ ##
48
+ # @return [String] the class name
49
+ def class_name
50
+ name.split('::')[-1]
51
+ end
52
+
53
+ ##
54
+ # Send a request to the API
55
+ #
56
+ # @param [Symbol] method for the request
57
+ # @param [String] endpoint for the request
58
+ # @param [Hash] options
59
+ # @param [Hash] Payload
60
+ #
61
+ # @return [Hash] response
62
+ # @raise [Hawkei::RequestError] if the request is invalid
63
+ # rubocop:disable Metrics/AbcSize
64
+ def request(method, path, payload = {}, options = {})
65
+ payload[:sent_at] = Time.now.utc.iso8601(3)
66
+ payload = Util.deep_obfuscate_value(payload, configurations.obfuscated_fields)
67
+ url_params = Util.encode_parameters(payload) if method == :get
68
+ uri = build_endpoint_url(path, url_params)
69
+
70
+ request_options = Util.compact(
71
+ method: method,
72
+ url: uri.to_s,
73
+ payload: payload.to_json,
74
+ proxy: configurations.proxy_url,
75
+ use_ssl: configurations.http_secure
76
+ ).merge(headers(options)).merge(options)
77
+
78
+ Request.execute(request_options).body
79
+ rescue Hawkei::RequestError => error
80
+ return error.http_body if error.http_status == 422
81
+
82
+ raise
83
+ end
84
+ # rubocop:enable Metrics/AbcSize
85
+
86
+ private
87
+
88
+ def build_endpoint_url(path, params = nil)
89
+ host, port = configurations.api_host.split(':')
90
+ port = port.to_i if port
91
+
92
+ url_params = Util.compact(
93
+ host: host,
94
+ path: path,
95
+ port: port,
96
+ query: params
97
+ )
98
+
99
+ return URI::HTTPS.build(url_params) if configurations.http_secure
100
+
101
+ URI::HTTP.build(url_params)
102
+ end
103
+
104
+ def ssl_options
105
+ return {} unless configurations.http_secure
106
+
107
+ {
108
+ verify_mode: OpenSSL::SSL::VERIFY_PEER,
109
+ }
110
+ end
111
+
112
+ def headers(options)
113
+ {
114
+ headers: {
115
+ accept: 'application/json',
116
+ content_type: 'application/json',
117
+ x_api_key: options.delete(:api_key) || configurations.api_key,
118
+ x_space_name: options.delete(:space_name) || configurations.space_name,
119
+ x_environment_name: options.delete(:environment_name) || configurations.environment_name,
120
+ },
121
+ }
122
+ end
123
+
124
+ def configurations
125
+ Hawkei.configurations
126
+ end
127
+
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,18 @@
1
+ module Hawkei
2
+ ##
3
+ # == Hawkei \Batch
4
+ #
5
+ # Accepted Methods:
6
+ #
7
+ # * create
8
+ #
9
+ # @example: Usage
10
+ #
11
+ # request = Hawkei::Batch.create(...) #=> #<Hawkei::Response...>
12
+ #
13
+ class Batch < APIResource
14
+ @resource_name = 'batches'
15
+
16
+ include Hawkei::APIOperation::Save
17
+ end
18
+ end
@@ -0,0 +1,123 @@
1
+ module Hawkei
2
+ ##
3
+ # == Hawkei \Config
4
+ #
5
+ # Represent the Hawkei configuration for the API
6
+ class Config
7
+
8
+ DEFAULT_OBFUSCATED_FIELDS = %w[
9
+ password
10
+ password_confirmation
11
+ secret
12
+ secret_token
13
+ authenticity_token
14
+ token
15
+ api_key
16
+ access_token
17
+ credit_card_number
18
+ cvv
19
+ ccv
20
+ ].freeze
21
+
22
+ ##
23
+ # @return [String] API account token
24
+ attr_accessor :api_key
25
+
26
+ ##
27
+ # @return [String] API space name
28
+ attr_accessor :space_name
29
+
30
+ ##
31
+ # @return [String] API environment name
32
+ attr_accessor :environment_name
33
+
34
+ ##
35
+ # @return [String] API host
36
+ attr_accessor :api_host
37
+
38
+ ##
39
+ # @return [String] API version
40
+ attr_accessor :api_version
41
+
42
+ ##
43
+ # @return [String] proxy url
44
+ attr_accessor :proxy_url
45
+
46
+ ##
47
+ # @return [Boolean] http secure
48
+ attr_accessor :http_secure
49
+
50
+ ##
51
+ # @return [Boolean] service is enable
52
+ attr_accessor :enabled
53
+
54
+ ##
55
+ # @return [Array[String]] fields to obfuscate
56
+ attr_accessor :obfuscated_fields
57
+
58
+ ##
59
+ # @return [Hash] metadata to be attach to the payload
60
+ attr_accessor :metadata
61
+
62
+ ##
63
+ # @return [Boolean] enable the logger
64
+ attr_accessor :log
65
+
66
+ ##
67
+ # @return [Logger] logger
68
+ attr_accessor :logger
69
+
70
+ ##
71
+ # @return [String] domain
72
+ attr_accessor :domain
73
+
74
+ ##
75
+ # @param [Hash{Symbol=>Object}]
76
+ # Initialize and validate the configuration
77
+ def initialize(options = {})
78
+ self.api_key = options[:api_key]
79
+ self.space_name = options[:space_name]
80
+ self.environment_name = options[:environment_name]
81
+ self.api_host = options[:api_host] || 'api.hawkei.io'
82
+ self.api_version = options[:api_version] || 'v1'
83
+ self.proxy_url = options[:proxy_url]
84
+ self.http_secure = options[:http_secure] || true
85
+ self.enabled = options[:enabled] || true
86
+ self.obfuscated_fields = options[:obfuscated_fields] || []
87
+ self.metadata = options[:metadata]
88
+ self.log = options[:log] || true
89
+ self.logger = FormatedLogger.build(options[:logger])
90
+ self.domain = options[:domain]
91
+ end
92
+
93
+ ##
94
+ # validate the configuration
95
+ # Raise when configuration are not valid
96
+ # @return [Boolean] true
97
+ def valid!
98
+ format!
99
+
100
+ %i[api_key space_name environment_name api_host api_version].each do |field|
101
+ validate_presence(field)
102
+ end
103
+
104
+ true
105
+ end
106
+
107
+ private
108
+
109
+ ##
110
+ # Format configuration fields
111
+ #
112
+ # * Set obfuscated_fields to string
113
+ #
114
+ def format!
115
+ self.obfuscated_fields = (obfuscated_fields.map(&:to_s) + DEFAULT_OBFUSCATED_FIELDS).uniq
116
+ end
117
+
118
+ def validate_presence(field)
119
+ raise Hawkei::ConfigurationError, "#{field} can't be blank" if send(field).nil? || send(field).empty?
120
+ end
121
+
122
+ end
123
+ end
@@ -0,0 +1,41 @@
1
+ module Hawkei
2
+
3
+ ##
4
+ # Configuration Error
5
+ class ConfigurationError < StandardError; end
6
+
7
+ ##
8
+ # Missing Implementation Error
9
+ class MissingImplementation < StandardError; end
10
+
11
+ ##
12
+ # Request to API Error
13
+ class RequestError < StandardError; end
14
+
15
+ ##
16
+ # Method unknown for the request
17
+ class UnknownRequestMethod < StandardError; end
18
+
19
+ ##
20
+ # Request to API Error
21
+ class RequestError < StandardError
22
+
23
+ attr_reader :http_body
24
+ attr_reader :http_status
25
+ attr_reader :http_status_type
26
+ attr_reader :http_message
27
+
28
+ def initialize(response, message: nil)
29
+ @http_status = response.code.to_i
30
+ @http_status_type = response.code_type
31
+ @http_body = response.body
32
+ @http_message = message || response.message
33
+ end
34
+
35
+ def to_s
36
+ "Status #{http_status}: #{http_message}"
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,45 @@
1
+ module Hawkei
2
+ ##
3
+ # Display formated log
4
+ class FormatedLogger
5
+
6
+ class << self
7
+
8
+ def build(logger)
9
+ return new(logger) if logger
10
+ return new(Rails.logger) if defined?(Rails)
11
+
12
+ new(::Logger.new(STDOUT))
13
+ end
14
+
15
+ end
16
+
17
+ attr_reader :logger
18
+
19
+ PREFIX = '[Hawkei]'.freeze
20
+ METHODS = %i[debug info warn error].freeze
21
+
22
+ def initialize(logger)
23
+ @logger = logger
24
+ end
25
+
26
+ METHODS.each do |method|
27
+ define_method(method) do |message|
28
+ log(method, message)
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def log(type, message)
35
+ return unless configurations.log
36
+
37
+ logger.send(type, "#{PREFIX} #{message}")
38
+ end
39
+
40
+ def configurations
41
+ Hawkei.configurations
42
+ end
43
+
44
+ end
45
+ end