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.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/lib/castle/api/list_items/archive.rb +23 -0
  3. data/lib/castle/api/list_items/count.rb +22 -0
  4. data/lib/castle/api/list_items/create.rb +22 -0
  5. data/lib/castle/api/list_items/get.rb +22 -0
  6. data/lib/castle/api/list_items/query.rb +22 -0
  7. data/lib/castle/api/list_items/unarchive.rb +22 -0
  8. data/lib/castle/api/list_items/update.rb +22 -0
  9. data/lib/castle/api/lists/create.rb +23 -0
  10. data/lib/castle/api/lists/delete.rb +22 -0
  11. data/lib/castle/api/lists/get.rb +22 -0
  12. data/lib/castle/api/lists/get_all.rb +22 -0
  13. data/lib/castle/api/lists/query.rb +22 -0
  14. data/lib/castle/api/lists/update.rb +22 -0
  15. data/lib/castle/client.rb +3 -0
  16. data/lib/castle/client_actions/list_items.rb +44 -0
  17. data/lib/castle/client_actions/lists.rb +39 -0
  18. data/lib/castle/commands/list_items/archive.rb +24 -0
  19. data/lib/castle/commands/list_items/count.rb +23 -0
  20. data/lib/castle/commands/list_items/create.rb +22 -0
  21. data/lib/castle/commands/list_items/get.rb +23 -0
  22. data/lib/castle/commands/list_items/query.rb +24 -0
  23. data/lib/castle/commands/list_items/unarchive.rb +23 -0
  24. data/lib/castle/commands/list_items/update.rb +22 -0
  25. data/lib/castle/commands/lists/create.rb +21 -0
  26. data/lib/castle/commands/lists/delete.rb +20 -0
  27. data/lib/castle/commands/lists/get.rb +20 -0
  28. data/lib/castle/commands/lists/get_all.rb +17 -0
  29. data/lib/castle/commands/lists/query.rb +21 -0
  30. data/lib/castle/commands/lists/update.rb +22 -0
  31. data/lib/castle/version.rb +1 -1
  32. data/lib/castle.rb +28 -0
  33. data/spec/lib/castle/api/approve_device_spec.rb +1 -1
  34. data/spec/lib/castle/api/authenticate_spec.rb +1 -1
  35. data/spec/lib/castle/api/end_impersonation_spec.rb +1 -1
  36. data/spec/lib/castle/api/filter_spec.rb +1 -1
  37. data/spec/lib/castle/api/get_device_spec.rb +1 -1
  38. data/spec/lib/castle/api/get_devices_for_user_spec.rb +1 -1
  39. data/spec/lib/castle/api/list_items/archive_spec.rb +18 -0
  40. data/spec/lib/castle/api/list_items/count_spec.rb +21 -0
  41. data/spec/lib/castle/api/list_items/create_spec.rb +22 -0
  42. data/spec/lib/castle/api/list_items/get_spec.rb +18 -0
  43. data/spec/lib/castle/api/list_items/query_spec.rb +21 -0
  44. data/spec/lib/castle/api/list_items/unarchive_spec.rb +18 -0
  45. data/spec/lib/castle/api/list_items/update_spec.rb +22 -0
  46. data/spec/lib/castle/api/lists/create_spec.rb +21 -0
  47. data/spec/lib/castle/api/lists/delete_spec.rb +17 -0
  48. data/spec/lib/castle/api/lists/get_all_spec.rb +17 -0
  49. data/spec/lib/castle/api/lists/get_spec.rb +17 -0
  50. data/spec/lib/castle/api/lists/query_spec.rb +21 -0
  51. data/spec/lib/castle/api/lists/update_spec.rb +21 -0
  52. data/spec/lib/castle/api/log_spec.rb +1 -1
  53. data/spec/lib/castle/api/report_device_spec.rb +1 -1
  54. data/spec/lib/castle/api/risk_spec.rb +1 -1
  55. data/spec/lib/castle/api/start_impersonation_spec.rb +1 -1
  56. data/spec/lib/castle/api/track_spec.rb +1 -1
  57. data/spec/lib/castle/api_spec.rb +1 -1
  58. data/spec/lib/castle/client_id/extract_spec.rb +1 -1
  59. data/spec/lib/castle/client_spec.rb +6 -1
  60. data/spec/lib/castle/command_spec.rb +1 -1
  61. data/spec/lib/castle/commands/approve_device_spec.rb +1 -1
  62. data/spec/lib/castle/commands/authenticate_spec.rb +1 -1
  63. data/spec/lib/castle/commands/end_impersonation_spec.rb +1 -1
  64. data/spec/lib/castle/commands/filter_spec.rb +1 -1
  65. data/spec/lib/castle/commands/get_device_spec.rb +1 -1
  66. data/spec/lib/castle/commands/get_devices_for_user_spec.rb +1 -1
  67. data/spec/lib/castle/commands/list_items/archive_spec.rb +21 -0
  68. data/spec/lib/castle/commands/list_items/count_spec.rb +21 -0
  69. data/spec/lib/castle/commands/list_items/create_spec.rb +22 -0
  70. data/spec/lib/castle/commands/list_items/get_spec.rb +21 -0
  71. data/spec/lib/castle/commands/list_items/query_spec.rb +27 -0
  72. data/spec/lib/castle/commands/list_items/unarchive_spec.rb +21 -0
  73. data/spec/lib/castle/commands/list_items/update_spec.rb +21 -0
  74. data/spec/lib/castle/commands/lists/create_spec.rb +33 -0
  75. data/spec/lib/castle/commands/lists/delete_spec.rb +21 -0
  76. data/spec/lib/castle/commands/lists/get_all_spec.rb +11 -0
  77. data/spec/lib/castle/commands/lists/get_spec.rb +21 -0
  78. data/spec/lib/castle/commands/lists/query_spec.rb +27 -0
  79. data/spec/lib/castle/commands/lists/update_spec.rb +29 -0
  80. data/spec/lib/castle/commands/log_spec.rb +1 -1
  81. data/spec/lib/castle/commands/report_device_spec.rb +1 -1
  82. data/spec/lib/castle/commands/risk_spec.rb +1 -1
  83. data/spec/lib/castle/commands/start_impersonation_spec.rb +1 -1
  84. data/spec/lib/castle/commands/track_spec.rb +1 -1
  85. data/spec/lib/castle/configuration_spec.rb +1 -1
  86. data/spec/lib/castle/context/get_default_spec.rb +1 -1
  87. data/spec/lib/castle/context/merge_spec.rb +1 -1
  88. data/spec/lib/castle/context/prepare_spec.rb +1 -1
  89. data/spec/lib/castle/context/sanitize_spec.rb +1 -1
  90. data/spec/lib/castle/core/get_connection_spec.rb +1 -1
  91. data/spec/lib/castle/core/process_response_spec.rb +1 -1
  92. data/spec/lib/castle/core/process_webhook_spec.rb +1 -1
  93. data/spec/lib/castle/core/send_request_spec.rb +1 -1
  94. data/spec/lib/castle/failover/strategy_spec.rb +1 -1
  95. data/spec/lib/castle/headers/extract_spec.rb +1 -1
  96. data/spec/lib/castle/headers/filter_spec.rb +1 -1
  97. data/spec/lib/castle/headers/format_spec.rb +1 -1
  98. data/spec/lib/castle/ips/extract_spec.rb +1 -1
  99. data/spec/lib/castle/logger_spec.rb +1 -1
  100. data/spec/lib/castle/payload/prepare_spec.rb +1 -1
  101. data/spec/lib/castle/secure_mode_spec.rb +1 -1
  102. data/spec/lib/castle/session_spec.rb +1 -1
  103. data/spec/lib/castle/singleton_configuration_spec.rb +1 -1
  104. data/spec/lib/castle/utils/clean_invalid_chars_spec.rb +1 -1
  105. data/spec/lib/castle/utils/clone_spec.rb +1 -1
  106. data/spec/lib/castle/utils/deep_symbolize_keys_spec.rb +1 -1
  107. data/spec/lib/castle/utils/get_timestamp_spec.rb +1 -1
  108. data/spec/lib/castle/utils/merge_spec.rb +1 -1
  109. data/spec/lib/castle/validators/not_supported_spec.rb +1 -1
  110. data/spec/lib/castle/validators/present_spec.rb +1 -1
  111. data/spec/lib/castle/verdict_spec.rb +1 -1
  112. data/spec/lib/castle/version_spec.rb +1 -1
  113. data/spec/lib/castle/webhooks/verify_spec.rb +1 -1
  114. data/spec/lib/castle_spec.rb +1 -1
  115. data/spec/spec_helper.rb +2 -0
  116. data/spec/support/shared_examples/list_items.rb +52 -0
  117. data/spec/support/shared_examples/lists.rb +45 -0
  118. metadata +87 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9dc06eac5803e36c8576d9938442ba1c1f6bb852420c7a736044127deea50b8
