Skip to content

Commit

Permalink
Merge pull request #222 from ioki-mobility/operator-api-users
Browse files Browse the repository at this point in the history
Operator Api | Add User endpoints
  • Loading branch information
tom-ioki committed May 23, 2023
2 parents cf8fbaa + aea4164 commit 552780a
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 27 deletions.
6 changes: 6 additions & 0 deletions lib/ioki/apis/operator_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions lib/ioki/model/operator/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 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
11 changes: 11 additions & 0 deletions lib/ioki/model/operator/notification_settings.rb
Original file line number Diff line number Diff line change
@@ -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
91 changes: 69 additions & 22 deletions lib/ioki/model/operator/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 29 additions & 5 deletions spec/ioki/operator_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

0 comments on commit 552780a

Please sign in to comment.