Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operator Api | Add RideOptions endpoints #458

Merged
merged 10 commits into from
Nov 25, 2024
5 changes: 5 additions & 0 deletions lib/ioki/apis/operator_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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::RideOptions
tom-ioki marked this conversation as resolved.
Show resolved Hide resolved
)
].freeze
end
Expand Down
91 changes: 83 additions & 8 deletions lib/ioki/model/operator/ride_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,89 @@ module Ioki
module Model
module Operator
class RideOptions < Base
unvalidated true # Specification not available.

attribute :book_for_others, on: :read, type: :boolean
attribute :destination_time_based_matching, on: :read, type: :boolean
attribute :max_wheelchairs, on: :read, type: :integer
attribute :max_walkers, on: :read, type: :integer
attribute :prebooking_threshold, on: :read, type: :object, class_name: 'PrebookingThreshold'
attribute :passengers, on: :read, type: :object, class_name: 'PassengerOptions'
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: [:string, :boolean, :integer]

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 :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
end
end
end
Expand Down
67 changes: 67 additions & 0 deletions spec/ioki/operator_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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::RideOptions))
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::RideOptions)
end
end

describe '#create_ride_option(product_id, ride_option)' do
let(:ride_option) { Ioki::Model::Operator::RideOptions.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::RideOptions)
end
end

describe '#update_ride_option(product_id, ride_option_id, ride_option)' do
let(:ride_option) { Ioki::Model::Operator::RideOptions.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::RideOptions)
end
end

describe '#delete_station(product_id, ride_option_id)' do
tom-ioki marked this conversation as resolved.
Show resolved Hide resolved
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::RideOptions)
end
end
end