public function createNorthstarUser($user)
  {

    $northstarAPIConfig = $this->mbConfig->getProperty('northstar_config');
    if (empty($northstarAPIConfig['host'])) {
      throw new Exception('MB_Toolbox->createNorthstarUser() northstar_config missing host setting.');
    }

    // Required - at least one of email or mobile must be set.
    $requiredSet = false;
    if (!empty($user->email)) {
      $post['email'] = $user->email;
      $requiredSet = true;
    }

    if (!empty($user->mobile)) {
      $post['mobile'] = $user->mobile;
      $requiredSet = true;
    }

    if (!$requiredSet) {
      throw new Exception('MB_Toolbox->createNorthstarUser() Neither email or mobile value available. Failed to create user.');
    }

    // Optional fields that can be a part of a Northstar user document
    // List of supported fields:
    // https://github.com/DoSomething/northstar/blob/dev/documentation/endpoints/users.md#create-a-user
    $supportedFields = [
      'password',
      'first_name',
      'last_name',
      'addr_street1',
      'addr_street2',
      'addr_city',
      'addr_state',
      'addr_zip',
      'country', // two character country code
      'language',
      'source',
      'race',
      'religion',
      'college_name',
      'degree_type',
      'major_name',
      'hs_gradyear',
      'hs_name',
      'sat_math',
      'sat_verbal',
      'sat_writing',
    ];

    foreach ($supportedFields as $field) {
      if (isset($user->$field)) {
        $post[$field] = $user->$field;
      }
    }

    // Optional fields that require formatting
    if (isset($user->birthdate) && strtotime($user->birthdate)) {
      $post['birthdate'] = date('Y-m-d', strtotime($user->birthdate));
    } elseif (isset($user->birthdate) && is_int($user->birthdate)) {
      $post['birthdate'] = date('Y-m-d', $user->birthdate);
    } elseif (isset($user->birthdate_timestamp) && is_int($user->birthdate_timestamp)) {
      $post['birthdate'] = date('Y-m-d', $user->birthdate_timestamp);
    }

    $northstarUrl =  $northstarAPIConfig['host'];

    // Append port if exists.
    if (!empty($northstarAPIConfig['port'])) {
      $port = (int) $northstarAPIConfig['port'];
      // Port is within allowed range:
      // https://en.wikipedia.org/wiki/Port_(computer_networking)#Details
      if ($port > 0 && $port < 65536) {
        $northstarUrl .= ':' . $port;
      }
    }

    $northstarUrl .= '/' . self::NORTHSTAR_API_VERSION . '/users?create_drupal_user=true';
    $result = $this->mbToolboxcURL->curlPOST($northstarUrl, $post);
    return $this->parseNorthstarUserResponse($result);
  }
public function createNorthstarUser($user)
  {

    $northstarAPIConfig = $this->mbConfig->getProperty('northstar_config');
    if (empty($northstarAPIConfig['host'])) {
      throw new Exception('MB_Toolbox->createNorthstarUser() northstar_config missing host setting.');
    }

    // Required - at least one of email or mobile must be set.
    $requiredSet = false;
    if (!empty($user->email)) {
      $post['email'] = $user->email;
      $requiredSet = true;
    }

    if (!empty($user->mobile)) {
      $post['mobile'] = $user->mobile;
      $requiredSet = true;
    }

    if (!$requiredSet) {
      throw new Exception('MB_Toolbox->createNorthstarUser() Neither email or mobile value available. Failed to create user.');
    }

    // Optional fields that can be a part of a Northstar user document
    // List of supported fields:
    // https://github.com/DoSomething/northstar/blob/dev/documentation/endpoints/users.md#create-a-user
    $supportedFields = [
      'password',
      'first_name',
      'last_name',
      'addr_street1',
      'addr_street2',
      'addr_city',
      'addr_state',
      'addr_zip',
      'country', // two character country code
      'language',
      'source',
      'race',
      'religion',
      'college_name',
      'degree_type',
      'major_name',
      'hs_gradyear',
      'hs_name',
      'sat_math',
      'sat_verbal',
      'sat_writing',
    ];

    foreach ($supportedFields as $field) {
      if (isset($user->$field)) {
        $post[$field] = $user->$field;
      }
    }

    // Optional fields that require formatting
    if (isset($user->birthdate) && strtotime($user->birthdate)) {
      $post['birthdate'] = date('Y-m-d', strtotime($user->birthdate));
    } elseif (isset($user->birthdate) && is_int($user->birthdate)) {
      $post['birthdate'] = date('Y-m-d', $user->birthdate);
    } elseif (isset($user->birthdate_timestamp) && is_int($user->birthdate_timestamp)) {
      $post['birthdate'] = date('Y-m-d', $user->birthdate_timestamp);
    }

    $northstarUrl =  $northstarAPIConfig['host'];

    // Append port if exists.
    if (!empty($northstarAPIConfig['port'])) {
      $port = (int) $northstarAPIConfig['port'];
      // Port is within allowed range:
      // https://en.wikipedia.org/wiki/Port_(computer_networking)#Details
      if ($port > 0 && $port < 65536) {
        $northstarUrl .= ':' . $port;
      }
    }

    $northstarUrl .= '/' . self::NORTHSTAR_API_VERSION . '/users?create_drupal_user=true';
    $result = $this->mbToolboxcURL->curlPOST($northstarUrl, $post);
    return $this->parseNorthstarUserResponse($result);
  }
