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

Platform API | Add drt_area and intermodal_area #365

Merged
merged 3 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/ioki/apis/platform_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,16 @@ class PlatformApi
except: [:index, :show, :update, :delete],
paths: { create: 'email_deliveries' },
model_class: Ioki::Model::Platform::EmailDelivery
),
Endpoints::ShowSingular.new(
:drt_area,
base_path: [API_BASE_PATH, 'products', :id],
model_class: Ioki::Model::Platform::Area
),
Endpoints::ShowSingular.new(
:intermodal_area,
base_path: [API_BASE_PATH, 'products', :id],
model_class: Ioki::Model::Platform::Area
)
].freeze
end
Expand Down
24 changes: 20 additions & 4 deletions lib/ioki/model/platform/area.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,26 @@ module Ioki
module Model
module Platform
class Area < Base
unvalidated true

attribute :coordinates, type: :array, on: :read
attribute :type, type: :string, on: :read
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, :update], type: :string
attribute :slug, on: [:read, :update], type: :string
attribute :area_type, on: [:read, :create], type: :string
attribute :description, on: [:read, :update], type: :string
attribute :color, on: [:read, :update], type: :string
attribute :opacity, on: :read, type: :float
attribute :stroke_weight, on: :read, type: :integer
attribute :fill_color, on: :read, type: :string
attribute :fill_opacity, on: :read, type: :float
attribute :invert, on: :read, type: :boolean
attribute :z_index, on: :read, type: :integer
attribute :legend_index, on: :read, type: :integer
attribute :legend_title, on: :read, type: :string
attribute :legend_description, on: :read, type: :string
attribute :product_id, on: :read, type: :string
attribute :area_geojson, on: [:read, :update], type: :object, class_name: 'GeoJson'
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ioki/model/platform/constraints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Constraints < Base
attribute :max_wheelchairs, on: :read, type: :integer
attribute :max_walkers, on: :read, type: :integer
attribute :max_storage_spaces, on: :read, type: :integer
attribute :area, on: :read, type: :object, class_name: 'Area'
attribute :area, on: :read, type: :object, class_name: 'GeoJson'
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions lib/ioki/model/platform/geo_json.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module Ioki
module Model
module Platform
class GeoJson < Base
attribute :coordinates, type: :array, on: :read
attribute :type, type: :string, on: :read
end
end
end
end
2 changes: 1 addition & 1 deletion lib/ioki/model/platform/matching_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MatchingConfiguration < Base
attribute :id, on: :read, type: :string
attribute :created_at, on: :read, type: :date_time
attribute :updated_at, on: :read, type: :date_time
attribute :area, on: :read, type: :object, class_name: 'Area'
attribute :area, on: :read, type: :object, class_name: 'GeoJson'
attribute :name, on: :read, type: :string
attribute :slug, on: :read, type: :string
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ioki/model/platform/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Product < Base
attribute :vehicles_planning_url, on: :read, type: :string
attribute :announcement, on: :read, type: :object, class_name: 'Announcement'
attribute :announcements, on: :read, type: :array, class_name: 'Announcement'
attribute :area, type: :object, on: :read, class_name: 'Area'
deprecated_attribute :area, type: :object, on: :read, class_name: 'GeoJson'
attribute :bounding_box, on: :read, type: :object, class_name: 'BoundingBox'
attribute :features, on: :read, type: :object, class_name: 'ProductFeatures'
attribute :driver_cancellation_statements, on: :read, type: :array, class_name: 'CancellationStatement'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe Ioki::Model::Platform::Area, :vcr do
RSpec.describe Ioki::Model::Platform::GeoJson, :vcr do
setup_platform_client(:platform_client)
let(:product) { platform_client.products.first }

Expand Down
24 changes: 24 additions & 0 deletions spec/ioki/platform_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -899,4 +899,28 @@
.to be_a(Ioki::Model::Platform::EmailDelivery)
end
end

describe '#drt_area(product_id)' do
it 'calls request on the client with expected params' do
expect(platform_client).to receive(:request) do |params|
expect(params[:url].to_s).to eq('platform/products/0815/drt_area')
[result_with_data, full_response]
end

expect(platform_client.drt_area('0815', options))
.to be_a(Ioki::Model::Platform::Area)
end
end

describe '#intermodal_area(product_id)' do
it 'calls request on the client with expected params' do
expect(platform_client).to receive(:request) do |params|
expect(params[:url].to_s).to eq('platform/products/0815/intermodal_area')
[result_with_data, full_response]
end

expect(platform_client.intermodal_area('0815', options))
.to be_a(Ioki::Model::Platform::Area)
end
end
end