castle-rb 7.2.0 → 8.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.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/lib/castle/api/authenticate.rb +3 -12
  3. data/lib/castle/api/end_impersonation.rb +1 -3
  4. data/lib/castle/api/filter.rb +2 -10
  5. data/lib/castle/api/list_items/archive.rb +23 -0
  6. data/lib/castle/api/list_items/count.rb +22 -0
  7. data/lib/castle/api/list_items/create.rb +22 -0
  8. data/lib/castle/api/list_items/get.rb +22 -0
  9. data/lib/castle/api/list_items/query.rb +22 -0
  10. data/lib/castle/api/list_items/unarchive.rb +22 -0
  11. data/lib/castle/api/list_items/update.rb +22 -0
  12. data/lib/castle/api/lists/create.rb +23 -0
  13. data/lib/castle/api/lists/delete.rb +22 -0
  14. data/lib/castle/api/lists/get.rb +22 -0
  15. data/lib/castle/api/lists/get_all.rb +22 -0
  16. data/lib/castle/api/lists/query.rb +22 -0
  17. data/lib/castle/api/lists/update.rb +22 -0
  18. data/lib/castle/api/log.rb +2 -10
  19. data/lib/castle/api/risk.rb +2 -10
  20. data/lib/castle/api/start_impersonation.rb +1 -3
  21. data/lib/castle/api/track.rb +1 -3
  22. data/lib/castle/client.rb +4 -5
  23. data/lib/castle/client_actions/list_items.rb +44 -0
  24. data/lib/castle/client_actions/lists.rb +39 -0
  25. data/lib/castle/commands/list_items/archive.rb +24 -0
  26. data/lib/castle/commands/list_items/count.rb +23 -0
  27. data/lib/castle/commands/list_items/create.rb +22 -0
  28. data/lib/castle/commands/list_items/get.rb +23 -0
  29. data/lib/castle/commands/list_items/query.rb +24 -0
  30. data/lib/castle/commands/list_items/unarchive.rb +23 -0
  31. data/lib/castle/commands/list_items/update.rb +22 -0
  32. data/lib/castle/commands/lists/create.rb +21 -0
  33. data/lib/castle/commands/lists/delete.rb +20 -0
  34. data/lib/castle/commands/lists/get.rb +20 -0
  35. data/lib/castle/commands/lists/get_all.rb +17 -0
  36. data/lib/castle/commands/lists/query.rb +21 -0
  37. data/lib/castle/commands/lists/update.rb +22 -0
  38. data/lib/castle/commands/log.rb +1 -5
  39. data/lib/castle/commands/risk.rb +1 -5
  40. data/lib/castle/configuration.rb +2 -5
  41. data/lib/castle/core/process_response.rb +4 -3
  42. data/lib/castle/core/send_request.rb +1 -3
  43. data/lib/castle/errors.rb +4 -0
  44. data/lib/castle/headers/extract.rb +1 -3
  45. data/lib/castle/headers/filter.rb +2 -3
  46. data/lib/castle/payload/prepare.rb +1 -2
  47. data/lib/castle/session.rb +1 -1
  48. data/lib/castle/version.rb +1 -1
  49. data/lib/castle.rb +29 -3
  50. data/spec/integration/rails/rails_spec.rb +9 -3
  51. data/spec/integration/rails/support/application.rb +2 -2
  52. data/spec/integration/rails/support/home_controller.rb +4 -30
  53. data/spec/lib/castle/api/approve_device_spec.rb +3 -7
  54. data/spec/lib/castle/api/authenticate_spec.rb +23 -26
  55. data/spec/lib/castle/api/end_impersonation_spec.rb +9 -15
  56. data/spec/lib/castle/api/filter_spec.rb +1 -1
  57. data/spec/lib/castle/api/get_device_spec.rb +2 -4
  58. data/spec/lib/castle/api/get_devices_for_user_spec.rb +2 -4
  59. data/spec/lib/castle/api/list_items/archive_spec.rb +18 -0
  60. data/spec/lib/castle/api/list_items/count_spec.rb +21 -0
  61. data/spec/lib/castle/api/list_items/create_spec.rb +22 -0
  62. data/spec/lib/castle/api/list_items/get_spec.rb +18 -0
  63. data/spec/lib/castle/api/list_items/query_spec.rb +21 -0
  64. data/spec/lib/castle/api/list_items/unarchive_spec.rb +18 -0
  65. data/spec/lib/castle/api/list_items/update_spec.rb +22 -0
  66. data/spec/lib/castle/api/lists/create_spec.rb +21 -0
  67. data/spec/lib/castle/api/lists/delete_spec.rb +17 -0
  68. data/spec/lib/castle/api/lists/get_all_spec.rb +17 -0
  69. data/spec/lib/castle/api/lists/get_spec.rb +17 -0
  70. data/spec/lib/castle/api/lists/query_spec.rb +21 -0
  71. data/spec/lib/castle/api/lists/update_spec.rb +21 -0
  72. data/spec/lib/castle/api/log_spec.rb +1 -1
  73. data/spec/lib/castle/api/report_device_spec.rb +3 -7
  74. data/spec/lib/castle/api/risk_spec.rb +1 -1
  75. data/spec/lib/castle/api/start_impersonation_spec.rb +9 -15
  76. data/spec/lib/castle/api/track_spec.rb +10 -17
  77. data/spec/lib/castle/api_spec.rb +1 -1
  78. data/spec/lib/castle/client_id/extract_spec.rb +3 -10
  79. data/spec/lib/castle/client_spec.rb +38 -79
  80. data/spec/lib/castle/command_spec.rb +4 -4
  81. data/spec/lib/castle/commands/approve_device_spec.rb +3 -3
  82. data/spec/lib/castle/commands/authenticate_spec.rb +18 -25
  83. data/spec/lib/castle/commands/end_impersonation_spec.rb +15 -22
  84. data/spec/lib/castle/commands/filter_spec.rb +16 -16
  85. data/spec/lib/castle/commands/get_device_spec.rb +3 -3
  86. data/spec/lib/castle/commands/get_devices_for_user_spec.rb +3 -3
  87. data/spec/lib/castle/commands/list_items/archive_spec.rb +21 -0
  88. data/spec/lib/castle/commands/list_items/count_spec.rb +21 -0
  89. data/spec/lib/castle/commands/list_items/create_spec.rb +22 -0
  90. data/spec/lib/castle/commands/list_items/get_spec.rb +21 -0
  91. data/spec/lib/castle/commands/list_items/query_spec.rb +27 -0
  92. data/spec/lib/castle/commands/list_items/unarchive_spec.rb +21 -0
  93. data/spec/lib/castle/commands/list_items/update_spec.rb +21 -0
  94. data/spec/lib/castle/commands/lists/create_spec.rb +33 -0
  95. data/spec/lib/castle/commands/lists/delete_spec.rb +21 -0
  96. data/spec/lib/castle/commands/lists/get_all_spec.rb +11 -0
  97. data/spec/lib/castle/commands/lists/get_spec.rb +21 -0
  98. data/spec/lib/castle/commands/lists/query_spec.rb +27 -0
  99. data/spec/lib/castle/commands/lists/update_spec.rb +29 -0
  100. data/spec/lib/castle/commands/log_spec.rb +16 -16
  101. data/spec/lib/castle/commands/report_device_spec.rb +3 -3
  102. data/spec/lib/castle/commands/risk_spec.rb +16 -16
  103. data/spec/lib/castle/commands/start_impersonation_spec.rb +15 -22
  104. data/spec/lib/castle/commands/track_spec.rb +20 -25
  105. data/spec/lib/castle/configuration_spec.rb +2 -2
  106. data/spec/lib/castle/context/get_default_spec.rb +10 -9
  107. data/spec/lib/castle/context/merge_spec.rb +1 -1
  108. data/spec/lib/castle/context/prepare_spec.rb +4 -5
  109. data/spec/lib/castle/context/sanitize_spec.rb +1 -1
  110. data/spec/lib/castle/core/get_connection_spec.rb +1 -1
  111. data/spec/lib/castle/core/process_response_spec.rb +4 -7
  112. data/spec/lib/castle/core/process_webhook_spec.rb +13 -7
  113. data/spec/lib/castle/core/send_request_spec.rb +8 -12
  114. data/spec/lib/castle/failover/strategy_spec.rb +6 -6
  115. data/spec/lib/castle/headers/extract_spec.rb +2 -2
  116. data/spec/lib/castle/headers/filter_spec.rb +7 -4
  117. data/spec/lib/castle/headers/format_spec.rb +6 -6
  118. data/spec/lib/castle/ips/extract_spec.rb +3 -7
  119. data/spec/lib/castle/logger_spec.rb +3 -2
  120. data/spec/lib/castle/payload/prepare_spec.rb +5 -8
  121. data/spec/lib/castle/secure_mode_spec.rb +2 -4
  122. data/spec/lib/castle/session_spec.rb +2 -6
  123. data/spec/lib/castle/singleton_configuration_spec.rb +2 -2
  124. data/spec/lib/castle/utils/clean_invalid_chars_spec.rb +1 -1
  125. data/spec/lib/castle/utils/clone_spec.rb +2 -2
  126. data/spec/lib/castle/utils/deep_symbolize_keys_spec.rb +1 -1
  127. data/spec/lib/castle/utils/get_timestamp_spec.rb +1 -1
  128. data/spec/lib/castle/utils/merge_spec.rb +3 -5
  129. data/spec/lib/castle/validators/not_supported_spec.rb +2 -7
  130. data/spec/lib/castle/validators/present_spec.rb +3 -10
  131. data/spec/lib/castle/verdict_spec.rb +4 -4
  132. data/spec/lib/castle/version_spec.rb +1 -1
  133. data/spec/lib/castle/webhooks/verify_spec.rb +13 -7
  134. data/spec/lib/castle_spec.rb +6 -8
  135. data/spec/spec_helper.rb +2 -0
  136. data/spec/support/shared_examples/action_request.rb +16 -34
  137. data/spec/support/shared_examples/configuration.rb +14 -16
  138. data/spec/support/shared_examples/list_items.rb +52 -0
  139. data/spec/support/shared_examples/lists.rb +45 -0
  140. metadata +132 -48
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ada9f9e25a4da59d7577cb10848d45697a6709648846011fc803167a8b96203
4
- data.tar.gz: 2b0927e4ae6f686a35c9c5ac39e510f46f8fc06506932441b421a845ba296f27
3
+ metadata.gz: 6f571bda5aa4075f18ef7c64173155401d822ced4fe66fe7c4ceaf4c7c6c6c6e
4
+ data.tar.gz: 15709ff2d5bbdf57063bdd0c1f3eb492f78beff5b1e2b8c61a848f3a2af1d32d
5
5
  SHA512:
