Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the docs and rename the command #227

Merged
merged 4 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,40 @@ end

List of Recognized Events can be found [here](https://github.com/castle/castle-ruby/tree/master/lib/castle/events.rb) or in the [docs](https://docs.castle.io/api_reference/#list-of-recognized-events)

## Device management

This SDK allows issuing requests to [Castle's Device Management Endpoints](https://docs.castle.io/device_management_tool/). Use these endpoints for admin-level management of end-user devices (i.e., for an internal dashboard).

Fetching device data, approving a device, reporting a device requires a valid `device_token`.

```ruby
# Get device data
::Castle::API::GetDevice.call(device_token: device_token)
# Approve a device
::Castle::API::ApproveDevice.call(device_token: device_token)
# Report a device
::Castle::API::ReportDevice.call(device_token: device_token)
```

#### castle_device_reporting_worker.rb

```ruby
class CastleDeviceReportingWorker
include Sidekiq::Worker

def perform(device_token)
::Castle::API::ReportDevice.call(device_token: device_token)
end
end
```

Fetching available devices that belong to a given user requires a valid `user_id`.

```ruby
# Get user's devices data
::Castle::API::GetDevicesForUser.call(user_id: user.id)
```

## Impersonation mode

https://castle.io/docs/impersonation_mode
Expand Down
4 changes: 2 additions & 2 deletions lib/castle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
castle/commands/approve_device
castle/commands/authenticate
castle/commands/get_device
castle/commands/get_devices
castle/commands/get_devices_for_user
castle/commands/identify
castle/commands/impersonate
castle/commands/report_device
Expand All @@ -36,7 +36,7 @@
castle/api/approve_device
castle/api/authenticate
castle/api/get_device
castle/api/get_devices
castle/api/get_devices_for_user
castle/api/identify
castle/api/impersonate
castle/api/report_device
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
module Castle
module API
# Sends GET users/#{user_id}/devices request
module GetDevices
module GetDevicesForUser
class << self
# @param options [Hash]
# return [Hash]
def call(options = {})
options = Castle::Utils::DeepSymbolizeKeys.call(options || {})

Castle::API.call(
Castle::Commands::GetDevices.build(options),
Castle::Commands::GetDevicesForUser.build(options),
{},
options[:http]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Castle
module Commands
# Generated the payload for the GET users/#{user_id}/devices request
class GetDevices
class GetDevicesForUser
class << self
# @param options [Hash]
# @return [Castle::Command]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

describe Castle::API::GetDevices do
describe Castle::API::GetDevicesForUser do
before do
stub_request(:any, /api.castle.io/).with(
basic_auth: ['', 'secret']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

describe Castle::Commands::GetDevices do
describe Castle::Commands::GetDevicesForUser do
subject(:instance) { described_class }

let(:context) { {} }
Expand Down