Skip to content

Commit

Permalink
Merge pull request #43 from ioki-mobility/platform-model-api-complete…
Browse files Browse the repository at this point in the history
…ness

Add missing platform models and attributes
  • Loading branch information
A5308Y authored Dec 16, 2021
2 parents c4b07aa + 85bf212 commit d7d4595
Show file tree
Hide file tree
Showing 168 changed files with 9,389 additions and 281 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,8 @@ If you would like to make those request with fast predictable results in you tes
expect(client.providers.first.city).to eq('Somewhere')
end
```

### OpenApi specifications

If you're allowed to access the OpenAPI-specifications for the three APIs you can place them in `spec/fixtures/open_api_definitions`. `open_api_spec` will then compare theses specs with the matching models. You can define `specification_scope` on the model to set the prefix the specs are looking for in the OpenApi-schema file and `schema_path` if the name of the schema is not the snake_case version of the class name and define `unvalidated true` to mark that no specification exists for a model.
Sometimes it's also helpful to disable the check for specific attributes. You can pass `unvalidated: true` as an option to the `attribute` definition.
2 changes: 1 addition & 1 deletion lib/ioki/apis/endpoints/endpoints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def self.url_elements(path, *args)
end

unless path.select { |element| element.is_a?(Symbol) }.size <= args.size
raise ArgumentError, 'args: must have an argument for every symbol in :path'
raise ArgumentError, "args: must have an argument for every symbol in :path. path: #{path}, args: #{args}"
end

interpolation_args = path.select { |inner_element| inner_element.is_a?(Symbol) }.zip(args).reverse
Expand Down
76 changes: 76 additions & 0 deletions lib/ioki/apis/platform_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,82 @@ class PlatformApi
base_path: [API_BASE_PATH, 'products', :id],
model_class: Ioki::Model::Platform::DriverVehicleConnection
),
Endpoints::ShowSingular.new(
:client,
base_path: [API_BASE_PATH],
model_class: Ioki::Model::Platform::Client
),
Endpoints::Show.new(
:driver_emergency,
base_path: [API_BASE_PATH, 'products', :id],
model_class: Ioki::Model::Platform::DriverEmergency
),
Endpoints::Index.new(
:driver_emergencies,
base_path: [API_BASE_PATH, 'products', :id],
model_class: Ioki::Model::Platform::DriverEmergency
),
Endpoints.crud_endpoints(
:pause,
base_path: [API_BASE_PATH, 'products', :id, 'task_lists', :id],
except: [:create, :update, :delete],
model_class: Ioki::Model::Platform::Pause
),
Endpoints.crud_endpoints(
:receipt,
base_path: [API_BASE_PATH, 'providers', :id],
except: [:create, :update, :delete],
model_class: Ioki::Model::Platform::Receipt
),
Endpoints.crud_endpoints(
:station_deactivation,
base_path: [API_BASE_PATH, 'products', :id, 'stations', :id],
paths: {
show: 'deactivation',
index: 'deactivations'
},
except: [:create, :update, :delete],
model_class: Ioki::Model::Platform::Deactivation
),
Endpoints.crud_endpoints(
:task_list_deactivation,
base_path: [API_BASE_PATH, 'products', :id, 'task_lists', :id],
paths: {
show: 'deactivation',
index: 'deactivations'
},
except: [:create, :update, :delete],
model_class: Ioki::Model::Platform::Deactivation
),
Endpoints::ShowSingular.new(
:current_journey,
base_path: [API_BASE_PATH, 'products', :id, 'task_lists', :id],
model_class: Ioki::Model::Platform::Journey
),
Endpoints.crud_endpoints(
:task_list,
base_path: [API_BASE_PATH, 'products', :id],
except: [:create, :update, :delete],
model_class: Ioki::Model::Platform::TaskList
),
Endpoints.crud_endpoints(
:task,
base_path: [API_BASE_PATH, 'products', :id, 'task_lists', :id],
except: [:create, :update, :delete],
model_class: Ioki::Model::Platform::Task
),
Endpoints.crud_endpoints(
:service_credit,
base_path: [API_BASE_PATH, 'providers', :id, 'users', :id],
except: [:create, :update, :delete],
model_class: Ioki::Model::Platform::ServiceCredit
),
Endpoints.crud_endpoints(
:webhook,
base_path: [API_BASE_PATH, 'providers', :id],
except: [:create, :update, :delete],
model_class: Ioki::Model::Platform::Webhook
),
Endpoints::Index.new(
:providers,
base_path: [API_BASE_PATH],
Expand Down
42 changes: 12 additions & 30 deletions lib/ioki/model.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,19 @@
# frozen_string_literal: true

require 'ioki/model/base'
require 'ioki/model/driver/base'
require 'ioki/model/driver/driver_request_token'
require 'ioki/model/driver/product'
require 'ioki/model/passenger/base'
require 'ioki/model/passenger/bootstrap'
require 'ioki/model/passenger/cancellation'
require 'ioki/model/passenger/features'
require 'ioki/model/passenger/phone_verification_request'
require 'ioki/model/passenger/product'
require 'ioki/model/passenger/provider'
require 'ioki/model/passenger/ride_inquiry'
require 'ioki/model/passenger/user_phone_number'
require 'ioki/model/platform/area'
require 'ioki/model/platform/base'
require 'ioki/model/platform/booking'
require 'ioki/model/platform/calculated_point'
require 'ioki/model/platform/driver'
require 'ioki/model/platform/driver_vehicle_connection'
require 'ioki/model/platform/passenger_request_token'
require 'ioki/model/platform/payment_method'
require 'ioki/model/platform/product'
require 'ioki/model/platform/provider'
require 'ioki/model/platform/rating'
require 'ioki/model/platform/requested_point'
require 'ioki/model/platform/ride'
require 'ioki/model/platform/ride_inquiry'
require 'ioki/model/platform/ride_passenger'
require 'ioki/model/platform/station'
require 'ioki/model/platform/user'
require 'ioki/model/platform/user_email'
require 'ioki/model/platform/vehicle'
require 'ioki/model/passenger/base'
require 'ioki/model/driver/base'

Dir[File.join(__dir__, 'model', 'platform', '*')].reject do |filename|
filename == File.join(__dir__, 'model', 'platform', 'base.rb')
end.sort.each { |file| require file }
Dir[File.join(__dir__, 'model', 'passenger', '*')].reject do |filename|
filename == File.join(__dir__, 'model', 'passenger', 'base.rb')
end.sort.each { |file| require file }
Dir[File.join(__dir__, 'model', 'driver', '*')].reject do |filename|
filename == File.join(__dir__, 'model', 'driver', 'base.rb')
end.sort.each { |file| require file }

module Ioki
module Model
Expand Down
18 changes: 17 additions & 1 deletion lib/ioki/model/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ def attribute(attribute, definition = {})
end
end

def schema_path
nil
end

def specification_scope
nil
end

def unvalidated(unvalidated = false)
@unvalidated = unvalidated
end

def unvalidated?
@unvalidated
end

def ancestor_model_classes
ancestors.select { |k| k <= Ioki::Model::Base }.reverse
end
Expand All @@ -47,7 +63,7 @@ def attribute_definitions
attr_accessor :_raw_attributes, :_attributes, :_etag

def initialize(raw_attributes = {}, etag = nil)
@_raw_attributes = raw_attributes.transform_keys(&:to_sym)
@_raw_attributes = (raw_attributes || {}).transform_keys(&:to_sym)
@_etag = etag
reset_attributes!
end
Expand Down
11 changes: 11 additions & 0 deletions lib/ioki/model/driver/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@
module Ioki
module Model
module Driver
def self.valid_models
constants.
select { |constant| const_get(constant).is_a?(Class) }.
reject { |constant| const_get(constant).unvalidated? }.
map { |model| const_get(model) } - [Base]
end

class Base < Ioki::Model::Base
def self.specification_scope
'driver_api'
end

attribute :id, on: :read, type: :string
attribute :type, on: :read, type: :string
attribute :created_at, on: :read, type: :date_time
Expand Down
12 changes: 12 additions & 0 deletions lib/ioki/model/driver/cancellation_statement.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module Ioki
module Model
module Driver
class CancellationStatement < Base
attribute :identifier, on: :read, type: :string
attribute :title, on: :read, type: :string
end
end
end
end
7 changes: 5 additions & 2 deletions lib/ioki/model/driver/driver_request_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ module Ioki
module Model
module Driver
class DriverRequestToken < Base
attribute :username, on: :create, type: :string
attribute :pin, on: :create, type: :string
# The model does not return it but it's used when sending data to the server.
attribute :username, on: :create, type: :string, unvalidated: true
# The model does not return it but it's used when sending data to the server.
attribute :pin, on: :create, type: :string, unvalidated: true
attribute :token, on: :read, type: :string
attribute :driver_id, on: :read, type: :string
end
end
end
Expand Down
24 changes: 24 additions & 0 deletions lib/ioki/model/driver/passenger_options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

require 'ioki/model/driver/passenger_type'

module Ioki
module Model
module Driver
class PassengerOptions < Ioki::Model::Base
# Note that this does not inherit from Base because it does not implement :type, :id, :created_at and
# :updated_at.

unvalidated true # Specification not available.

attribute :types, on: :read, type: :array, model_class: PassengerType
attribute :wheelchair, on: :read, type: :boolean
attribute :walker, on: :read, type: :boolean
attribute :public_transport_ticket, on: :read, type: :boolean
attribute :bahncard, on: :read, type: :boolean
attribute :blue_badge, on: :read, type: :boolean
attribute :name_required_if_no_public_transport_ticket, on: :read, type: :boolean
end
end
end
end
16 changes: 16 additions & 0 deletions lib/ioki/model/driver/passenger_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module Ioki
module Model
module Driver
class PassengerType < Ioki::Model::Base
# Note that this does not inherit from Base because it does not implement :type, :id, :created_at and
# :updated_at.

unvalidated true # Specification not available.

attribute :type, on: :read, type: :string
end
end
end
end
17 changes: 17 additions & 0 deletions lib/ioki/model/driver/prebooking_threshold.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module Ioki
module Model
module Driver
class PrebookingThreshold < Ioki::Model::Base
# Note that this does not inherit from Base because it does not implement :type, :id, :created_at and
# :updated_at.

unvalidated true # Specification not available.

attribute :min, on: :read, type: :integer
attribute :max, on: :read, type: :integer
end
end
end
end
5 changes: 5 additions & 0 deletions lib/ioki/model/driver/product.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# frozen_string_literal: true

require 'ioki/model/driver/ride_options'
require 'ioki/model/driver/cancellation_statement'

module Ioki
module Model
module Driver
Expand All @@ -12,6 +15,8 @@ class Product < Base
attribute :drivers_can_pause, on: :read, type: :boolean
attribute :supports_driver_emergency_button, on: :read, type: :boolean
attribute :supports_tipping, on: :read, type: :boolean
attribute :cancellation_statements, on: :read, type: :array, model_class: CancellationStatement
attribute :ride_options, on: :read, type: :object, model_class: RideOptions
end
end
end
Expand Down
24 changes: 24 additions & 0 deletions lib/ioki/model/driver/ride_options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

require 'ioki/model/driver/prebooking_threshold'
require 'ioki/model/driver/passenger_options'

module Ioki
module Model
module Driver
class RideOptions < Ioki::Model::Base
# Note that this does not inherit from Base because it does not implement :type, :id, :created_at and
# :updated_at.

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, model_class: PrebookingThreshold
attribute :passengers, on: :read, type: :object, model_class: PassengerOptions
end
end
end
end
16 changes: 16 additions & 0 deletions lib/ioki/model/passenger/announcement.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module Ioki
module Model
module Passenger
class Announcement < Base
attribute :ends_at, on: :read, type: :date_time
attribute :severity, on: :read, type: :string
attribute :show_on_every_app_start, on: :read, type: :boolean
attribute :starts_at, on: :read, type: :date_time
attribute :text, on: :read, type: :string
attribute :title, on: :read, type: :string
end
end
end
end
16 changes: 16 additions & 0 deletions lib/ioki/model/passenger/area.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module Ioki
module Model
module Passenger
class Area < Ioki::Model::Base
# Note that this does not inherit from Base because :type behaves differently here.

unvalidated true

attribute :coordinates, type: :array, on: :read
attribute :type, type: :string, on: :read
end
end
end
end
20 changes: 20 additions & 0 deletions lib/ioki/model/passenger/assistance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Ioki
module Model
module Passenger
class Assistance < Ioki::Model::Base
# Note that this does not inherit from Base because :created_at, :updated_at and :id are not defined.

def self.schema_path
'passenger_api--ride_inquiry--assistance'
end

attribute :href, on: :read, type: :string
attribute :text, on: :read, type: :string
attribute :title, on: :read, type: :string
attribute :type, on: :read, type: :string
end
end
end
end
Loading

0 comments on commit d7d4595

Please sign in to comment.