6
- metadata.gz: 5ff2d32ab3ae269adbcd5380ba7488e06c0d9ae0ab463cd73856eb65b67bb4559daa1118344bc1a6896b097f00f9e5cc35c80ce68add430785769c2502e261b0
7
- data.tar.gz: e48b7c5332de7d74ad8d13a89f52b2fd756d1c2b77600af86b86d74c78789916ac2972983781708be097d9d6f4067705b59ba26eaca2dc3e45720eee4ced6f08
6
+ metadata.gz: 5186002c86cef93deb33c8c03c95ffc81adaa7b59b032a06f2f81ff1423d0cd247d198e0a7fce2a15e2a1ab6a76a986c524644c4f4338be5a7e16ec45ba6cdca
7
+ data.tar.gz: a9c63ce6293981630ed431471ceb0ffb70fe990b68784f70088dba28140a63e7ff012286604d8da9a79f5b93486ba4cb8e3318c93ee3617c29f6f981ef737d86
@@ -7,26 +7,17 @@ module Castle
7
7
  # @param options [Hash]
8
8
  # return [Hash]
9
9
  def call(options = {})
10
- unless options[:no_symbolize]
11
- options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
12
- end
10
+ options = Castle::Utils::DeepSymbolizeKeys.call(options || {}) unless options[:no_symbolize]
13
11
  options.delete(:no_symbolize)
