castle-rb 3.0.1 → 3.1.0
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 -2
- data/lib/castle/client.rb +14 -7
- data/lib/castle/support/hanami.rb +1 -1
- data/lib/castle/support/padrino.rb +1 -1
- data/lib/castle/support/rails.rb +1 -1
- data/lib/castle/support/sinatra.rb +1 -1
- data/lib/castle/version.rb +1 -1
- data/spec/lib/castle/client_spec.rb +1 -1
- metadata +20 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40fd82599b83e0b0393c41de08d2be555909b5f3
|
4
|
+
data.tar.gz: b9bcfae0cf9eed03bb33ab81c0f1f3ca4a149c0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '07275877fa6fdf40f2451955444869f1f3c98f6ca7332edd1ee51b09d4f14da1f3c10cd53f06da70c4e0b65f646df33afcbe352f64720a52e26f677fe17318f1'
|
7
|
+
data.tar.gz: d3847b889ede27f92b4a06651e4c085f0f1ba7bab38012966ede3c5304b8b036beb41b7c8626e2bc4a68340f774140c55e7ac118d00c639796dbe291b39f871d
|
data/README.md
CHANGED
@@ -29,7 +29,7 @@ A Castle client instance will be made available as `castle` in your
|
|
29
29
|
|
30
30
|
* Sinatra app when you add `require 'castle/support/sinatra'` (and additionally explicitly add `register Sinatra::Castle` to your `Sinatra::Base` class if you have a modular application)
|
31
31
|
|
32
|
-
```
|
32
|
+
```ruby
|
33
33
|
require 'castle/support/sinatra'
|
34
34
|
|
35
35
|
class ApplicationController < Sinatra::Base
|
@@ -39,7 +39,7 @@ end
|
|
39
39
|
|
40
40
|
* Hanami when you add `require 'castle/support/hanami'` and include `Castle::Hanami` to your Hanami application
|
41
41
|
|
42
|
-
```
|
42
|
+
```ruby
|
43
43
|
require 'castle/support/hanami'
|
44
44
|
|
45
45
|
module Web
|
@@ -100,3 +100,37 @@ end
|
|
100
100
|
## Signature
|
101
101
|
|
102
102
|
`Castle::SecureMode.signature(user_id)` will create a signed user_id.
|
103
|
+
|
104
|
+
## Async tracking
|
105
|
+
|
106
|
+
By default Castle sends requests synchronously. To eg. use Sidekiq to send requests in a background worker you can pass data to the worker:
|
107
|
+
|
108
|
+
#### castle_tracking_worker.rb
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
class CastleTrackingWorker
|
112
|
+
include Sidekiq::Worker
|
113
|
+
|
114
|
+
def perform(context, track_options = {})
|
115
|
+
client = ::Castle::Client.new(context)
|
116
|
+
client.track(track_options)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
```
|
120
|
+
|
121
|
+
#### tracking_controller.rb
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
request_context = ::Castle::Client.to_context(request)
|
125
|
+
track_options = {
|
126
|
+
event: '$login.succeeded',
|
127
|
+
user_id: user.id,
|
128
|
+
properties: {
|
129
|
+
key: 'value'
|
130
|
+
},
|
131
|
+
traits: {
|
132
|
+
key: 'value'
|
133
|
+
}
|
134
|
+
}
|
135
|
+
CastleTrackingWorker.perform_async(request_context, track_options)
|
136
|
+
```
|
data/lib/castle/client.rb
CHANGED
@@ -2,11 +2,22 @@
|
|
2
2
|
|
3
3
|
module Castle
|
4
4
|
class Client
|
5
|
+
class << self
|
6
|
+
def from_request(request, options = {})
|
7
|
+
new(to_context(request, options), options[:do_not_track])
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_context(request, options = {})
|
11
|
+
default_context = Castle::DefaultContext.new(request, options[:cookies]).call
|
12
|
+
Castle::ContextMerger.new(default_context).call(options[:context] || {})
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
5
16
|
attr_accessor :api
|
6
17
|
|
7
|
-
def initialize(
|
8
|
-
@do_not_track =
|
9
|
-
@context =
|
18
|
+
def initialize(context, do_not_track = false)
|
19
|
+
@do_not_track = do_not_track
|
20
|
+
@context = context
|
10
21
|
@api = API.new
|
11
22
|
end
|
12
23
|
|
@@ -66,9 +77,5 @@ module Castle
|
|
66
77
|
return failover_response.generate unless Castle.config.failover_strategy == :throw
|
67
78
|
raise error
|
68
79
|
end
|
69
|
-
|
70
|
-
def default_tracking(options)
|
71
|
-
options.key?(:do_not_track) ? options[:do_not_track] : false
|
72
|
-
end
|
73
80
|
end
|
74
81
|
end
|
data/lib/castle/support/rails.rb
CHANGED
data/lib/castle/version.rb
CHANGED
@@ -11,7 +11,7 @@ describe Castle::Client do
|
|
11
11
|
)
|
12
12
|
end
|
13
13
|
let(:request) { Rack::Request.new(env) }
|
14
|
-
let(:client) { described_class.
|
14
|
+
let(:client) { described_class.from_request(request) }
|
15
15
|
let(:headers) { { 'X-Forwarded-For' => ip.to_s } }
|
16
16
|
let(:context) do
|
17
17
|
{
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: castle-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johan Brissmyr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Castle protects your users from account compromise
|
14
14
|
email: johan@castle.io
|
@@ -92,32 +92,32 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
version: '0'
|
93
93
|
requirements: []
|
94
94
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.6.
|
95
|
+
rubygems_version: 2.6.14
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: Castle
|
99
99
|
test_files:
|
100
|
-
- spec/
|
100
|
+
- spec/spec_helper.rb
|
101
|
+
- spec/lib/castle_spec.rb
|
102
|
+
- spec/lib/castle/review_spec.rb
|
101
103
|
- spec/lib/castle/client_spec.rb
|
102
|
-
- spec/lib/castle/
|
103
|
-
- spec/lib/castle/commands/authenticate_spec.rb
|
104
|
-
- spec/lib/castle/commands/identify_spec.rb
|
105
|
-
- spec/lib/castle/commands/review_spec.rb
|
106
|
-
- spec/lib/castle/commands/track_spec.rb
|
104
|
+
- spec/lib/castle/api_spec.rb
|
107
105
|
- spec/lib/castle/configuration_spec.rb
|
108
|
-
- spec/lib/castle/
|
106
|
+
- spec/lib/castle/version_spec.rb
|
109
107
|
- spec/lib/castle/default_context_spec.rb
|
110
|
-
- spec/lib/castle/extractors/client_id_spec.rb
|
111
|
-
- spec/lib/castle/extractors/headers_spec.rb
|
112
|
-
- spec/lib/castle/extractors/ip_spec.rb
|
113
108
|
- spec/lib/castle/header_formatter_spec.rb
|
114
|
-
- spec/lib/castle/request_spec.rb
|
115
|
-
- spec/lib/castle/response_spec.rb
|
116
|
-
- spec/lib/castle/review_spec.rb
|
117
|
-
- spec/lib/castle/secure_mode_spec.rb
|
118
109
|
- spec/lib/castle/utils/cloner_spec.rb
|
119
110
|
- spec/lib/castle/utils/merger_spec.rb
|
111
|
+
- spec/lib/castle/command_spec.rb
|
112
|
+
- spec/lib/castle/request_spec.rb
|
113
|
+
- spec/lib/castle/response_spec.rb
|
114
|
+
- spec/lib/castle/commands/review_spec.rb
|
115
|
+
- spec/lib/castle/commands/authenticate_spec.rb
|
116
|
+
- spec/lib/castle/commands/track_spec.rb
|
117
|
+
- spec/lib/castle/commands/identify_spec.rb
|
118
|
+
- spec/lib/castle/context_merger_spec.rb
|
119
|
+
- spec/lib/castle/extractors/ip_spec.rb
|
120
|
+
- spec/lib/castle/extractors/headers_spec.rb
|
121
|
+
- spec/lib/castle/extractors/client_id_spec.rb
|
120
122
|
- spec/lib/castle/utils_spec.rb
|
121
|
-
- spec/lib/castle/
|
122
|
-
- spec/lib/castle_spec.rb
|
123
|
-
- spec/spec_helper.rb
|
123
|
+
- spec/lib/castle/secure_mode_spec.rb
|