Sha256: 41d34d47a6f9f5547445a58da7e8b1cd9da7d30a68237e5f5f75baa77068bd17

Contents?: true

Size: 1.4 KB

Versions: 9

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true
require_relative '../utils/query_builder'

module FinApps
  module REST
    class Operators < FinAppsCore::REST::Resources
      include FinApps::Utils::QueryBuilder

      def list(params=nil)
        return super if params.nil?
        raise FinAppsCore::InvalidArgumentsError.new 'Invalid argument: params' unless params.is_a? Hash
        super build_query_path(end_point, params)
      end

      def show(id)
        not_blank(id, :operator_id)

        super id
      end

      def create(params, path=nil)
        not_blank(params, :params)
        super params, path
      end

      def update(id, params)
        not_blank(id, :operator_id)
        not_blank(params, :params)

        path = "#{end_point}/#{ERB::Util.url_encode(id)}"
        super params, path
      end

      def update_password(params)
        # update password for current operator, need authorization session in header
        not_blank(params, :params)
        raise FinAppsCore::InvalidArgumentsError.new 'Invalid argument: params.' unless validates params
        path = "#{end_point}/password/change"

        create params, path
      end

      def destroy(id)
        not_blank(id, :operator_id)
        super id
      end

      private

      def validates(params)
        params.key?(:password) && params[:password] && params.key?(:password_confirm) && params[:password_confirm]
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
finapps-2.2.22 lib/finapps/rest/operators.rb
finapps-2.2.21 lib/finapps/rest/operators.rb
finapps-2.2.20 lib/finapps/rest/operators.rb
finapps-2.2.19 lib/finapps/rest/operators.rb
finapps-2.2.18 lib/finapps/rest/operators.rb
finapps-2.2.17 lib/finapps/rest/operators.rb
finapps-2.2.16 lib/finapps/rest/operators.rb
finapps-2.2.15 lib/finapps/rest/operators.rb
finapps-2.2.14 lib/finapps/rest/operators.rb