diff --git a/lib/ioki/apis/operator_api.rb b/lib/ioki/apis/operator_api.rb index 93544663..1502f6b5 100644 --- a/lib/ioki/apis/operator_api.rb +++ b/lib/ioki/apis/operator_api.rb @@ -370,6 +370,11 @@ class OperatorApi :cancellation_statement, base_path: [API_BASE_PATH, 'products', :id], model_class: Ioki::Model::Operator::CancellationStatement + ), + Endpoints.crud_endpoints( + :ride_option, + base_path: [API_BASE_PATH, 'products', :id], + model_class: Ioki::Model::Operator::RideOption ) ].freeze end diff --git a/lib/ioki/model/operator/ride_options.rb b/lib/ioki/model/operator/legacy_ride_options.rb similarity index 94% rename from lib/ioki/model/operator/ride_options.rb rename to lib/ioki/model/operator/legacy_ride_options.rb index 1163ddf0..7948ab28 100644 --- a/lib/ioki/model/operator/ride_options.rb +++ b/lib/ioki/model/operator/legacy_ride_options.rb @@ -3,7 +3,7 @@ module Ioki module Model module Operator - class RideOptions < Base + class LegacyRideOptions < Base unvalidated true # Specification not available. attribute :book_for_others, on: :read, type: :boolean diff --git a/lib/ioki/model/operator/product.rb b/lib/ioki/model/operator/product.rb index ad552205..38cf9205 100644 --- a/lib/ioki/model/operator/product.rb +++ b/lib/ioki/model/operator/product.rb @@ -114,7 +114,7 @@ class Product < Base attribute :ride_options, on: :read, type: :object, - class_name: 'RideOptions' + class_name: 'LegacyRideOptions' attribute :ride_rating_criteria, on: :read, diff --git a/lib/ioki/model/operator/ride_option.rb b/lib/ioki/model/operator/ride_option.rb new file mode 100644 index 00000000..aed882e2 --- /dev/null +++ b/lib/ioki/model/operator/ride_option.rb @@ -0,0 +1,102 @@ +# frozen_string_literal: true + +module Ioki + module Model + module Operator + class RideOption < Base + attribute :type, + on: :read, + type: :string + + attribute :id, + on: :read, + type: :string + + attribute :created_at, + on: :read, + type: :date_time + + attribute :updated_at, + on: :read, + type: :date_time + + attribute :slug, + on: [:read, :create], + type: :string + + attribute :default_value, + on: [:read, :create, :update], + type: [:boolean, :integer, :string] + + attribute :bookable, + on: [:read, :create, :update], + type: :boolean + + attribute :data_type, + on: [:read, :create], + type: :string + + attribute :option_type, + on: [:read, :create, :update], + type: :string + + attribute :sort_key, + on: [:read, :create, :update], + type: :integer + + attribute :localized_accessibility_information, + on: :read, + type: :string + + attribute :localized_name, + on: :read, + type: :string + + attribute :localized_description, + on: :read, + type: :string + + attribute :localized_info, + on: :read, + type: :string + + attribute :localized_link, + on: :read, + type: :string + + attribute :localized_link_text, + on: :read, + type: :string + + attribute :accessibility_information_translations, + on: [:read, :create, :update], + type: :object + + attribute :name_translations, + on: [:read, :create, :update], + type: :object + + attribute :description_translations, + on: [:read, :create, :update], + type: :object + + attribute :info_translations, + on: [:read, :create, :update], + type: :object + + attribute :link_translations, + on: [:read, :create, :update], + type: :object + + attribute :link_text_translations, + on: [:read, :create, :update], + type: :object + + attribute :resource_consumption, + on: [:read, :create, :update], + type: :object, + class_name: 'ResourceConfiguration' + end + end + end +end diff --git a/spec/ioki/model/operator/product_spec.rb b/spec/ioki/model/operator/product_spec.rb index 15f6ee1d..63346e2d 100644 --- a/spec/ioki/model/operator/product_spec.rb +++ b/spec/ioki/model/operator/product_spec.rb @@ -32,7 +32,7 @@ it { is_expected.to define_attribute(:parking_time).as(:integer) } it { is_expected.to define_attribute(:prebookable).as(:boolean) } it { is_expected.to define_attribute(:product_login_slug).as(:string) } - it { is_expected.to define_attribute(:ride_options).as(:object).with(class_name: 'RideOptions') } + it { is_expected.to define_attribute(:ride_options).as(:object).with(class_name: 'LegacyRideOptions') } it { is_expected.to define_attribute(:ride_rating_criteria).as(:array) } it { is_expected.to define_attribute(:service_time_info).as(:string) } it { is_expected.to define_attribute(:state).as(:string) } diff --git a/spec/ioki/operator_api_spec.rb b/spec/ioki/operator_api_spec.rb index f51cd779..49301c93 100644 --- a/spec/ioki/operator_api_spec.rb +++ b/spec/ioki/operator_api_spec.rb @@ -1775,4 +1775,71 @@ .to be_a(Ioki::Model::Operator::CancellationStatement) end end + + describe '#ride_options(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/ride_options') + result_with_index_data + end + + expect(operator_client.ride_options('0815', options)) + .to all(be_a(Ioki::Model::Operator::RideOption)) + end + end + + describe '#ride_option(product_id, ride_option_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/ride_options/4711') + [result_with_data, full_response] + end + + expect(operator_client.ride_option('0815', '4711', options)) + .to be_a(Ioki::Model::Operator::RideOption) + end + end + + describe '#create_ride_option(product_id, ride_option)' do + let(:ride_option) { Ioki::Model::Operator::RideOption.new({ id: '4711' }) } + + 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/ride_options') + expect(params[:method]).to eq(:post) + [result_with_data, full_response] + end + + expect(operator_client.create_ride_option('0815', ride_option, options)) + .to be_a(Ioki::Model::Operator::RideOption) + end + end + + describe '#update_ride_option(product_id, ride_option_id, ride_option)' do + let(:ride_option) { Ioki::Model::Operator::RideOption.new({ id: '4711' }) } + + 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/ride_options/4711') + expect(params[:method]).to eq(:patch) + [result_with_data, full_response] + end + + expect(operator_client.update_ride_option('0815', '4711', ride_option, options)) + .to be_a(Ioki::Model::Operator::RideOption) + end + end + + describe '#delete_ride_option(product_id, ride_option_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/ride_options/4711') + expect(params[:method]).to eq(:delete) + result_with_data + end + + expect(operator_client.delete_ride_option('0815', '4711', options)) + .to be_a(Ioki::Model::Operator::RideOption) + end + end end