From 35ae0ccdb28b4c9e9d972b8f99c21d00ff2ba45e Mon Sep 17 00:00:00 2001 From: Tobias Matz Date: Thu, 11 May 2023 22:52:17 +0200 Subject: [PATCH 1/3] Add NotificationSetting and NotificationSettings for operator api --- lib/ioki/model/operator/notification_setting.rb | 14 ++++++++++++++ lib/ioki/model/operator/notification_settings.rb | 11 +++++++++++ 2 files changed, 25 insertions(+) create mode 100644 lib/ioki/model/operator/notification_setting.rb create mode 100644 lib/ioki/model/operator/notification_settings.rb diff --git a/lib/ioki/model/operator/notification_setting.rb b/lib/ioki/model/operator/notification_setting.rb new file mode 100644 index 00000000..63f62581 --- /dev/null +++ b/lib/ioki/model/operator/notification_setting.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Ioki + module Model + module Operator + 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 diff --git a/lib/ioki/model/operator/notification_settings.rb b/lib/ioki/model/operator/notification_settings.rb new file mode 100644 index 00000000..80e90e59 --- /dev/null +++ b/lib/ioki/model/operator/notification_settings.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Ioki + module Model + module Operator + class NotificationSettings < Base + base 'Array', item_class_name: 'NotificationSetting' + end + end + end +end From 1751667f40c1b3bf8a129deb66fa8aacea890c4f Mon Sep 17 00:00:00 2001 From: Tobias Matz Date: Thu, 11 May 2023 22:52:54 +0200 Subject: [PATCH 2/3] Refine User model --- lib/ioki/model/operator/user.rb | 91 +++++++++++++++++++++++++-------- 1 file changed, 69 insertions(+), 22 deletions(-) diff --git a/lib/ioki/model/operator/user.rb b/lib/ioki/model/operator/user.rb index 6acc3684..1af92791 100644 --- a/lib/ioki/model/operator/user.rb +++ b/lib/ioki/model/operator/user.rb @@ -4,28 +4,75 @@ module Ioki module Model module Operator class User < 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 :email, type: :object, on: [:read, :create, :update], -omit_if_blank_on: [:create, :update], class_name: 'UserEmail' - attribute :external_id, type: :string, on: [:read, :create, :update], -omit_if_blank_on: [:create, :update] - attribute :first_name, type: :string, on: [:read, :create, :update], -omit_if_blank_on: [:create, :update] - attribute :last_name, type: :string, on: [:read, :create, :update], -omit_if_blank_on: [:create, :update] - attribute :locale, type: :string, on: :read - attribute :lock_reason, type: :string, on: :read - attribute :lock_type, type: :string, on: :read - attribute :locked_at, type: :date_time, on: :read - attribute :phone_number, type: :string, on: [:read, :create, :update], -omit_if_blank_on: [:create, :update] - attribute :terms_accepted_at, type: :date_time, on: :read - # The model does not return it but it's used when sending data to the server. - attribute :terms_accepted, type: :boolean, on: [:create, :update], unvalidated: true - attribute :version, type: :integer, on: [:read, :update] + 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 :email, + on: [:read, :create, :update], + omit_if_blank_on: [:create, :update], + type: :object, + class_name: 'UserEmail' + + attribute :external_id, + on: [:read, :create, :update], + omit_if_blank_on: [:create, :update], + type: :string + + attribute :first_name, + on: [:read, :create, :update], + omit_if_blank_on: [:create, :update], + type: :string + + attribute :last_name, + on: [:read, :create, :update], + omit_if_blank_on: [:create, :update], + type: :string + + attribute :locale, + on: :read, + type: :string + + attribute :lock_reason, + on: :read, + type: :string + + attribute :lock_type, + on: :read, + type: :string + + attribute :locked_at, + on: :read, + type: :date_time + + attribute :notification_settings, + on: :read, + type: :array + + attribute :phone_number, + on: [:read, :create, :update], + omit_if_blank_on: [:create, :update], + type: :string + + attribute :terms_accepted_at, + on: :read, + type: :date_time + + attribute :version, + on: [:read, :update], + type: :integer end end end From aea4164503d4f76fa48336a35681e09c34bb36cd Mon Sep 17 00:00:00 2001 From: Tobias Matz Date: Thu, 11 May 2023 22:53:09 +0200 Subject: [PATCH 3/3] Add user endpoints for operator api --- lib/ioki/apis/operator_api.rb | 6 ++++++ spec/ioki/operator_api_spec.rb | 34 +++++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/lib/ioki/apis/operator_api.rb b/lib/ioki/apis/operator_api.rb index 52356cdb..db015a20 100644 --- a/lib/ioki/apis/operator_api.rb +++ b/lib/ioki/apis/operator_api.rb @@ -191,6 +191,12 @@ class OperatorApi base_path: [API_BASE_PATH, 'products', :id, 'lines', :id], except: [:create, :delete], model_class: Ioki::Model::Operator::LineStop + ), + Endpoints.crud_endpoints( + :user, + base_path: [API_BASE_PATH, 'providers', :id], + model_class: Ioki::Model::Operator::User, + except: [:create, :update, :delete] ) ].freeze end diff --git a/spec/ioki/operator_api_spec.rb b/spec/ioki/operator_api_spec.rb index 69f9f454..98ab66d4 100644 --- a/spec/ioki/operator_api_spec.rb +++ b/spec/ioki/operator_api_spec.rb @@ -1093,7 +1093,7 @@ end expect(operator_client.create_line('0815', line, options)) - .to eq(Ioki::Model::Operator::Line.new) + .to be_a(Ioki::Model::Operator::Line) end end @@ -1108,7 +1108,7 @@ end expect(operator_client.update_line('0815', line, options)) - .to eq(Ioki::Model::Operator::Line.new) + .to be_a(Ioki::Model::Operator::Line) end end @@ -1120,7 +1120,7 @@ end expect(operator_client.delete_line('0815', '4711', options)) - .to eq(Ioki::Model::Operator::Line.new) + .to be_a(Ioki::Model::Operator::Line) end end @@ -1134,7 +1134,7 @@ end expect(operator_client.create_line_stop('0815', '0815', line_stop, options)) - .to eq(Ioki::Model::Operator::LineStop.new) + .to be_a(Ioki::Model::Operator::LineStop) end end @@ -1146,7 +1146,31 @@ end expect(operator_client.delete_line_stop('0815', '0815', '4711', options)) - .to eq(Ioki::Model::Operator::LineStop.new) + .to be_a(Ioki::Model::Operator::LineStop) + end + end + + describe '#users(provider_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/providers/0815/users') + result_with_index_data + end + + expect(operator_client.users('0815', options)) + .to all(be_a(Ioki::Model::Operator::User)) + end + end + + describe '#user(provider_id, user_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/providers/0815/users/4711') + [result_with_data, full_response] + end + + expect(operator_client.user('0815', '4711', options)) + .to be_a(Ioki::Model::Operator::User) end end end