castle-rb 8.0.0 → 8.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/castle/api/list_items/archive.rb +23 -0
- data/lib/castle/api/list_items/count.rb +22 -0
- data/lib/castle/api/list_items/create.rb +22 -0
- data/lib/castle/api/list_items/get.rb +22 -0
- data/lib/castle/api/list_items/query.rb +22 -0
- data/lib/castle/api/list_items/unarchive.rb +22 -0
- data/lib/castle/api/list_items/update.rb +22 -0
- data/lib/castle/api/lists/create.rb +23 -0
- data/lib/castle/api/lists/delete.rb +22 -0
- data/lib/castle/api/lists/get.rb +22 -0
- data/lib/castle/api/lists/get_all.rb +22 -0
- data/lib/castle/api/lists/query.rb +22 -0
- data/lib/castle/api/lists/update.rb +22 -0
- data/lib/castle/client.rb +3 -0
- data/lib/castle/client_actions/list_items.rb +44 -0
- data/lib/castle/client_actions/lists.rb +39 -0
- data/lib/castle/commands/list_items/archive.rb +24 -0
- data/lib/castle/commands/list_items/count.rb +23 -0
- data/lib/castle/commands/list_items/create.rb +22 -0
- data/lib/castle/commands/list_items/get.rb +23 -0
- data/lib/castle/commands/list_items/query.rb +24 -0
- data/lib/castle/commands/list_items/unarchive.rb +23 -0
- data/lib/castle/commands/list_items/update.rb +22 -0
- data/lib/castle/commands/lists/create.rb +21 -0
- data/lib/castle/commands/lists/delete.rb +20 -0
- data/lib/castle/commands/lists/get.rb +20 -0
- data/lib/castle/commands/lists/get_all.rb +17 -0
- data/lib/castle/commands/lists/query.rb +21 -0
- data/lib/castle/commands/lists/update.rb +22 -0
- data/lib/castle/version.rb +1 -1
- data/lib/castle.rb +28 -0
- data/spec/lib/castle/api/approve_device_spec.rb +1 -1
- data/spec/lib/castle/api/authenticate_spec.rb +1 -1
- data/spec/lib/castle/api/end_impersonation_spec.rb +1 -1
- data/spec/lib/castle/api/filter_spec.rb +1 -1
- data/spec/lib/castle/api/get_device_spec.rb +1 -1
- data/spec/lib/castle/api/get_devices_for_user_spec.rb +1 -1
- data/spec/lib/castle/api/list_items/archive_spec.rb +18 -0
- data/spec/lib/castle/api/list_items/count_spec.rb +21 -0
- data/spec/lib/castle/api/list_items/create_spec.rb +22 -0
- data/spec/lib/castle/api/list_items/get_spec.rb +18 -0
- data/spec/lib/castle/api/list_items/query_spec.rb +21 -0
- data/spec/lib/castle/api/list_items/unarchive_spec.rb +18 -0
- data/spec/lib/castle/api/list_items/update_spec.rb +22 -0
- data/spec/lib/castle/api/lists/create_spec.rb +21 -0
- data/spec/lib/castle/api/lists/delete_spec.rb +17 -0
- data/spec/lib/castle/api/lists/get_all_spec.rb +17 -0
- data/spec/lib/castle/api/lists/get_spec.rb +17 -0
- data/spec/lib/castle/api/lists/query_spec.rb +21 -0
- data/spec/lib/castle/api/lists/update_spec.rb +21 -0
- data/spec/lib/castle/api/log_spec.rb +1 -1
- data/spec/lib/castle/api/report_device_spec.rb +1 -1
- data/spec/lib/castle/api/risk_spec.rb +1 -1
- data/spec/lib/castle/api/start_impersonation_spec.rb +1 -1
- data/spec/lib/castle/api/track_spec.rb +1 -1
- data/spec/lib/castle/api_spec.rb +1 -1
- data/spec/lib/castle/client_id/extract_spec.rb +1 -1
- data/spec/lib/castle/client_spec.rb +6 -1
- data/spec/lib/castle/command_spec.rb +1 -1
- data/spec/lib/castle/commands/approve_device_spec.rb +1 -1
- data/spec/lib/castle/commands/authenticate_spec.rb +1 -1
- data/spec/lib/castle/commands/end_impersonation_spec.rb +1 -1
- data/spec/lib/castle/commands/filter_spec.rb +1 -1
- data/spec/lib/castle/commands/get_device_spec.rb +1 -1
- data/spec/lib/castle/commands/get_devices_for_user_spec.rb +1 -1
- data/spec/lib/castle/commands/list_items/archive_spec.rb +21 -0
- data/spec/lib/castle/commands/list_items/count_spec.rb +21 -0
- data/spec/lib/castle/commands/list_items/create_spec.rb +22 -0
- data/spec/lib/castle/commands/list_items/get_spec.rb +21 -0
- data/spec/lib/castle/commands/list_items/query_spec.rb +27 -0
- data/spec/lib/castle/commands/list_items/unarchive_spec.rb +21 -0
- data/spec/lib/castle/commands/list_items/update_spec.rb +21 -0
- data/spec/lib/castle/commands/lists/create_spec.rb +33 -0
- data/spec/lib/castle/commands/lists/delete_spec.rb +21 -0
- data/spec/lib/castle/commands/lists/get_all_spec.rb +11 -0
- data/spec/lib/castle/commands/lists/get_spec.rb +21 -0
- data/spec/lib/castle/commands/lists/query_spec.rb +27 -0
- data/spec/lib/castle/commands/lists/update_spec.rb +29 -0
- data/spec/lib/castle/commands/log_spec.rb +1 -1
- data/spec/lib/castle/commands/report_device_spec.rb +1 -1
- data/spec/lib/castle/commands/risk_spec.rb +1 -1
- data/spec/lib/castle/commands/start_impersonation_spec.rb +1 -1
- data/spec/lib/castle/commands/track_spec.rb +1 -1
- data/spec/lib/castle/configuration_spec.rb +1 -1
- data/spec/lib/castle/context/get_default_spec.rb +1 -1
- data/spec/lib/castle/context/merge_spec.rb +1 -1
- data/spec/lib/castle/context/prepare_spec.rb +1 -1
- data/spec/lib/castle/context/sanitize_spec.rb +1 -1
- data/spec/lib/castle/core/get_connection_spec.rb +1 -1
- data/spec/lib/castle/core/process_response_spec.rb +1 -1
- data/spec/lib/castle/core/process_webhook_spec.rb +1 -1
- data/spec/lib/castle/core/send_request_spec.rb +1 -1
- data/spec/lib/castle/failover/strategy_spec.rb +1 -1
- data/spec/lib/castle/headers/extract_spec.rb +1 -1
- data/spec/lib/castle/headers/filter_spec.rb +1 -1
- data/spec/lib/castle/headers/format_spec.rb +1 -1
- data/spec/lib/castle/ips/extract_spec.rb +1 -1
- data/spec/lib/castle/logger_spec.rb +1 -1
- data/spec/lib/castle/payload/prepare_spec.rb +1 -1
- data/spec/lib/castle/secure_mode_spec.rb +1 -1
- data/spec/lib/castle/session_spec.rb +1 -1
- data/spec/lib/castle/singleton_configuration_spec.rb +1 -1
- data/spec/lib/castle/utils/clean_invalid_chars_spec.rb +1 -1
- data/spec/lib/castle/utils/clone_spec.rb +1 -1
- data/spec/lib/castle/utils/deep_symbolize_keys_spec.rb +1 -1
- data/spec/lib/castle/utils/get_timestamp_spec.rb +1 -1
- data/spec/lib/castle/utils/merge_spec.rb +1 -1
- data/spec/lib/castle/validators/not_supported_spec.rb +1 -1
- data/spec/lib/castle/validators/present_spec.rb +1 -1
- data/spec/lib/castle/verdict_spec.rb +1 -1
- data/spec/lib/castle/version_spec.rb +1 -1
- data/spec/lib/castle/webhooks/verify_spec.rb +1 -1
- data/spec/lib/castle_spec.rb +1 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/support/shared_examples/list_items.rb +52 -0
- data/spec/support/shared_examples/lists.rb +45 -0
- metadata +87 -3
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::ListItems::Get do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build(options) }
|
6
|
+
|
7
|
+
context 'with valid options' do
|
8
|
+
let(:options) { { list_id: 'list_id', list_item_id: 'list_item_id'} }
|
9
|
+
|
10
|
+
it { expect(command.method).to be(:get) }
|
11
|
+
it { expect(command.path).to eql('lists/list_id/items/list_item_id') }
|
12
|
+
it { expect(command.data).to be_nil }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with invalid options' do
|
16
|
+
let(:options) { { list_id: 'list_id' } }
|
17
|
+
|
18
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::ListItems::Query do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build(options) }
|
6
|
+
|
7
|
+
context 'with valid options' do
|
8
|
+
let(:options) { { list_id: 'list_id', filters: [{ field: 'primary_value', op: '$eq', value: 'test'}]} }
|
9
|
+
|
10
|
+
it { expect(command.method).to be(:post) }
|
11
|
+
it { expect(command.path).to eql('lists/list_id/items/query') }
|
12
|
+
it { expect(command.data).to eql(options.except(:list_id)) }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with invalid filters' do
|
16
|
+
let(:options) { { list_id: 'list_id', filters: [{ field: 'primary_field', op: '$eq' }]} }
|
17
|
+
|
18
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'with no list_id' do
|
22
|
+
let(:options) { { filters: [{ field: 'primary_field', op: '$eq', value: 'test' }]} }
|
23
|
+
|
24
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::ListItems::Unarchive do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build(options) }
|
6
|
+
|
7
|
+
context 'with valid options' do
|
8
|
+
let(:options) { { list_id: 'list_id', list_item_id: 'list_item_id'} }
|
9
|
+
|
10
|
+
it { expect(command.method).to be(:put) }
|
11
|
+
it { expect(command.path).to eql('lists/list_id/items/list_item_id/unarchive') }
|
12
|
+
it { expect(command.data).to be_nil }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with invalid options' do
|
16
|
+
let(:options) { { list_id: 'list_id' } }
|
17
|
+
|
18
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::ListItems::Update do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build(options) }
|
6
|
+
|
7
|
+
context 'with valid options' do
|
8
|
+
let(:options) { { list_id: 'list_id', list_item_id: 'list_item_id', comment: 'updating item' } }
|
9
|
+
|
10
|
+
it { expect(command.method).to be(:put) }
|
11
|
+
it { expect(command.path).to eql('lists/list_id/items/list_item_id') }
|
12
|
+
it { expect(command.data).to eql(options.except(:list_id, :list_item_id)) }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with invalid options' do
|
16
|
+
let(:options) { { list_id: 'list_id', list_item_id: 'list_item_id' } }
|
17
|
+
|
18
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::Lists::Create do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build(options) }
|
6
|
+
|
7
|
+
let(:options) { { name: 'list_name', color: '$green', primary_field: 'user.email' } }
|
8
|
+
|
9
|
+
context 'with valid options' do
|
10
|
+
it { expect(command.method).to be(:post) }
|
11
|
+
it { expect(command.path).to eql('lists') }
|
12
|
+
it { expect(command.data).to eql(options) }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'without name' do
|
16
|
+
let(:options) { { color: '$green', primary_field: 'user.email' } }
|
17
|
+
|
18
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'without color' do
|
22
|
+
let(:options) { { name: 'list_name', primary_field: 'user.email' } }
|
23
|
+
|
24
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'without primary_field' do
|
28
|
+
let(:options) { { name: 'list_name', color: '$green' } }
|
29
|
+
|
30
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::Lists::Delete do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build(options) }
|
6
|
+
|
7
|
+
let(:options) { { list_id: 'list_id' } }
|
8
|
+
|
9
|
+
context 'with valid options' do
|
10
|
+
it { expect(command.method).to be(:delete) }
|
11
|
+
it { expect(command.path).to eql('lists/list_id') }
|
12
|
+
it { expect(command.data).to be_nil }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'without list_id' do
|
16
|
+
let(:options) { {} }
|
17
|
+
|
18
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::Lists::GetAll do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build }
|
6
|
+
|
7
|
+
it { expect(command.method).to be(:get) }
|
8
|
+
it { expect(command.path).to eql('lists') }
|
9
|
+
it { expect(command.data).to be_nil }
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::Lists::Get do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build(options) }
|
6
|
+
|
7
|
+
let(:options) { { list_id: 'list_id' } }
|
8
|
+
|
9
|
+
context 'with valid options' do
|
10
|
+
it { expect(command.method).to be(:get) }
|
11
|
+
it { expect(command.path).to eql('lists/list_id') }
|
12
|
+
it { expect(command.data).to be_nil }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'without list_id' do
|
16
|
+
let(:options) { {} }
|
17
|
+
|
18
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::Lists::Query do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build(options) }
|
6
|
+
|
7
|
+
context 'with valid options' do
|
8
|
+
let(:options) { { filters: [{ field: 'primary_field', op: '$eq', value: 'test' }]} }
|
9
|
+
|
10
|
+
it { expect(command.method).to be(:post) }
|
11
|
+
it { expect(command.path).to eql('lists/query') }
|
12
|
+
it { expect(command.data).to eq(options.except(:list_id)) }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with invalid filters' do
|
16
|
+
let(:options) { { filters: [{ field: 'primary_field', op: '$eq' }]} }
|
17
|
+
|
18
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'with invalid sort' do
|
22
|
+
let(:options) { { sort: { field: 'primary_field' } } }
|
23
|
+
|
24
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::Lists::Update do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build(options) }
|
6
|
+
|
7
|
+
context 'with valid options' do
|
8
|
+
let(:options) do
|
9
|
+
{
|
10
|
+
list_id: 'list_id',
|
11
|
+
name: 'name',
|
12
|
+
description: 'description',
|
13
|
+
color: '$yellow',
|
14
|
+
default_item_archivation_time: 6000
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
it { expect(command.method).to be(:put) }
|
19
|
+
it { expect(command.path).to eql('lists/list_id') }
|
20
|
+
it { expect(command.data).to eql(options.except(:list_id)) }
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'without list_id' do
|
24
|
+
let(:options) { { name: 'name' } }
|
25
|
+
|
26
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe Castle::Utils::DeepSymbolizeKeys do
|
3
|
+
RSpec.describe Castle::Utils::DeepSymbolizeKeys do
|
4
4
|
let(:nested_strings) { { 'a' => { 'b' => { 'c' => 3 } } } }
|
5
5
|
let(:nested_symbols) { { a: { b: { c: 3 } } } }
|
6
6
|
let(:nested_mixed) { { 'a' => { b: { 'c' => 3 } } } }
|
data/spec/lib/castle_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.shared_examples 'it has list item actions' do
|
4
|
+
describe 'archive_list_item' do
|
5
|
+
it do
|
6
|
+
client.archive_list_item(list_id: '1234', list_item_id: '5678')
|
7
|
+
assert_requested :delete, 'https://api.castle.io/v1/lists/1234/items/5678/archive', times: 1
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'count_list_items' do
|
12
|
+
it do
|
13
|
+
client.count_list_items(list_id: '1234', filters: [{ field: 'email', op: 'eq', value: 'test' }])
|
14
|
+
assert_requested :post, 'https://api.castle.io/v1/lists/1234/items/count', times: 1
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'create_list_item' do
|
19
|
+
it do
|
20
|
+
client.create_list_item(list_id: '1234', author: { type: 'other', identifier: '1234' }, primary_value: 'email')
|
21
|
+
assert_requested :post, 'https://api.castle.io/v1/lists/1234/items', times: 1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'get_list_item' do
|
26
|
+
it do
|
27
|
+
client.get_list_item(list_id: '1234', list_item_id: '5678')
|
28
|
+
assert_requested :get, 'https://api.castle.io/v1/lists/1234/items/5678', times: 1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'query_list_items' do
|
33
|
+
it do
|
34
|
+
client.query_list_items(list_id: '1234', filters: [{ field: 'email', op: 'eq', value: 'test' }])
|
35
|
+
assert_requested :post, 'https://api.castle.io/v1/lists/1234/items/query', times: 1
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'unarchive_list_item' do
|
40
|
+
it do
|
41
|
+
client.unarchive_list_item(list_id: '1234', list_item_id: '5678')
|
42
|
+
assert_requested :put, 'https://api.castle.io/v1/lists/1234/items/5678/unarchive', times: 1
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'update_list_item' do
|
47
|
+
it do
|
48
|
+
client.update_list_item(list_id: '1234', list_item_id: '5678', comment: 'updating comment')
|
49
|
+
assert_requested :put, 'https://api.castle.io/v1/lists/1234/items/5678', times: 1
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|