castle-rb 3.4.0 → 3.4.1
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 +4 -4
- data/README.md +36 -24
- data/lib/castle.rb +5 -3
- data/lib/castle/client.rb +21 -18
- data/lib/castle/commands/authenticate.rb +8 -16
- data/lib/castle/commands/identify.rb +9 -21
- data/lib/castle/commands/impersonate.rb +9 -23
- data/lib/castle/commands/review.rb +5 -4
- data/lib/castle/commands/track.rb +8 -16
- data/lib/castle/configuration.rb +1 -2
- data/lib/castle/context/default.rb +40 -0
- data/lib/castle/context/merger.rb +14 -0
- data/lib/castle/context/sanitizer.rb +23 -0
- data/lib/castle/review.rb +1 -1
- data/lib/castle/utils/merger.rb +9 -9
- data/lib/castle/validators/not_supported.rb +16 -0
- data/lib/castle/validators/present.rb +16 -0
- data/lib/castle/version.rb +1 -1
- data/spec/lib/castle/client_spec.rb +3 -2
- data/spec/lib/castle/commands/authenticate_spec.rb +21 -21
- data/spec/lib/castle/commands/identify_spec.rb +17 -17
- data/spec/lib/castle/commands/impersonate_spec.rb +1 -1
- data/spec/lib/castle/commands/review_spec.rb +1 -1
- data/spec/lib/castle/commands/track_spec.rb +23 -23
- data/spec/lib/castle/configuration_spec.rb +13 -13
- data/spec/lib/castle/{default_context_spec.rb → context/default_spec.rb} +1 -1
- data/spec/lib/castle/{context_merger_spec.rb → context/merger_spec.rb} +4 -4
- data/spec/lib/castle/{context_sanitizer_spec.rb → context/sanitizer_spec.rb} +1 -1
- data/spec/lib/castle/extractors/client_id_spec.rb +1 -1
- data/spec/lib/castle/request_spec.rb +2 -2
- data/spec/lib/castle/response_spec.rb +4 -4
- data/spec/lib/castle/review_spec.rb +1 -1
- data/spec/lib/castle/utils_spec.rb +14 -14
- data/spec/lib/castle/validators/not_supported_spec.rb +26 -0
- data/spec/lib/castle/validators/present_spec.rb +33 -0
- data/spec/lib/castle_spec.rb +3 -3
- metadata +19 -13
- data/lib/castle/context_merger.rb +0 -12
- data/lib/castle/context_sanitizer.rb +0 -20
- data/lib/castle/default_context.rb +0 -28
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Castle
|
4
|
-
class ContextMerger
|
5
|
-
class << self
|
6
|
-
def call(initial_context, request_context)
|
7
|
-
main_context = Castle::Utils::Cloner.call(initial_context)
|
8
|
-
Castle::Utils::Merger.call(main_context, request_context || {})
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Castle
|
4
|
-
# removes not proper active flag values
|
5
|
-
class ContextSanitizer
|
6
|
-
class << self
|
7
|
-
def call(context)
|
8
|
-
sanitized_active_mode(context) || {}
|
9
|
-
end
|
10
|
-
|
11
|
-
private
|
12
|
-
|
13
|
-
def sanitized_active_mode(context)
|
14
|
-
return context unless context && context.key?(:active)
|
15
|
-
return context if [true, false].include?(context[:active])
|
16
|
-
context.reject { |key| key == :active }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Castle
|
4
|
-
class DefaultContext
|
5
|
-
def initialize(request, cookies = nil)
|
6
|
-
@client_id = Extractors::ClientId.new(request, cookies || request.cookies).call('__cid')
|
7
|
-
@headers = Extractors::Headers.new(request).call
|
8
|
-
@ip = Extractors::IP.new(request).call
|
9
|
-
end
|
10
|
-
|
11
|
-
def call
|
12
|
-
context = {
|
13
|
-
client_id: @client_id,
|
14
|
-
active: true,
|
15
|
-
origin: 'web',
|
16
|
-
headers: @headers || {},
|
17
|
-
ip: @ip,
|
18
|
-
library: {
|
19
|
-
name: 'castle-rb',
|
20
|
-
version: Castle::VERSION
|
21
|
-
}
|
22
|
-
}
|
23
|
-
context[:locale] = @headers['Accept-Language'] if @headers['Accept-Language']
|
24
|
-
context[:user_agent] = @headers['User-Agent'] if @headers['User-Agent']
|
25
|
-
context
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|