Skip to content
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
2 changes: 2 additions & 0 deletions lib/castle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
castle/context/prepare
castle/commands/identify
castle/commands/authenticate
castle/commands/get_device
castle/commands/get_devices
castle/commands/track
castle/commands/review
Expand All @@ -35,6 +36,7 @@
castle/api/track
castle/api/review
castle/api/impersonate
castle/api/get_device
castle/api/get_devices
castle/payload/prepare
castle/configuration
Expand Down
22 changes: 22 additions & 0 deletions lib/castle/api/get_device.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

module Castle
module API
# Sends GET devices/#{device_token} request
module GetDevice
class << self
# @param options [Hash]
# return [Hash]
def call(options = {})
options = Castle::Utils::DeepSymbolizeKeys.call(options || {})

Castle::API.call(
Castle::Commands::GetDevice.build(options),
{},
options[:http]
)
end
end
end
end
end
21 changes: 21 additions & 0 deletions lib/castle/commands/get_device.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Castle
module Commands
# Generated the payload for the GET devices/#{device_token} request
class GetDevice
class << self
# @param options [Hash]
# @return [Castle::Command]
def build(options = {})
Castle::Validators::Present.call(options, %i[device_token])
Castle::Command.new(
"devices/#{options[:device_token]}",
nil,
:get
)
end
end
end
end
end
19 changes: 19 additions & 0 deletions spec/lib/castle/api/get_device_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

describe Castle::API::GetDevice do
before do
stub_request(:any, /api.castle.io/).with(
basic_auth: ['', 'secret']
).to_return(status: 200, body: '{}', headers: {})
end

describe '.call' do
subject(:retrieve) { described_class.call(device_token: device_token) }

let(:device_token) { '1234' }

before { retrieve }

it { assert_requested :get, "https://api.castle.io/v1/devices/#{device_token}", times: 1 }
end
end
24 changes: 24 additions & 0 deletions spec/lib/castle/commands/get_device_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

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

let(:context) { {} }
let(:device_token) { '1234' }

describe '.build' do
subject(:command) { instance.build(device_token: device_token) }

context 'without device_token' do
let(:device_token) { '' }

it { expect { command }.to raise_error(Castle::InvalidParametersError) }
end

context 'with device_token' do
it { expect(command.method).to be_eql(:get) }
it { expect(command.path).to be_eql("devices/#{device_token}") }
it { expect(command.data).to be_nil }
end
end
end