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

Change notification settings to new API #181

Merged
merged 1 commit into from
Jan 31, 2023
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
7 changes: 6 additions & 1 deletion lib/ioki/apis/endpoints/show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ def call(client, args = [], options = {})
# :show can optionally use the model for caching.
model = options[:model] if options[:model].is_a?(model_class)
attributes, etag = model_params(client, args, options, model)
model_class.new(attributes, etag)

if model_class == Array
attributes
else
model_class.new(attributes, etag)
end
end

private
Expand Down
14 changes: 7 additions & 7 deletions lib/ioki/apis/passenger_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,25 @@ class PassengerApi
:notification_settings,
path: 'notification_settings',
base_path: [API_BASE_PATH],
model_class: Ioki::Model::Passenger::NotificationSettings
model_class: Array
),
Endpoints::ShowSingular.new(
:default_notification_settings,
path: %w[passenger notification_settings defaults],
base_path: [API_BASE_PATH],
model_class: Ioki::Model::Passenger::NotificationSettings
model_class: Array
),
Endpoints::ShowSingular.new(
:available_notification_settings,
path: %w[passenger notification_settings available],
base_path: [API_BASE_PATH],
model_class: Ioki::Model::Passenger::NotificationSettings
model_class: Array
),
Endpoints::UpdateSingular.new(
:notification_settings,
path: 'notification_settings',
Endpoints.crud_endpoints(
:notification_setting,
base_path: [API_BASE_PATH],
model_class: Ioki::Model::Passenger::NotificationSettings
model_class: Ioki::Model::Passenger::NotificationSetting,
except: [:index, :show, :create, :delete]
),
Endpoints::Create.new(
:rating,
Expand Down
14 changes: 14 additions & 0 deletions lib/ioki/model/passenger/notification_setting.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Ioki
module Model
module Passenger
class NotificationSetting < Base
attribute :id, on: :read, type: :string
attribute :type, on: :read, type: :string
attribute :name, on: [:read, :update], type: :string
attribute :channels, on: [:read, :update], type: :array
end
end
end
end
13 changes: 7 additions & 6 deletions lib/ioki/model/passenger/notification_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ module Ioki
module Model
module Passenger
class NotificationSettings < Base
attribute :type, on: :read, type: :string
attribute :ride_notifications, on: [:read, :update], type: :array
attribute :booking_notifications, on: [:read, :update], type: :array
attribute :booking_by_operator_notifications, on: [:read, :update], type: :array
attribute :payment_notifications, on: [:read, :update], type: :array
attribute :referral_notifications, on: [:read, :update], type: :array
attribute :root, on: [:read, :update], type: :array

def serialize(usecase = :read)
serialized_data = super(usecase)

serialized_data[:root]
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ioki/model/passenger/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class User < Base
attribute :failed_payments, on: :read, type: :boolean
attribute :logpay_customer_set, on: :read, type: :boolean
attribute :minimum_age_confirmed, on: :read, type: :boolean
attribute :notification_settings, on: [:read, :update], type: :object, class_name: 'NotificationSettings'
attribute :notification_settings, on: [:read, :update], type: :array
attribute :referral_code, on: :read, type: :string
attribute :referring_user_set, on: :read, type: :boolean
attribute :registered, on: :read, type: :boolean
Expand Down
15 changes: 13 additions & 2 deletions spec/ioki/passenger_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
)
end
let(:result_with_data) { instance_double(Hash, 'result double with data', '[]' => {}) }
let(:result_with_array_data) { instance_double(Hash, 'result double with data', '[]' => []) }
let(:result_with_index_data) { instance_double(Hash, 'result double with data', '[]' => [{}]) }
let(:full_response) { instance_double(Faraday::Response, 'full_response', headers: {}) }
let(:options) { { options: :example } }
Expand Down Expand Up @@ -378,9 +379,19 @@
it 'calls request on the client with expected params' do
expect(passenger_client).to receive(:request) do |params|
expect(params[:url].to_s).to eq('passenger/notification_settings/available')
[result_with_data, full_response]
[result_with_array_data, full_response]
end
expect(passenger_client.available_notification_settings).to be_a Array
end
end

describe '#default_notification_settings' do
it 'calls request on the client with expected params' do
expect(passenger_client).to receive(:request) do |params|
expect(params[:url].to_s).to eq('passenger/notification_settings/defaults')
[result_with_array_data, full_response]
end
expect(passenger_client.available_notification_settings).to be_a Ioki::Model::Passenger::NotificationSettings
expect(passenger_client.default_notification_settings).to be_a Array
end
end

Expand Down