Sha256: 54100a44e726fc452eac7ddc4c6b99215930460cca6abf777fb0179f8a4b6b46

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 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 'Invalid authentication request. Card/Member Number and Lastname not found.'
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
centaman-6.0.1 lib/centaman/service/authenticate_member.rb
centaman-6.0.0 lib/centaman/service/authenticate_member.rb
centaman-5.0.8 lib/centaman/service/authenticate_member.rb
centaman-5.0.7 lib/centaman/service/authenticate_member.rb
centaman-5.0.6 lib/centaman/service/authenticate_member.rb