Skip to content

Commit

Permalink
Merge pull request #368 from ioki-mobility/operator-api/fleet-state-e…
Browse files Browse the repository at this point in the history
…ndpoint

Operator Api | Add `fleet_state` endpoint
  • Loading branch information
tom-ioki committed Apr 22, 2024
2 parents 33a0984 + 75024f9 commit 9e62d59
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/ioki/apis/operator_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ class OperatorApi
base_path: [API_BASE_PATH, 'products', :id, 'task_lists'],
model_class: Ioki::Model::Operator::TaskList
),
Endpoints::Index.new(
:task_list_overview,
base_path: [API_BASE_PATH, 'products', :id, 'task_lists'],
path: 'overview',
model_class: Ioki::Model::Operator::TaskList
),
Endpoints.custom_endpoints(
'task_lists',
actions: { 'current_journey' => :get },
Expand Down Expand Up @@ -297,6 +303,11 @@ class OperatorApi
actions: { 'rematching_suggestions' => :get },
path: [API_BASE_PATH, 'products', :id, 'task_lists', :id],
model_class: Ioki::Model::Operator::RematchingSuggestion
),
Endpoints::ShowSingular.new(
:fleet_state,
base_path: [API_BASE_PATH],
model_class: Ioki::Model::Operator::FleetState
)
].freeze
end
Expand Down
18 changes: 18 additions & 0 deletions lib/ioki/model/operator/fleet_state.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module Ioki
module Model
module Operator
class FleetState < Base
attribute :type,
on: :read,
type: :string

attribute :vehicles,
on: :read,
type: :array,
class_name: 'Vehicle'
end
end
end
end
4 changes: 4 additions & 0 deletions lib/ioki/model/operator/vehicle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class Vehicle < Base
on: :read,
type: :date_time

attribute :active,
on: :read,
type: :boolean

attribute :autonomous,
on: [:create, :read, :update],
omit_if_nil_on: [:create, :update],
Expand Down
1 change: 1 addition & 0 deletions spec/ioki/model/operator/vehicle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
it { is_expected.to define_attribute(:created_at).as(:date_time) }
it { is_expected.to define_attribute(:updated_at).as(:date_time) }
it { is_expected.to define_attribute(:version).as(:integer) }
it { is_expected.to define_attribute(:active).as(:boolean) }
it { is_expected.to define_attribute(:autonomous).as(:boolean) }
it { is_expected.to define_attribute(:connected_driver_id).as(:string) }

Expand Down
23 changes: 23 additions & 0 deletions spec/ioki/operator_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,18 @@
end
end

describe '#task_list_overview(product_id)' do
it 'calls request on the client with expected params' do
expect(operator_client).to receive(:request) do |params|
expect(params[:url].to_s).to eq('operator/products/0815/task_lists/overview')
[result_with_data, full_response]
end

expect(operator_client.task_list_overview('0815', options))
.to all(be_a(Ioki::Model::Operator::TaskList))
end
end

describe '#pauses(product_id, task_list_id)' do
it 'calls request on the client with expected params' do
expect(operator_client).to receive(:request) do |params|
Expand Down Expand Up @@ -1519,4 +1531,15 @@
.to be_a(Ioki::Model::Operator::RematchingSuggestion)
end
end

describe '#fleet_state' do
it 'calls request on the client with expected params' do
expect(operator_client).to receive(:request) do |params|
expect(params[:url].to_s).to eq('operator/fleet_state')
[result_with_data, full_response]
end

expect(operator_client.fleet_state(options)).to be_a Ioki::Model::Operator::FleetState
end
end
end

0 comments on commit 9e62d59

Please sign in to comment.