14
12
  http = options.delete(:http)
15
13
  config = options.delete(:config) || Castle.config
16
14
 
17
- response =
18
- Castle::API.call(Castle::Commands::Authenticate.build(options), {}, http, config)
15
+ response = Castle::API.call(Castle::Commands::Authenticate.build(options), {}, http, config)
19
16
  response.merge(failover: false, failover_reason: nil)
20
17
  rescue Castle::RequestError, Castle::InternalServerError => e
21
18
  unless config.failover_strategy == :throw
22
19
  strategy = (config || Castle.config).failover_strategy
23
- return(
24
- Castle::Failover::PrepareResponse.new(
25
- options[:user_id],
26
- reason: e.to_s,
27
- strategy: strategy
28
- ).call
29
- )
20
+ return(Castle::Failover::PrepareResponse.new(options[:user_id], reason: e.to_s, strategy: strategy).call)
30
21
  end
31
22
 
32
23
  raise e
@@ -7,9 +7,7 @@ module Castle
7
7
  class << self
8
8
  # @param options [Hash]
9
9
  def call(options = {})
10
- unless options[:no_symbolize]
11
- options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
12
- end
10
+ options = Castle::Utils::DeepSymbolizeKeys.call(options || {}) unless options[:no_symbolize]
13
11
  options.delete(:no_symbolize)
