castle-rb 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c80e0f6121cdd9c4b914d5dee3e497a72ed7b8a3
4
- data.tar.gz: a2e9b71846f87d339c715682f29aabe40fe8acc3
3
+ metadata.gz: cf802329a5b427cc2b979f02931c572601397506
4
+ data.tar.gz: 58746daf7163fe23e054261b1b52a44e918b7074
5
5
  SHA512:
6
- metadata.gz: fce99899d97c33bc764d2d86c95613e715122fff126aed50f8a81dc0eb41e7cf169c44e2ef3553e61771b67cb5bb1ad5f1a0e7ef30c3252333a9ae131f49bc4d
7
- data.tar.gz: b62455350a0c8b2de21b257ea83b908526277f66205d104636b1d56d2e8f146956dfe6d8e85201fca00d3ca7e2d584db7d6f7c638e62ff613ba50d58d11dfb5c
6
+ metadata.gz: 16c66f7e9c363791316aa12aac26ab42f77770929ce8fca7732b2fdf26e3cf4c8efb304bd8b6683f34c9d31ff74e4b01e88ff4efa44caf7e11d4854c89c35760
7
+ data.tar.gz: 1287a6ac045069c0ef795c4764c8e1235c04dcf0a7b8a696d3e88c499f815cd3f112f1bad848580006c55d7ffdb80ee5d25e3477616f8e7ede2c98dbda5f1ef2
@@ -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
- req = Net::HTTP::Post.new(
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)
@@ -10,6 +10,10 @@ module Castle
10
10
  @api = API.new(cookie_id, ip, headers)
11
11
  end
12
12
 
13
+ def fetch_review(id)
14
+ @api.request("reviews/#{id}", nil, method: :get)
15
+ end
16
+
13
17
  def identify(args)
14
18
  @api.request('identify', args) unless do_not_track?
15
19
  end
@@ -1,3 +1,3 @@
1
1
  module Castle
2
- VERSION = "2.1.0"
2
+ VERSION = "2.2.0"
3
3
  end
@@ -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 {
@@ -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
- it 'parses the request' do
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
- req = Request.new(env)
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(req, nil)
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.1.0
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-01-23 00:00:00.000000000 Z
11
+ date: 2017-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry