castle-rb 2.1.0 → 2.2.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/lib/castle-rb/api.rb +4 -3
- data/lib/castle-rb/client.rb +4 -0
- data/lib/castle-rb/version.rb +1 -1
- data/spec/api_spec.rb +0 -12
- data/spec/client_spec.rb +36 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf802329a5b427cc2b979f02931c572601397506
|
4
|
+
data.tar.gz: 58746daf7163fe23e054261b1b52a44e918b7074
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16c66f7e9c363791316aa12aac26ab42f77770929ce8fca7732b2fdf26e3cf4c8efb304bd8b6683f34c9d31ff74e4b01e88ff4efa44caf7e11d4854c89c35760
|
7
|
+
data.tar.gz: 1287a6ac045069c0ef795c4764c8e1235c04dcf0a7b8a696d3e88c499f815cd3f112f1bad848580006c55d7ffdb80ee5d25e3477616f8e7ede2c98dbda5f1ef2
|
data/lib/castle-rb/api.rb
CHANGED
@@ -26,11 +26,12 @@ module Castle
|
|
26
26
|
@headers.delete_if { |k, v| v.nil? }
|
27
27
|
end
|
28
28
|
|
29
|
-
def request(endpoint, args)
|
30
|
-
|
29
|
+
def request(endpoint, args, method: :post)
|
30
|
+
http_method = method.to_s.capitalize
|
31
|
+
req = Net::HTTP.const_get(http_method).new(
|
31
32
|
"#{Castle.config.api_endpoint.path}/#{endpoint}", @headers)
|
32
33
|
req.basic_auth("", Castle.config.api_secret)
|
33
|
-
req.body = args.to_json
|
34
|
+
req.body = args.to_json unless http_method == 'Get'
|
34
35
|
|
35
36
|
begin
|
36
37
|
response = @http.request(req)
|
data/lib/castle-rb/client.rb
CHANGED
data/lib/castle-rb/version.rb
CHANGED
data/spec/api_spec.rb
CHANGED
@@ -3,18 +3,6 @@ require 'spec_helper'
|
|
3
3
|
describe Castle::API do
|
4
4
|
let(:api) { Castle::API.new('abcd', '1.2.3.4', '{}') }
|
5
5
|
|
6
|
-
it 'identifies' do
|
7
|
-
api.request('identify', user_id: '1234', traits: { name: 'Jo' })
|
8
|
-
assert_requested :post, 'https://:secret@api.castle.io/v1/identify',
|
9
|
-
times: 1
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'authenticates' do
|
13
|
-
api.request('authenticate', user_id: '1234')
|
14
|
-
assert_requested :post, 'https://:secret@api.castle.io/v1/authenticate',
|
15
|
-
times: 1
|
16
|
-
end
|
17
|
-
|
18
6
|
it 'handles timeout' do
|
19
7
|
stub_request(:any, /api.castle.io/).to_timeout
|
20
8
|
expect {
|
data/spec/client_spec.rb
CHANGED
@@ -7,18 +7,49 @@ end
|
|
7
7
|
describe Castle::Client do
|
8
8
|
let(:ip) {'1.2.3.4' }
|
9
9
|
let(:cookie_id) { 'abcd' }
|
10
|
-
|
11
|
-
|
12
|
-
env = Rack::MockRequest.env_for('/',
|
10
|
+
let(:env) do
|
11
|
+
Rack::MockRequest.env_for('/',
|
13
12
|
'HTTP_X_FORWARDED_FOR' => '1.2.3.4',
|
14
13
|
'HTTP_COOKIE' => "__cid=#{cookie_id};other=efgh"
|
15
14
|
)
|
16
|
-
|
15
|
+
end
|
16
|
+
let(:request) { Request.new(env) }
|
17
|
+
let(:client) { Castle::Client.new(request, nil) }
|
18
|
+
let(:review_id) { '12356789' }
|
17
19
|
|
20
|
+
it 'parses the request' do
|
18
21
|
expect(Castle::API).to receive(:new).with(cookie_id, ip,
|
19
22
|
"{\"X-Forwarded-For\":\"#{ip}\"}").and_call_original
|
20
23
|
|
21
|
-
client = Castle::Client.new(
|
24
|
+
client = Castle::Client.new(request, nil)
|
22
25
|
client.authenticate({name: '$login.succeeded', user_id: '1234'})
|
23
26
|
end
|
27
|
+
|
28
|
+
it 'identifies' do
|
29
|
+
client.identify( user_id: '1234', traits: { name: 'Jo' })
|
30
|
+
assert_requested :post, 'https://:secret@api.castle.io/v1/identify',
|
31
|
+
times: 1,
|
32
|
+
body: { user_id: '1234', traits: { name: 'Jo' } }
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'authenticates' do
|
36
|
+
client.authenticate(name: '$login.succeeded', user_id: '1234')
|
37
|
+
assert_requested :post, 'https://:secret@api.castle.io/v1/authenticate',
|
38
|
+
times: 1,
|
39
|
+
body: { name: '$login.succeeded', user_id: "1234" }
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'tracks' do
|
43
|
+
client.track(name: '$login.succeeded', user_id: '1234')
|
44
|
+
assert_requested :post, 'https://:secret@api.castle.io/v1/track',
|
45
|
+
times: 1,
|
46
|
+
body: { name: '$login.succeeded', user_id: "1234" }
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'fetches review' do
|
50
|
+
client.fetch_review(review_id)
|
51
|
+
|
52
|
+
assert_requested :get, "https://:secret@api.castle.io/v1/reviews/#{review_id}",
|
53
|
+
times: 1
|
54
|
+
end
|
24
55
|
end
|
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: 2.
|
4
|
+
version: 2.2.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-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|