14
12
  http = options.delete(:http)
15
13
  config = options.delete(:config) || Castle.config
@@ -8,9 +8,7 @@ module Castle
8
8
  # @param options [Hash]
9
9
  # return [Hash]
10
10
  def call(options = {})
11
- unless options[:no_symbolize]
12
- options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
13
- end
11
+ options = Castle::Utils::DeepSymbolizeKeys.call(options || {}) unless options[:no_symbolize]
14
12
  options.delete(:no_symbolize)
15
13
  http = options.delete(:http)
16
14
  config = options.delete(:config) || Castle.config
@@ -20,13 +18,7 @@ module Castle
20
18
  rescue Castle::RequestError, Castle::InternalServerError => e
21
19
  unless config.failover_strategy == :throw
22
20
  strategy = (config || Castle.config).failover_strategy
23
- return(
24
- Castle::Failover::PrepareResponse.new(
25
- options[:user][:id],
26
- reason: e.to_s,
27
- strategy: strategy
28
- ).call
29
- )
21
+ return(Castle::Failover::PrepareResponse.new(options[:user][:id], reason: e.to_s, strategy: strategy).call)
30
22
  end
31
23
 
32
24
  raise e
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module API
5
+ # Namespace for the list items API ednpoints
6
+ module ListItems
7
+ # Sends DELETE /lists/:list_id/items/:item_id request
8
+ module Archive
9
+ class << self
10
+ # @param options [Hash]
11
+ # @return [Hash]
12
+ def call(options = {})
13
+ options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
14
+ http = options.delete(:http)
15
+ config = options.delete(:config) || Castle.config
16
+
17
+ Castle::API.call(Castle::Commands::ListItems::Archive.build(options), {}, http, config)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module API
5
+ module ListItems
6
+ # Sends POST /lists/:list_id/items request
7
+ module Count
8
+ class << self
9
+ # @param options [Hash]
10
+ # @return [Hash]
11
+ def call(options = {})
12
+ options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
13
+ http = options.delete(:http)
14
+ config = options.delete(:config) || Castle.config
15
+
16
+ Castle::API.call(Castle::Commands::ListItems::Count.build(options), {}, http, config)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module API
5
+ module ListItems
6
+ # Sends POST /lists/:list_id/items request
7
+ module Create
8
+ class << self
9
+ # @param options [Hash]
10
+ # @return [Hash]
11
+ def call(options = {})
12
+ options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
13
+ http = options.delete(:http)
14
+ config = options.delete(:config) || Castle.config
15
+
16
+ Castle::API.call(Castle::Commands::ListItems::Create.build(options), {}, http, config)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module API
5
+ module ListItems
6
+ # Sends GET /lists/:list_id/items/:item_id request
7
+ module Get
8
+ class << self
9
+ # @param options [Hash]
10
+ # @return [Hash]
11
+ def call(options = {})
12
+ options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
13
+ http = options.delete(:http)
14
+ config = options.delete(:config) || Castle.config
15
+
16
+ Castle::API.call(Castle::Commands::ListItems::Get.build(options), {}, http, config)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module API
5
+ module ListItems
6
+ # Sends POST /lists/:list_id/items/query request
7
+ module Query
8
+ class << self
9
+ # @param options [Hash]
10
+ # @return [Hash]
11
+ def call(options = {})
12
+ options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
13
+ http = options.delete(:http)
14
+ config = options.delete(:config) || Castle.config
15
+
16
+ Castle::API.call(Castle::Commands::ListItems::Query.build(options), {}, http, config)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module API
5
+ module ListItems
6
+ # Sends PUT /lists/:list_id/items/:item_id/unarchive request
7
+ module Unarchive
8
+ class << self
9
+ # @param options [Hash]
10
+ # @return [Hash]
11
+ def call(options = {})
12
+ options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
13
+ http = options.delete(:http)
14
+ config = options.delete(:config) || Castle.config
15
+
16
+ Castle::API.call(Castle::Commands::ListItems::Unarchive.build(options), {}, http, config)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module API
5
+ module ListItems
6
+ # Sends PUT /lists/:list_id/items/:item_id request
7
+ module Update
8
+ class << self
9
+ # @param options [Hash]
10
+ # @return [Hash]
11
+ def call(options = {})
12
+ options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
13
+ http = options.delete(:http)
14
+ config = options.delete(:config) || Castle.config
15
+
16
+ Castle::API.call(Castle::Commands::ListItems::Update.build(options), {}, http, config)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module API
5
+ # Namespace for the lists API ednpoints
6
+ module Lists
7
+ # Sends POST /lists request
8
+ module Create
9
+ class << self
10
+ # @param options [Hash]
11
+ # @return [Hash]
12
+ def call(options = {})
13
+ options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
14
+ http = options.delete(:http)
15
+ config = options.delete(:config) || Castle.config
16
+
17
+ Castle::API.call(Castle::Commands::Lists::Create.build(options), {}, http, config)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module API
5
+ module Lists
6
+ # Sends DELETE /lists/:list_id request
7
+ module Delete
8
+ class << self
9
+ # @param options [Hash]
10
+ # @return [Hash]
11
+ def call(options = {})
12
+ options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
13
+ http = options.delete(:http)
14
+ config = options.delete(:config) || Castle.config
15
+
16
+ Castle::API.call(Castle::Commands::Lists::Delete.build(options), {}, http, config)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module API
5
+ module Lists
6
+ # Sends GET /lists/:list_id request
7
+ module Get
8
+ class << self
9
+ # @param options [Hash]
10
+ # @return [Hash]
11
+ def call(options = {})
12
+ options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
13
+ http = options.delete(:http)
14
+ config = options.delete(:config) || Castle.config
15
+
16
+ Castle::API.call(Castle::Commands::Lists::Get.build(options), {}, http, config)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module API
5
+ module Lists
6
+ # Sends GET /lists request
7
+ module GetAll
8
+ class << self
9
+ # @param options [Hash]
10
+ # @return [Hash]
11
+ def call(options = {})
12
+ options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
13
+ http = options.delete(:http)
14
+ config = options.delete(:config) || Castle.config
15
+
16
+ Castle::API.call(Castle::Commands::Lists::GetAll.build, {}, http, config)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module API
5
+ module Lists
6
+ # Sends POST /lists/query request
7
+ module Query
8
+ class << self
9
+ # @param options [Hash]
10
+ # @return [Hash]
11
+ def call(options = {})
12
+ options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
13
+ http = options.delete(:http)
14
+ config = options.delete(:config) || Castle.config
15
+
16
+ Castle::API.call(Castle::Commands::Lists::Query.build(options), {}, http, config)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module API
5
+ module Lists
6
+ # Sends PUT /lists/:list_id request
7
+ module Update
8
+ class << self
9
+ # @param options [Hash]
10
+ # @return [Hash]
11
+ def call(options = {})
12
+ options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
13
+ http = options.delete(:http)
14
+ config = options.delete(:config) || Castle.config
15
+
16
+ Castle::API.call(Castle::Commands::Lists::Update.build(options), {}, http, config)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -8,9 +8,7 @@ module Castle
8
8
  # @param options [Hash]
