From 84560494d413f918297a9d34cd496d0ec78501a0 Mon Sep 17 00:00:00 2001 From: Tobias Matz Date: Mon, 18 Sep 2023 14:49:07 +0200 Subject: [PATCH 1/4] Add autocomplete for operator api --- lib/ioki/apis/operator_api.rb | 6 ++++++ lib/ioki/model/operator/user_autocomplete.rb | 21 ++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 lib/ioki/model/operator/user_autocomplete.rb diff --git a/lib/ioki/apis/operator_api.rb b/lib/ioki/apis/operator_api.rb index 8ae88975..a50a1098 100644 --- a/lib/ioki/apis/operator_api.rb +++ b/lib/ioki/apis/operator_api.rb @@ -214,6 +214,12 @@ class OperatorApi model_class: Ioki::Model::Operator::User, except: [:create, :update, :delete] ), + Endpoitns.custom_endpoints( + 'users', + actions: { 'autocomplete' => :get }, + path: [API_BASE_PATH, 'providers', :id, 'users'], + model_class: Ioki::Model::Operator::UserAutocomplete + ), Endpoints::Create.new( :ride_inquiry, base_path: [API_BASE_PATH, 'products', :id], diff --git a/lib/ioki/model/operator/user_autocomplete.rb b/lib/ioki/model/operator/user_autocomplete.rb new file mode 100644 index 00000000..77b6edbc --- /dev/null +++ b/lib/ioki/model/operator/user_autocomplete.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Ioki + module Model + module Operator + class UserAutocomplete < Base + attribute :value, + on: :read, + type: :string + + attribute :label, + on: :read, + type: :string + + attribute :locked, + on: :read, + type: :boolean + end + end + end +end From 9b34f9ddacca3546a81d89f8f046c9c6bbc7fd79 Mon Sep 17 00:00:00 2001 From: Tobias Matz Date: Mon, 18 Sep 2023 14:53:46 +0200 Subject: [PATCH 2/4] Fix typo --- lib/ioki/apis/operator_api.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ioki/apis/operator_api.rb b/lib/ioki/apis/operator_api.rb index a50a1098..12c924e9 100644 --- a/lib/ioki/apis/operator_api.rb +++ b/lib/ioki/apis/operator_api.rb @@ -214,7 +214,7 @@ class OperatorApi model_class: Ioki::Model::Operator::User, except: [:create, :update, :delete] ), - Endpoitns.custom_endpoints( + Endpoints.custom_endpoints( 'users', actions: { 'autocomplete' => :get }, path: [API_BASE_PATH, 'providers', :id, 'users'], From 3bcce68e4fc6a85631f56de2de1b2a478e68ede7 Mon Sep 17 00:00:00 2001 From: Tobias Matz Date: Mon, 18 Sep 2023 15:13:56 +0200 Subject: [PATCH 3/4] Add spec --- spec/ioki/operator_api_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spec/ioki/operator_api_spec.rb b/spec/ioki/operator_api_spec.rb index a15ae264..2591fac8 100644 --- a/spec/ioki/operator_api_spec.rb +++ b/spec/ioki/operator_api_spec.rb @@ -1253,4 +1253,17 @@ .to be_a(Ioki::Model::Operator::Task) end end + + describe '#users_autocomplete(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/autocomplete') + expect(params[:method]).to eq(:get) + result_with_data + end + + expect(operator_client.users_autocomplete('0815', options)) + .to be_a(Ioki::Model::Operator::UserAutocomplete) + end + end end From 787e3c270f24cc7535a485f4b7ed87006cb607cc Mon Sep 17 00:00:00 2001 From: Tobias Matz Date: Tue, 19 Sep 2023 14:32:45 +0200 Subject: [PATCH 4/4] Fix array issue --- lib/ioki/apis/operator_api.rb | 2 +- lib/ioki/model/operator/user_autocompletes.rb | 11 +++++++++++ spec/ioki/operator_api_spec.rb | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 lib/ioki/model/operator/user_autocompletes.rb diff --git a/lib/ioki/apis/operator_api.rb b/lib/ioki/apis/operator_api.rb index 12c924e9..55bf32bd 100644 --- a/lib/ioki/apis/operator_api.rb +++ b/lib/ioki/apis/operator_api.rb @@ -218,7 +218,7 @@ class OperatorApi 'users', actions: { 'autocomplete' => :get }, path: [API_BASE_PATH, 'providers', :id, 'users'], - model_class: Ioki::Model::Operator::UserAutocomplete + model_class: Ioki::Model::Operator::UserAutocompletes ), Endpoints::Create.new( :ride_inquiry, diff --git a/lib/ioki/model/operator/user_autocompletes.rb b/lib/ioki/model/operator/user_autocompletes.rb new file mode 100644 index 00000000..e0af2ac4 --- /dev/null +++ b/lib/ioki/model/operator/user_autocompletes.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Ioki + module Model + module Operator + class UserAutocompletes < Base + base 'Array', item_class_name: 'UserAutocomplete' + end + end + end +end diff --git a/spec/ioki/operator_api_spec.rb b/spec/ioki/operator_api_spec.rb index 2591fac8..ae20fd33 100644 --- a/spec/ioki/operator_api_spec.rb +++ b/spec/ioki/operator_api_spec.rb @@ -1263,7 +1263,7 @@ end expect(operator_client.users_autocomplete('0815', options)) - .to be_a(Ioki::Model::Operator::UserAutocomplete) + .to be_a(Ioki::Model::Operator::UserAutocompletes) end end end