Sha256: 452585ecc32b766e5c2a2e6707cb00929e913b51eae0a56ef3dd9f943d86fcc7

Contents?: true

Size: 1.22 KB

Versions: 13

Compression:

Stored size: 1.22 KB

Contents

require 'securerandom'

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

    attr_reader :first_name, :last_name, :email, :password

    def after_init(args)
      @first_name = args[:first_name].try(:squish)
      @last_name = args[:last_name].try(:squish)
      @email = args[:email].try(:squish)
      @password = args[:password] || SecureRandom.hex
    end

    def endpoint
      '/member_services/Member'
    end

    def object_class
      Centaman::Object::Member
    end

    def build_object(resp)
      return build_objects(resp) if resp.respond_to?(:map)
      return create_error(resp) unless resp.respond_to?(:merge)
      @build_object ||= object_class.new(resp.merge(additional_hash_to_serialize_after_response))
    end

    def options_hash
      [
        {
          'FirstName' => first_name.try(:upcase),
          'LastName' => last_name.try(:upcase),
          'Email' => email.try(:upcase),
          'Password' => password,
          'IsPrimary' => true
        }
      ].to_json
    end

    private

    def create_error(resp)
      message = { error: resp.parsed_response || 'Unable to create primary member record.' }
      raise message[:error]
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
centaman-6.0.2 lib/centaman/service/create_primary_member.rb
centaman-6.0.1 lib/centaman/service/create_primary_member.rb
centaman-6.0.0 lib/centaman/service/create_primary_member.rb
centaman-5.0.8 lib/centaman/service/create_primary_member.rb
centaman-5.0.7 lib/centaman/service/create_primary_member.rb
centaman-5.0.6 lib/centaman/service/create_primary_member.rb
centaman-5.0.5 lib/centaman/service/create_primary_member.rb
centaman-5.0.4 lib/centaman/service/create_primary_member.rb
centaman-5.0.3 lib/centaman/service/create_primary_member.rb
centaman-5.0.2 lib/centaman/service/create_primary_member.rb
centaman-5.0.1 lib/centaman/service/create_primary_member.rb
centaman-5.0.0 lib/centaman/service/create_primary_member.rb
centaman-4.0.5 lib/centaman/service/create_primary_member.rb