Skip to content

Commit

Permalink
Add support for Lists API (#272)
Browse files Browse the repository at this point in the history
* Add list commands

* Add list item commands && update castle required files

* update specs and add list_item/count and list/all commands

* Add list & list_item apis and tests

* Add client actions for list and list item apis

* Pluralize list & list item namespaces and add client specs for added actions

* Rename lists/all to lists/get_all

* Update lib/castle/client_actions/list_items.rb

Co-authored-by: Igor Pstyga <[email protected]>

* update client action calls to have option signature of apis called

---------

Co-authored-by: Igor Pstyga <[email protected]>
  • Loading branch information
andymond and opti authored Oct 31, 2024
1 parent 743adff commit b1d3425
Show file tree
Hide file tree
Showing 59 changed files with 1,292 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/castle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@
castle/commands/risk
castle/commands/start_impersonation
castle/commands/track
castle/commands/lists/get_all
castle/commands/lists/create
castle/commands/lists/delete
castle/commands/lists/get
castle/commands/lists/query
castle/commands/lists/update
castle/commands/list_items/archive
castle/commands/list_items/create
castle/commands/list_items/count
castle/commands/list_items/get
castle/commands/list_items/query
castle/commands/list_items/unarchive
castle/commands/list_items/update
castle/api/approve_device
castle/api/authenticate
castle/api/end_impersonation
Expand All @@ -42,12 +55,27 @@
castle/api/risk
castle/api/start_impersonation
castle/api/track
castle/api/lists/get_all
castle/api/lists/create
castle/api/lists/delete
castle/api/lists/get
castle/api/lists/query
castle/api/lists/update
castle/api/list_items/archive
castle/api/list_items/create
castle/api/list_items/count
castle/api/list_items/get
castle/api/list_items/query
castle/api/list_items/unarchive
castle/api/list_items/update
castle/payload/prepare
castle/configuration
castle/singleton_configuration
castle/logger
castle/failover/prepare_response
castle/failover/strategy
castle/client_actions/lists
castle/client_actions/list_items
castle/client
castle/headers/filter
castle/headers/format
Expand Down
21 changes: 21 additions & 0 deletions lib/castle/api/list_items/archive.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Castle
module API
module ListItems
module Archive
class << self
# @param options [Hash]
# return [Hash]
def call(options = {})
options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
http = options.delete(:http)
config = options.delete(:config) || Castle.config

Castle::API.call(Castle::Commands::ListItems::Archive.build(options), {}, http, config)
end
end
end
end
end
end
21 changes: 21 additions & 0 deletions lib/castle/api/list_items/count.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Castle
module API
module ListItems
module Count
class << self
# @param options [Hash]
# return [Hash]
def call(options = {})
options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
http = options.delete(:http)
config = options.delete(:config) || Castle.config

Castle::API.call(Castle::Commands::ListItems::Count.build(options), {}, http, config)
end
end
end
end
end
end
21 changes: 21 additions & 0 deletions lib/castle/api/list_items/create.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Castle
module API
module ListItems
module Create
class << self
# @param options [Hash]
# return [Hash]
def call(options = {})
options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
http = options.delete(:http)
config = options.delete(:config) || Castle.config

Castle::API.call(Castle::Commands::ListItems::Create.build(options), {}, http, config)
end
end
end
end
end
end
21 changes: 21 additions & 0 deletions lib/castle/api/list_items/get.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Castle
module API
module ListItems
module Get
class << self
# @param options [Hash]
# return [Hash]
def call(options = {})
options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
http = options.delete(:http)
config = options.delete(:config) || Castle.config

Castle::API.call(Castle::Commands::ListItems::Get.build(options), {}, http, config)
end
end
end
end
end
end
21 changes: 21 additions & 0 deletions lib/castle/api/list_items/query.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Castle
module API
module ListItems
module Query
class << self
# @param options [Hash]
# return [Hash]
def call(options = {})
options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
http = options.delete(:http)
config = options.delete(:config) || Castle.config

Castle::API.call(Castle::Commands::ListItems::Query.build(options), {}, http, config)
end
end
end
end
end
end
21 changes: 21 additions & 0 deletions lib/castle/api/list_items/unarchive.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Castle
module API
module ListItems
module Unarchive
class << self
# @param options [Hash]
# return [Hash]
def call(options = {})
options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
http = options.delete(:http)
config = options.delete(:config) || Castle.config

Castle::API.call(Castle::Commands::ListItems::Unarchive.build(options), {}, http, config)
end
end
end
end
end
end
21 changes: 21 additions & 0 deletions lib/castle/api/list_items/update.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Castle
module API
module ListItems
module Update
class << self
# @param options [Hash]
# return [Hash]
def call(options = {})
options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
http = options.delete(:http)
config = options.delete(:config) || Castle.config

Castle::API.call(Castle::Commands::ListItems::Update.build(options), {}, http, config)
end
end
end
end
end
end
21 changes: 21 additions & 0 deletions lib/castle/api/lists/create.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Castle
module API
module Lists
module Create
class << self
# @param options [Hash]
# return [Hash]
def call(options = {})
options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
http = options.delete(:http)
config = options.delete(:config) || Castle.config

Castle::API.call(Castle::Commands::Lists::Create.build(options), {}, http, config)
end
end
end
end
end
end
21 changes: 21 additions & 0 deletions lib/castle/api/lists/delete.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Castle
module API
module Lists
module Delete
class << self
# @param options [Hash]
# return [Hash]
def call(options = {})
options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
http = options.delete(:http)
config = options.delete(:config) || Castle.config

Castle::API.call(Castle::Commands::Lists::Delete.build(options), {}, http, config)
end
end
end
end
end
end
21 changes: 21 additions & 0 deletions lib/castle/api/lists/get.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Castle
module API
module Lists
module Get
class << self
# @param options [Hash]
# return [Hash]
def call(options = {})
options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
http = options.delete(:http)
config = options.delete(:config) || Castle.config

Castle::API.call(Castle::Commands::Lists::Get.build(options), {}, http, config)
end
end
end
end
end
end
21 changes: 21 additions & 0 deletions lib/castle/api/lists/get_all.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Castle
module API
module Lists
module GetAll
class << self
# @param options [Hash]
# return [Hash]
def call(options = {})
options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
http = options.delete(:http)
config = options.delete(:config) || Castle.config

Castle::API.call(Castle::Commands::Lists::GetAll.build, {}, http, config)
end
end
end
end
end
end
21 changes: 21 additions & 0 deletions lib/castle/api/lists/query.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Castle
module API
module Lists
module Query
class << self
# @param options [Hash]
# return [Hash]
def call(options = {})
options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
http = options.delete(:http)
config = options.delete(:config) || Castle.config

Castle::API.call(Castle::Commands::Lists::Query.build(options), {}, http, config)
end
end
end
end
end
end
21 changes: 21 additions & 0 deletions lib/castle/api/lists/update.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Castle
module API
module Lists
module Update
class << self
# @param options [Hash]
# return [Hash]
def call(options = {})
options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
http = options.delete(:http)
config = options.delete(:config) || Castle.config

Castle::API.call(Castle::Commands::Lists::Update.build(options), {}, http, config)
end
end
end
end
end
end
3 changes: 3 additions & 0 deletions lib/castle/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
module Castle
# Castle's client.
class Client
include Castle::ClientActions::ListItems
include Castle::ClientActions::Lists

class << self
def from_request(request, options = {})
new(options.merge(context: Castle::Context::Prepare.call(request, options)))
Expand Down
34 changes: 34 additions & 0 deletions lib/castle/client_actions/list_items.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true
module Castle
module ClientActions
module ListItems
def archive_list_item(options = {})
Castle::API::ListItems::Archive.call(options)
end

def count_list_items(options = {})
Castle::API::ListItems::Count.call(options)
end

def create_list_item(options = {})
Castle::API::ListItems::Create.call(options)
end

def get_list_item(options = {})
Castle::API::ListItems::Get.call(options)
end

def query_list_items(options = {})
Castle::API::ListItems::Query.call(options)
end

def unarchive_list_item(options)
Castle::API::ListItems::Unarchive.call(options)
end

def update_list_item(options = {})
Castle::API::ListItems::Update.call(options)
end
end
end
end
Loading

0 comments on commit b1d3425

Please sign in to comment.