hooks-ruby 0.0.4 → 0.0.5

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
  SHA256:
3
- metadata.gz: 2cab1bf1a1f61011d053be5beb9d48738bd439303b87743e41e10df0b4b9d65c
4
- data.tar.gz: 9b9abc62fff8f0f2f77ad94949bc7e067fff5a2f072bbf73f8e6e55c03865714
3
+ metadata.gz: 20afc330ce2c974fa7cb50950e261e0ed8bfb01a9e65aa615f1d1fc4aeff3b90
4
+ data.tar.gz: 2e561e403eab068f75cce3f41b48ba0642d4fd5f81124d9bea66d563f1472ff4
5
5
  SHA512:
6
- metadata.gz: 40f769a697bd61c6c851eef217fadc66387c49d37c19639a283dd770ca8be8889a13eeba2785a41c53edcdef29327231527405a9de21b2b4620416196da792c2
7
- data.tar.gz: 119a371d927f240aefe4e74c822b48318032250e7cbf060a9bd077b1375823137b419f7d1e2d27d775e6468d38843afb45ec9c8cd8a71a22d82226160c66043e
6
+ metadata.gz: 1152f3eef93d6c1d872b13dc59154584229f3bfed17a46c2cc748c0f8d1bd9847441dbe96ca2d084bdb6ed6f30077bcf0b49515c8e46bf668c355c8bdb5d52b0
7
+ data.tar.gz: '038523ad1ed72fc0f27fad4172a15b316c02d52b95936951a3f9f9efbdc2034dc074847665ee43524d7af93f6432ddd91c0ac97b2a0dbafa0f10deea8238fd67'
data/lib/hooks/app/api.rb CHANGED
@@ -105,10 +105,11 @@ module Hooks
105
105
  payload = parse_payload(raw_body, headers, symbolize: config[:symbolize_payload])
106
106
  handler = load_handler(handler_class_name)
107
107
  normalized_headers = config[:normalize_headers] ? Hooks::Utils::Normalize.headers(headers) : headers
108
+ symbolized_headers = config[:symbolize_headers] ? Hooks::Utils::Normalize.symbolize_headers(normalized_headers) : normalized_headers
108
109
 
109
110
  response = handler.call(
110
111
  payload:,
111
- headers: normalized_headers,
112
+ headers: symbolized_headers,
112
113
  config: endpoint_config
113
114
  )
114
115
 
@@ -21,7 +21,8 @@ module Hooks
21
21
  endpoints_dir: "./config/endpoints",
22
22
  use_catchall_route: false,
23
23
  symbolize_payload: true,
24
- normalize_headers: true
24
+ normalize_headers: true,
25
+ symbolize_headers: true
25
26
  }.freeze
26
27
 
27
28
  SILENCE_CONFIG_LOADER_MESSAGES = ENV.fetch(
@@ -143,6 +144,7 @@ module Hooks
143
144
  "HOOKS_USE_CATCHALL_ROUTE" => :use_catchall_route,
144
145
  "HOOKS_SYMBOLIZE_PAYLOAD" => :symbolize_payload,
145
146
  "HOOKS_NORMALIZE_HEADERS" => :normalize_headers,
147
+ "HOOKS_SYMBOLIZE_HEADERS" => :symbolize_headers,
146
148
  "HOOKS_SOME_STRING_VAR" => :some_string_var # Added for test
147
149
  }
148
150
 
@@ -154,7 +156,7 @@ module Hooks
154
156
  case config_key
155
157
  when :request_limit, :request_timeout
156
158
  env_config[config_key] = value.to_i
157
- when :use_catchall_route, :symbolize_payload, :normalize_headers
159
+ when :use_catchall_route, :symbolize_payload, :normalize_headers, :symbolize_headers
158
160
  # Convert string to boolean
159
161
  env_config[config_key] = %w[true 1 yes on].include?(value.downcase)
160
162
  else
@@ -15,8 +15,8 @@ module Hooks
15
15
  # Process a webhook request
16
16
  #
17
17
  # @param payload [Hash, String] Parsed request body (JSON Hash) or raw string
18
- # @param headers [Hash<String, String>] HTTP headers
19
- # @param config [Hash] Merged endpoint configuration including opts section
18
+ # @param headers [Hash] HTTP headers (symbolized keys by default)
19
+ # @param config [Hash] Merged endpoint configuration including opts section (symbolized keys)
20
20
  # @return [Hash, String, nil] Response body (will be auto-converted to JSON)
21
21
  # @raise [NotImplementedError] if not implemented by subclass
22
22
  def call(payload:, headers:, config:)
@@ -58,6 +58,39 @@ module Hooks
58
58
  normalized
59
59
  end
60
60
 
61
+ # Symbolize header keys in a hash
62
+ #
63
+ # @param headers [Hash, #each] Headers hash or hash-like object
64
+ # @return [Hash] Hash with symbolized keys (hyphens converted to underscores)
65
+ #
66
+ # @example Header symbolization
67
+ # headers = { "content-type" => "application/json", "x-github-event" => "push" }
68
+ # symbolized = Normalize.symbolize_headers(headers)
69
+ # # => { content_type: "application/json", x_github_event: "push" }
70
+ #
71
+ # @example Handle various input types
72
+ # Normalize.symbolize_headers(nil) # => nil
73
+ # Normalize.symbolize_headers({}) # => {}
74
+ def self.symbolize_headers(headers)
75
+ # Handle nil input
76
+ return nil if headers.nil?
77
+
78
+ # Fast path for non-enumerable inputs
79
+ return {} unless headers.respond_to?(:each)
80
+
81
+ symbolized = {}
82
+
83
+ headers.each do |key, value|
84
+ next if key.nil?
85
+
86
+ # Convert key to symbol, replacing hyphens with underscores
87
+ symbolized_key = key.to_s.tr("-", "_").to_sym
88
+ symbolized[symbolized_key] = value
89
+ end
90
+
91
+ symbolized
92
+ end
93
+
61
94
  # Normalize a single HTTP header name
62
95
  #
63
96
  # @param header [String] Header name to normalize
data/lib/hooks/version.rb CHANGED
@@ -4,5 +4,5 @@
4
4
  module Hooks
5
5
  # Current version of the Hooks webhook framework
6
6
  # @return [String] The version string following semantic versioning
7
- VERSION = "0.0.4".freeze
7
+ VERSION = "0.0.5".freeze
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hooks-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - github