From e66dac0f34ba85d12b152abc674293da9bc5acd2 Mon Sep 17 00:00:00 2001 From: Tobias Matz Date: Fri, 5 Jul 2024 10:28:51 +0200 Subject: [PATCH 1/6] Add custom endpoints areas --- lib/ioki/apis/operator_api.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/ioki/apis/operator_api.rb b/lib/ioki/apis/operator_api.rb index 083f5983..c32a5d20 100644 --- a/lib/ioki/apis/operator_api.rb +++ b/lib/ioki/apis/operator_api.rb @@ -227,6 +227,15 @@ class OperatorApi base_path: [API_BASE_PATH, 'products', :id], model_class: Ioki::Model::Operator::Area ), + Endpoints.custom_endpoints( + 'areas', + actions: { + 'drt_area' => :get, + 'intermodal_area' => :get + }, + path: [API_BASE_PATH, 'products', :id], + model_class: Ioki::Model::Operator::Area + ), Endpoints.crud_endpoints( :line, base_path: [API_BASE_PATH, 'products', :id], From a662cc9cbd1117ffa90c7bf55e7048379cddbae0 Mon Sep 17 00:00:00 2001 From: Tobias Matz Date: Fri, 5 Jul 2024 10:40:35 +0200 Subject: [PATCH 2/6] Add specs --- spec/ioki/operator_api_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/ioki/operator_api_spec.rb b/spec/ioki/operator_api_spec.rb index 6abf9b50..e57e6fba 100644 --- a/spec/ioki/operator_api_spec.rb +++ b/spec/ioki/operator_api_spec.rb @@ -1609,4 +1609,28 @@ .to be_a(Ioki::Model::Operator::Zone) end end + + describe '#areas_drt_area(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/drt_area') + [result_with_data, full_response] + end + + expect(operator_client.areas_drt_area('0815', options)) + .to be_a(Ioki::Model::Operator::Area) + end + end + + describe '#areas_intermodal_area(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/intermodal_area') + [result_with_data, full_response] + end + + expect(operator_client.areas_intermodal_area('0815', options)) + .to be_a(Ioki::Model::Operator::Area) + end + end end From 6eef00f3ff19187ab3ad4035401df7978d8d161f Mon Sep 17 00:00:00 2001 From: Tobias Matz Date: Mon, 8 Jul 2024 10:33:36 +0200 Subject: [PATCH 3/6] Refine area model --- lib/ioki/model/operator/area.rb | 87 ++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 19 deletions(-) diff --git a/lib/ioki/model/operator/area.rb b/lib/ioki/model/operator/area.rb index 79de5361..8360f794 100644 --- a/lib/ioki/model/operator/area.rb +++ b/lib/ioki/model/operator/area.rb @@ -21,47 +21,96 @@ class Area < Base type: :date_time attribute :name, - type: :string, on: [:create, :read, :update], - omit_if_nil_on: [:create, :update] + omit_if_nil_on: [:create, :update], + type: :string attribute :slug, - type: :string, on: [:create, :read, :update], - omit_if_nil_on: [:create, :update] + omit_if_nil_on: [:create, :update], + type: :string attribute :area_type, - type: :string, on: [:create, :read, :update], - omit_if_nil_on: [:create, :update] + omit_if_nil_on: [:create, :update], + type: :string attribute :description, - type: :string, - on: [:create, :read, :update] + on: [:create, :read, :update], + type: :string attribute :color, - type: :string, on: [:create, :read, :update], - omit_if_nil_on: [:create, :update] + omit_if_nil_on: [:create, :update], + type: :string + + attribute :opacity, + on: [:create, :read, :update], + omit_if_nil_on: [:create, :update], + type: :float + + attribute :stroke_weight, + on: [:create, :read, :update], + omit_if_nil_on: [:create, :update], + type: :integer + + attribute :fill_color, + on: [:create, :read, :upate], + omit_if_nil_on: [:create, :update], + type: :string + + attribute :fill_opacity, + on: [:create, :read, :upate], + omit_if_nil_on: [:create, :update], + type: :float + + attribute :invert, + on: [:create, :read, :upate], + omit_if_nil_on: [:create, :update], + type: :boolean + + attribute :z_index, + on: [:create, :read, :upate], + omit_if_nil_on: [:create, :update], + type: :integer + + attribute :legend_index, + on: [:create, :read, :upate], + omit_if_nil_on: [:create, :update], + type: :integer + + attribute :legend_title, + on: :read, + type: :string + + attribute :legend_description, + on: :read, + type: :string + + attribute :legend_title_translations, + on: :read, + type: :object, + class_name: 'MultilanguageString' - attribute :area, + attribute :legend_description_translations, on: :read, type: :object, - class_name: 'Geojson' + class_name: 'MultilanguageString' - attribute :inverted_area, + attribute :bounding_box, on: :read, type: :object, - class_name: 'Geojson' + class_name: 'BoundingBox' attribute :area_geojson, - on: [:create, :update], - type: :string + on: [:create, :read, :update], + omit_if_nil_on: [:create, :update], + type: :object, + class_name: 'Geojson' attribute :product_id, - type: :string, - on: [:create, :read, :update], - omit_if_nil_on: [:create, :update] + on: :read, + type: :string end end end From 18c625230d76dad21ca7627ae75bc42fbd141a44 Mon Sep 17 00:00:00 2001 From: Tobias Matz Date: Tue, 9 Jul 2024 10:49:37 +0200 Subject: [PATCH 4/6] Fix failing spec --- lib/ioki/model/operator/area.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/ioki/model/operator/area.rb b/lib/ioki/model/operator/area.rb index 8360f794..6081934f 100644 --- a/lib/ioki/model/operator/area.rb +++ b/lib/ioki/model/operator/area.rb @@ -55,27 +55,27 @@ class Area < Base type: :integer attribute :fill_color, - on: [:create, :read, :upate], + on: [:create, :read, :update], omit_if_nil_on: [:create, :update], type: :string attribute :fill_opacity, - on: [:create, :read, :upate], + on: [:create, :read, :update], omit_if_nil_on: [:create, :update], type: :float attribute :invert, - on: [:create, :read, :upate], + on: [:create, :read, :update], omit_if_nil_on: [:create, :update], type: :boolean attribute :z_index, - on: [:create, :read, :upate], + on: [:create, :read, :update], omit_if_nil_on: [:create, :update], type: :integer attribute :legend_index, - on: [:create, :read, :upate], + on: [:create, :read, :update], omit_if_nil_on: [:create, :update], type: :integer From d58371c69da885d99c6a0c1208fae2b942616781 Mon Sep 17 00:00:00 2001 From: Tobias Matz Date: Tue, 9 Jul 2024 18:57:07 +0200 Subject: [PATCH 5/6] Remove product_id from area model --- lib/ioki/model/operator/area.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/ioki/model/operator/area.rb b/lib/ioki/model/operator/area.rb index 6081934f..f7c35f0d 100644 --- a/lib/ioki/model/operator/area.rb +++ b/lib/ioki/model/operator/area.rb @@ -107,10 +107,6 @@ class Area < Base omit_if_nil_on: [:create, :update], type: :object, class_name: 'Geojson' - - attribute :product_id, - on: :read, - type: :string end end end From a753d3195e45c75547b946053be0470d31eff104 Mon Sep 17 00:00:00 2001 From: Tobias Matz Date: Wed, 10 Jul 2024 09:05:55 +0200 Subject: [PATCH 6/6] Adjust endpoints for drt_area and intermodal_area --- lib/ioki/apis/operator_api.rb | 15 ++++++++------- spec/ioki/operator_api_spec.rb | 8 ++++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/ioki/apis/operator_api.rb b/lib/ioki/apis/operator_api.rb index c32a5d20..f4513512 100644 --- a/lib/ioki/apis/operator_api.rb +++ b/lib/ioki/apis/operator_api.rb @@ -227,13 +227,14 @@ class OperatorApi base_path: [API_BASE_PATH, 'products', :id], model_class: Ioki::Model::Operator::Area ), - Endpoints.custom_endpoints( - 'areas', - actions: { - 'drt_area' => :get, - 'intermodal_area' => :get - }, - path: [API_BASE_PATH, 'products', :id], + Endpoints::ShowSingular.new( + :drt_area, + base_path: [API_BASE_PATH, 'products', :id], + model_class: Ioki::Model::Operator::Area + ), + Endpoints::ShowSingular.new( + :intermodal_area, + base_path: [API_BASE_PATH, 'products', :id], model_class: Ioki::Model::Operator::Area ), Endpoints.crud_endpoints( diff --git a/spec/ioki/operator_api_spec.rb b/spec/ioki/operator_api_spec.rb index e57e6fba..e92fcaa3 100644 --- a/spec/ioki/operator_api_spec.rb +++ b/spec/ioki/operator_api_spec.rb @@ -1610,26 +1610,26 @@ end end - describe '#areas_drt_area(product_id)' do + describe '#drt_area(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/drt_area') [result_with_data, full_response] end - expect(operator_client.areas_drt_area('0815', options)) + expect(operator_client.drt_area('0815', options)) .to be_a(Ioki::Model::Operator::Area) end end - describe '#areas_intermodal_area(product_id)' do + describe '#intermodal_area(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/intermodal_area') [result_with_data, full_response] end - expect(operator_client.areas_intermodal_area('0815', options)) + expect(operator_client.intermodal_area('0815', options)) .to be_a(Ioki::Model::Operator::Area) end end