4
- data.tar.gz: 5d89738c670359a0345d51b41d0137d614622002711f20665238a4c289f28bab
3
+ metadata.gz: 6f571bda5aa4075f18ef7c64173155401d822ced4fe66fe7c4ceaf4c7c6c6c6e
4
+ data.tar.gz: 15709ff2d5bbdf57063bdd0c1f3eb492f78beff5b1e2b8c61a848f3a2af1d32d
5
5
  SHA512:
6
- metadata.gz: 118236690b20da223208e043cb4aafea5c1d9870e0d2e44d87106a45122652ca894f8bfbc79bf465e474923a026b9b2253a6c7a1ab2c2f5157b0b21d51459d6c
7
- data.tar.gz: 223933e1de62111635ba5d22fed064541a1d54aee9c9374fc8524a808b27b623245ee0d5240a42d0eff4ac72e214cc4f61ce44bb72f15591d3944790d8bc3e0d
6
+ metadata.gz: 5186002c86cef93deb33c8c03c95ffc81adaa7b59b032a06f2f81ff1423d0cd247d198e0a7fce2a15e2a1ab6a76a986c524644c4f4338be5a7e16ec45ba6cdca
7
+ data.tar.gz: a9c63ce6293981630ed431471ceb0ffb70fe990b68784f70088dba28140a63e7ff012286604d8da9a79f5b93486ba4cb8e3318c93ee3617c29f6f981ef737d86
@@ -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
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)))
@@ -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
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module Commands
5
+ module ListItems
6
+ # Builds the command to query list items
7
+ class Query
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
+ Castle::Validators::Present.call(options[:sort], %i[field order]) if options[:sort]
15
+
16
+ list_id = options.delete(:list_id)
17
+
18
+ Castle::Command.new("lists/#{list_id}/items/query", options, :post)
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
+ # Builds the command to unarchive a list item
7
+ class Unarchive
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}/unarchive", nil, :put)
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 update a list item
7
+ class Update
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 comment])
13
+ list_id = options.delete(:list_id)
14
+ list_item_id = options.delete(:list_item_id)
15
+
16
+ Castle::Command.new("lists/#{list_id}/items/#{list_item_id}", options, :put)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module Commands
5
+ # Commands for lists endpoints
6
+ module Lists
7
+ # Builds the command to create a list
8
+ class Create
9
+ class << self
10
+ # @param options [Hash]
11
+ # @return [Castle::Command]
12
+ def build(options = {})
13
+ Castle::Validators::Present.call(options, %i[name color primary_field])
14
+
15
+ Castle::Command.new('lists', options, :post)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module Commands
5
+ module Lists
6
+ # Builds the command to delete a list
7
+ class Delete
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
+
14
+ Castle::Command.new("lists/#{options[:list_id]}", nil, :delete)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module Commands
5
+ module Lists
6
+ # Builds the command to get a list
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])
13
+
14
+ Castle::Command.new("lists/#{options[:list_id]}", nil, :get)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module Commands
5
+ module Lists
6
+ # Builds the command to get all lists
7
+ class GetAll
8
+ class << self
9
+ # @return [Castle::Command]
10
+ def build
11
+ Castle::Command.new('lists', nil, :get)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end