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
5 changes: 5 additions & 0 deletions lib/ioki/apis/operator_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,11 @@ class OperatorApi
base_path: [API_BASE_PATH],
model_class: Ioki::Model::Operator::FleetState
),
Endpoints::ShowSingular.new(
:station_state,
base_path: [API_BASE_PATH, 'products', :id],
model_class: Ioki::Model::Operator::StationState
),
Endpoints.crud_endpoints(
:zone,
base_path: [API_BASE_PATH, 'products', :id],
Expand Down
4 changes: 4 additions & 0 deletions lib/ioki/model/operator/station.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class Station < Base
on: :read,
type: :boolean

attribute :active_deactivation_id,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen it in other places as well, and I probably have done it before as well: we are starting to use the same class for different things. The API knows a Station and a StationState::Station, which are different classes. We use the same Station class for both though.

This leads to confusing bugs, where you have a Station object, call active_deactivation_id on it, and it's always nil. You then wonder and eventually figure out that depending on the API you call, different attributes are set. I had this exact flow last week with the User class - the autocomplete endpoint returns different attributes than users#show, but both use the same class.

If I had a wish, it'd be for stronger typing and different classes here 😀

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel you. It didn't feel good to add the active_deactivation_id attribute to the station model. And I agree, I'd prefer different classes as well.

on: :read,
type: :string

attribute :approach,
on: [:read, :create, :update],
type: :string
Expand Down
32 changes: 32 additions & 0 deletions lib/ioki/model/operator/station_state.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

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

attribute :limit_reached,
on: :read,
type: :boolean

attribute :stations,
on: :read,
type: :array,
class_name: 'Station'

attribute :station_categories,
on: :read,
type: :array,
class_name: 'StationCategory'

attribute :station_deactivations,
on: :read,
type: :array,
class_name: 'Deactivation'
end
end
end
end
11 changes: 11 additions & 0 deletions spec/ioki/operator_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3039,4 +3039,15 @@
.to be_a(Ioki::Model::Operator::Purchase)
end
end

describe '#station_state(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/station_state')
[result_with_data, full_response]
end

expect(operator_client.station_state('0815', options)).to be_a Ioki::Model::Operator::StationState
end
end
end