Skip to content

Commit

Permalink
Merge pull request #458 from ioki-mobility/ride-options
Browse files Browse the repository at this point in the history
Operator Api | Add `RideOptions` endpoints
  • Loading branch information
tom-ioki authored Nov 25, 2024
2 parents 11dca9d + c710e6a commit 5c1c1ab
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 3 deletions.
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::RideOption
)
].freeze
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/ioki/model/operator/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
102 changes: 102 additions & 0 deletions lib/ioki/model/operator/ride_option.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion spec/ioki/model/operator/product_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
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::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

0 comments on commit 5c1c1ab

Please sign in to comment.