Skip to content

Commit

Permalink
Merge pull request #224 from ioki-mobility/feature/operator-line
Browse files Browse the repository at this point in the history
  • Loading branch information
rmehner committed May 17, 2023
2 parents 6b057e2 + fe9548c commit 01d4278
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/ioki/apis/operator_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@ class OperatorApi
:area,
base_path: [API_BASE_PATH, 'products', :id],
model_class: Ioki::Model::Operator::Area
),
Endpoints.crud_endpoints(
:line,
base_path: [API_BASE_PATH, 'products', :id],
model_class: Ioki::Model::Operator::Line
),
Endpoints.crud_endpoints(
:line_stop,
base_path: [API_BASE_PATH, 'products', :id, 'lines', :id],
except: [:create, :delete],
model_class: Ioki::Model::Operator::LineStop
)
].freeze
end
Expand Down
21 changes: 21 additions & 0 deletions lib/ioki/model/operator/line.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Ioki
module Model
module Operator
class Line < 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 :name, on: [:read, :create, :update], type: :string
attribute :mode, on: [:read, :create, :update], type: :string
attribute :route_number, on: [:read, :create, :update], type: :string
attribute :skip_time_window_check, on: [:read, :create, :update], type: :boolean
attribute :slug, on: [:read, :create, :update], type: :string
attribute :variant, on: [:read, :create, :update], type: :string
attribute :line_stops, type: :array, on: :read, class_name: 'LineStop'
end
end
end
end
21 changes: 21 additions & 0 deletions lib/ioki/model/operator/line_stop.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Ioki
module Model
module Operator
class LineStop < 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 :tier, on: [:read, :create], type: :integer
attribute :relative_time, on: [:read, :create], type: :integer
attribute :supports_pickup, on: [:read, :create], type: :boolean
attribute :supports_dropoff, on: [:read, :create], type: :boolean
attribute :supports_pass_through, on: [:read, :create], type: :boolean
attribute :station_id, on: [:read, :create], type: :string
attribute :version, on: :read, type: :integer
end
end
end
end
67 changes: 67 additions & 0 deletions spec/ioki/operator_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1082,4 +1082,71 @@
.to be_a(Ioki::Model::Operator::Area)
end
end

describe '#create_line(product_id, line)' do
let(:line) { Ioki::Model::Operator::Line.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/lines')
[result_with_data, full_response]
end

expect(operator_client.create_line('0815', line, options))
.to eq(Ioki::Model::Operator::Line.new)
end
end

describe '#update_line(product_id, line)' do
let(:line) { Ioki::Model::Operator::Line.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/lines/4711')
expect(params[:method]).to eq :patch
[result_with_data, full_response]
end

expect(operator_client.update_line('0815', line, options))
.to eq(Ioki::Model::Operator::Line.new)
end
end

describe '#delete_line(product_id, line_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/lines/4711')
result_with_data
end

expect(operator_client.delete_line('0815', '4711', options))
.to eq(Ioki::Model::Operator::Line.new)
end
end

describe '#create_line_stop(product_id, line_id, line_stop)' do
let(:line_stop) { Ioki::Model::Operator::LineStop.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/lines/0815/line_stops')
[result_with_data, full_response]
end

expect(operator_client.create_line_stop('0815', '0815', line_stop, options))
.to eq(Ioki::Model::Operator::LineStop.new)
end
end

describe '#delete_line_stop(product_id, line_id, line_stop_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/lines/0815/line_stops/4711')
result_with_data
end

expect(operator_client.delete_line_stop('0815', '0815', '4711', options))
.to eq(Ioki::Model::Operator::LineStop.new)
end
end
end

0 comments on commit 01d4278

Please sign in to comment.