Sha256: 5c5ee4fbfb10ce65553e7474d87e0910e4e80bd8f8f525a16551403370db5fef

Contents?: true

Size: 1.12 KB

Versions: 7

Compression:

Stored size: 1.12 KB

Contents

module Centaman
  class Service::AuthenticateMember < Centaman::Service
    include Centaman::JsonWrapper

    attr_reader :member_number, :last_name, :email, :password

    def after_init(args)
      @member_number = args.fetch(:member_number, nil).try(:to_i)
      @last_name = args.fetch(:last_name, nil)
      @email = args.fetch(:email, nil)
      @password = args.fetch(:password, nil)
    end

    def endpoint
      '/member_services/Authentication'
    end

    def object_class
      Centaman::Object::Member
    end

    def build_object(resp)
      return build_objects(resp) if resp.respond_to?(:map)

      return auth_error unless resp.respond_to?(:merge)
      @build_object ||= object_class.new(resp.merge(additional_hash_to_serialize_after_response))
    end

    def options_hash
      {
        'MemberNumber' => member_number,
        'Surname' => last_name,
        'Email' => email,
        'Password' => password
      }.to_json
    end

    private

    def auth_error
      raise Centaman::Exceptions::CentamanUnauthorized.new('Invalid authentication request. Card/Member Number and Lastname not found.')
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
centaman-7.0.0 lib/centaman/service/authenticate_member.rb
centaman-6.0.8 lib/centaman/service/authenticate_member.rb
centaman-6.0.7 lib/centaman/service/authenticate_member.rb
centaman-6.0.5 lib/centaman/service/authenticate_member.rb
centaman-6.0.4 lib/centaman/service/authenticate_member.rb
centaman-6.0.3 lib/centaman/service/authenticate_member.rb
centaman-6.0.2 lib/centaman/service/authenticate_member.rb