9
9
  # return [Hash]
10
10
  def call(options = {})
11
- unless options[:no_symbolize]
12
- options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
13
- end
11
+ options = Castle::Utils::DeepSymbolizeKeys.call(options || {}) unless options[:no_symbolize]
14
12
  options.delete(:no_symbolize)
15
13
  http = options.delete(:http)
16
14
  config = options.delete(:config) || Castle.config
@@ -20,13 +18,7 @@ module Castle
20
18
  rescue Castle::RequestError, Castle::InternalServerError => e
21
19
  unless config.failover_strategy == :throw
22
20
  strategy = (config || Castle.config).failover_strategy
23
- return(
24
- Castle::Failover::PrepareResponse.new(
25
- options[:user][:id],
26
- reason: e.to_s,
27
- strategy: strategy
28
- ).call
29
- )
21
+ return(Castle::Failover::PrepareResponse.new(options[:user][:id], reason: e.to_s, strategy: strategy).call)
30
22
  end
31
23
 
32
24
  raise e
@@ -8,9 +8,7 @@ module Castle
8
8
  # @param options [Hash]
9
9
  # return [Hash]
10
10
  def call(options = {})
11
- unless options[:no_symbolize]
12
- options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
13
- end
11
+ options = Castle::Utils::DeepSymbolizeKeys.call(options || {}) unless options[:no_symbolize]
14
12
  options.delete(:no_symbolize)