public function createNorthstarUser ( $ user ) { $ northstarAPIConfig = $ this -> mbConfig -> getProperty ( 'northstar_config' ) ; if ( empty ( $ northstarAPIConfig [ 'host' ] ) ) { throw new Exception ( 'MB_Toolbox->createNorthstarUser() northstar_config missing host setting.' ) ; } // Required - at least one of email or mobile must be set. $ requiredSet = false ; if ( ! empty ( $ user -> email ) ) { $ post [ 'email' ] = $ user -> email ; $ requiredSet = true ; } if ( ! empty ( $ user -> mobile ) ) { $ post [ 'mobile' ] = $ user -> mobile ; $ requiredSet = true ; } if ( ! $ requiredSet ) { throw new Exception ( 'MB_Toolbox->createNorthstarUser() Neither email or mobile value available. Failed to create user.' ) ; } // Optional fields that can be a part of a Northstar user document // List of supported fields: // https://github.com/DoSomething/northstar/blob/dev/documentation/endpoints/users.md#create-a-user $ supportedFields = [ 'password' , 'first_name' , 'last_name' , 'addr_street1' , 'addr_street2' , 'addr_city' , 'addr_state' , 'addr_zip' , 'country' , // two character country code 'language' , 'source' , 'race' , 'religion' , 'college_name' , 'degree_type' , 'major_name' , 'hs_gradyear' , 'hs_name' , 'sat_math' , 'sat_verbal' , 'sat_writing' , ] ; foreach ( $ supportedFields as $ field ) { if ( isset ( $ user -> $ field ) ) { $ post [ $ field ] = $ user -> $ field ; } } // Optional fields that require formatting if ( isset ( $ user -> birthdate ) && strtotime ( $ user -> birthdate ) ) { $ post [ 'birthdate' ] = date ( 'Y-m-d' , strtotime ( $ user -> birthdate ) ) ; } elseif ( isset ( $ user -> birthdate ) && is_int ( $ user -> birthdate ) ) { $ post [ 'birthdate' ] = date ( 'Y-m-d' , $ user -> birthdate ) ; } elseif ( isset ( $ user -> birthdate_timestamp ) && is_int ( $ user -> birthdate_timestamp ) ) { $ post [ 'birthdate' ] = date ( 'Y-m-d' , $ user -> birthdate_timestamp ) ; } $ northstarUrl = $ northstarAPIConfig [ 'host' ] ; // Append port if exists. if ( ! empty ( $ northstarAPIConfig [ 'port' ] ) ) { $ port = ( int ) $ northstarAPIConfig [ 'port' ] ; // Port is within allowed range: // https://en.wikipedia.org/wiki/Port_(computer_networking)#Details if ( $ port > 0 && $ port < 65536 ) { $ northstarUrl .= ':' . $ port ; } } $ northstarUrl .= '/' . self :: NORTHSTAR_API_VERSION . '/users?create_drupal_user=true' ; $ result = $ this -> mbToolboxcURL -> curlPOST ( $ northstarUrl , $ post ) ; return $ this -> parseNorthstarUserResponse ( $ result ) ; }
Create a user entry in Northstar, the DoSomething User API.

@param object $user Values used to define the user created in Northstar.

@return object The values returned from Northstar as a result of user creation.
Create a user entry in Northstar the DoSomething User API .