Sha256: 32f8c8175cb961a9b12a763e87d025453847358b9db244ba68fa1409164b4320

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

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

    attr_reader :member_code, :last_name, :email, :password

    def after_init(args)
      @member_code = args.fetch(:member_code, 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(resp) unless resp.respond_to?(:merge)
      @build_object ||= object_class.new(resp.merge(additional_hash_to_serialize_after_response))
    end

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

    private

    def auth_error(resp)
      { error: resp.parsed_response ? resp.parsed_response : 'Authentication Failed. Invalid credentials.' }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
centaman-0.2.1 lib/centaman/service/authenticate_member.rb
centaman-0.2.0 lib/centaman/service/authenticate_member.rb