15
13
  http = options.delete(:http)
16
14
  config = options.delete(:config) || Castle.config
@@ -20,13 +18,7 @@ module Castle
20
18
  rescue Castle::RequestError, Castle::InternalServerError => e
21
19
  unless config.failover_strategy == :throw
22
20
  strategy = (config || Castle.config).failover_strategy
23
- return(
24
- Castle::Failover::PrepareResponse.new(
25
- options[:user][:id],
26
- reason: e.to_s,
27
- strategy: strategy
28
- ).call
29
- )
21
+ return(Castle::Failover::PrepareResponse.new(options[:user][:id], reason: e.to_s, strategy: strategy).call)
30
22
  end
31
23
 
32
24
  raise e
@@ -7,9 +7,7 @@ module Castle
7
7
  class << self
8
8
  # @param options [Hash]
9
9
  def call(options = {})
10
- unless options[:no_symbolize]
11
- options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
12
- end
10
+ options = Castle::Utils::DeepSymbolizeKeys.call(options || {}) unless options[:no_symbolize]
13
11
  options.delete(:no_symbolize)
14
12
  http = options.delete(:http)
15
13
  config = options.delete(:config) || Castle.config
@@ -6,9 +6,7 @@ module Castle
6
6
  class << self
7
7
  # @param options [Hash]
8
8
  def call(options = {})
9
- unless options[:no_symbolize]
10
- options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
11
- end
9
+ options = Castle::Utils::DeepSymbolizeKeys.call(options || {}) unless options[:no_symbolize]
12
10
  options.delete(:no_symbolize)
13
11
  http = options.delete(:http)
14
12
  config = options.delete(:config) || Castle.config
data/lib/castle/client.rb CHANGED
@@ -3,6 +3,9 @@
3
3
  module Castle
4
4
  # Castle's client.
5
5
  class Client
6
+ include Castle::ClientActions::ListItems
7
+ include Castle::ClientActions::Lists
8
+
6
9
  class << self
7
10
  def from_request(request, options = {})
8
11
  new(options.merge(context: Castle::Context::Prepare.call(request, options)))
@@ -123,11 +126,7 @@ module Castle
123
126
 
124
127
  # @param user_id [String, Boolean]
125
128
  def generate_do_not_track_response(user_id)
126
- Castle::Failover::PrepareResponse.new(
127
- user_id,
128
- strategy: :allow,
129
- reason: 'Castle is set to do not track.'
130
- ).call
129
+ Castle::Failover::PrepareResponse.new(user_id, strategy: :allow, reason: 'Castle is set to do not track.').call
131
130
  end
132
131
 
