survos / platform-api-php

Survos php api client
0 stars 0 forks source link

Example script to act on applicants #2

Open tacman opened 9 years ago

tacman commented 9 years ago

We don't need a separate endpoint for applicants, we can get it from the members call.

$resource = new MemberResource($client);
$data = $resource->getApplicants(1, 100);
$applicants = $data['items'];

getApplicants should be replaced with getMembers with a filter for applicants.

the loop should call a single action for each member, e.g.

foreach ($applicants as $applicant) {
    $id = $applicant['id'];
   $age = ... // get age from memberPersonalData
    if (isEligible($applicant)) {
        $resource->applicationAction($id, 'accept', ['message' =>"$age is eligible", 'sendEmail' => true);
    } else {
        $resource->applicationAction($id, 'reject', ['message' =>"rejected, age $age is ineligble", 'sendEmail' => true);
    }
}
kcivey commented 9 years ago

Currently the members endpoint doesn't return personal_data. It should.

kcivey commented 9 years ago

I added personal_data (see https://github.com/survos/Survos/issues/2334) and got rid of the /members/applicants endpoint. We can use /members?criteria[enrollment_status_code]=applicant instead (https://github.com/survos/Survos/commit/536a547a60417849945cfe521cd746c00c86cd01)

I've moved /members/applicants/status to /members/applicants/{action}, where action is "accept" or "reject", but I haven't changed it otherwise (https://github.com/survos/Survos/commit/7c7783071987eaac238fc92d32212b98fcd9d8b0).

karser commented 9 years ago

@kcivey I updated member_applicants example according your changes https://github.com/survos/platform-api-php/blob/master/examples/member_applicants.php