133
132
  # @param options [Hash]
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ # Namesapce for client actions
5
+ module ClientActions
6
+ # Client actions for list items
7
+ module ListItems
8
+ # @param options [Hash]
9
+ def archive_list_item(options = {})
10
+ Castle::API::ListItems::Archive.call(options)
11
+ end
12
+
13
+ # @param options [Hash]
14
+ def count_list_items(options = {})
15
+ Castle::API::ListItems::Count.call(options)
16
+ end
17
+
18
+ # @param options [Hash]
19
+ def create_list_item(options = {})
20
+ Castle::API::ListItems::Create.call(options)
21
+ end
22
+
23
+ # @param options [Hash]
24
+ def get_list_item(options = {})
25
+ Castle::API::ListItems::Get.call(options)
26
+ end
27
+
28
+ # @param options [Hash]
29
+ def query_list_items(options = {})
30
+ Castle::API::ListItems::Query.call(options)
31
+ end
32
+
33
+ # @param options [Hash]
34
+ def unarchive_list_item(options)
35
+ Castle::API::ListItems::Unarchive.call(options)
36
+ end
37
+
38
+ # @param options [Hash]
39
+ def update_list_item(options = {})
40
+ Castle::API::ListItems::Update.call(options)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ # Namespace for client actions
5
+ module ClientActions
6
+ # Client actions for lists
7
+ module Lists
8
+ # @param options [Hash]
9
+ def create_list(options = {})
10
+ Castle::API::Lists::Create.call(options)
11
+ end
12
+
13
+ # @param options [Hash]
14
+ def delete_list(options = {})
15
+ Castle::API::Lists::Delete.call(options)
16
+ end
17
+
18
+ # @param options [Hash]
19
+ def get_all_lists(options = {})
20
+ Castle::API::Lists::GetAll.call(options)
21
+ end
22
+
23
+ # @param options [Hash]
24
+ def get_list(options = {})
25
+ Castle::API::Lists::Get.call(options)
26
+ end
27
+
28
+ # @param options [Hash]
29
+ def query_lists(options = {})
30
+ Castle::API::Lists::Query.call(options)
31
+ end
32
+
33
+ # @param options [Hash]
34
+ def update_list(options = {})
35
+ Castle::API::Lists::Update.call(options)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module Commands
5
+ # Commands for list items endpoints
6
+ module ListItems
7
+ # Generates the payload for the DELETE /lists/:list_id/items/:item_id/archive request
8
+ class Archive
9
+ class << self
10
+ # @param options [Hash]
11
+ # @return [Castle::Command]
12
+ def build(options = {})
13
+ Castle::Validators::Present.call(options, %i[list_id list_item_id])
14
+
15
+ list_id = options.delete(:list_id)
16
+ list_item_id = options.delete(:list_item_id)
17
+
18
+ Castle::Command.new("lists/#{list_id}/items/#{list_item_id}/archive", nil, :delete)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module Commands
5
+ module ListItems
6
+ # Generates the payload for the POST /lists/:list_id/items/count request
7
+ class Count
8
+ class << self
9
+ # @param options [Hash]
10
+ # @return [Castle::Command]
11
+ def build(options = {})
12
+ Castle::Validators::Present.call(options, %i[list_id])
13
+ options[:filters]&.each { |f| Castle::Validators::Present.call(f, %i[field op value]) }
14
+
15
+ list_id = options.delete(:list_id)
16
+
17
+ Castle::Command.new("lists/#{list_id}/items/count", options, :post)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module Commands
5
+ module ListItems
6
+ # Builds the command to create a list item
7
+ class Create
8
+ class << self
9
+ # @param options [Hash]
10
+ # @return [Castle::Command]
11
+ def build(options = {})
12
+ Castle::Validators::Present.call(options, %i[list_id author primary_value])
13
+
14
+ list_id = options.delete(:list_id)
15
+
16
+ Castle::Command.new("lists/#{list_id}/items", options, :post)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module Commands
5
+ module ListItems
6
+ # Builds the command to get a list item
7
+ class Get
8
+ class << self
9
+ # @param options [Hash]
10
+ # @return [Castle::Command]
11
+ def build(options = {})
12
+ Castle::Validators::Present.call(options, %i[list_id list_item_id])
13
+
14
+ list_id = options.delete(:list_id)
15
+ list_item_id = options.delete(:list_item_id)
16
+
17
+ Castle::Command.new("lists/#{list_id}/items/#{list_item_id}", nil, :get)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end