<commit_before><?php
// Uses Composer.
require 'vendor/autoload.php';
use GuzzleHttp\Client;
use Symfony\Component\Yaml\Yaml;

// Retrieve the runtime parameters and validate them.
function initialize()
{
    $shortopts = "";
    $longopts = array(
        "login:"
    );
    $options = getopt($shortopts, $longopts);
    if (false == array_key_exists('login', $options)) {
        exit("\nYou must provide a parameter file with --login!\n");
    }
    $filename = $options['login'];
    $cred = Yaml::parseFile($filename);
    validateCredentials($cred, $filename);
    return $cred;
}

// Validate the contents of the provided credential file.
// All fields are required.  Exits on errors.
function validateCredentials($cred, $filename) {
    $errors = false;
    $fields = array(
        "token",
        "host",
        "supporterId"
    );
    foreach ($fields as $f) {
        if (false == array_key_exists($f, $cred)) {
            printf("Error: %s must contain a %s.\n", $filename, $f);
            $errors = true;
        }
    }
    if ($errors) {
        exit("Too many errors, terminating.\n");
    }
}

function main()
{
    $cred = initialize();
    $headers = [
        'authToken' => $cred["token"],
        'Content-Type' => 'application/json',<commit_msg>Added example of retrieving donations for a supporter.<commit_after><?php
// Uses Composer.
require 'vendor/autoload.php';
use GuzzleHttp\Client;
use Symfony\Component\Yaml\Yaml;

// Read donations for one supporter.  
// Usage:
// php src/actvities/search_activities_for_supporter.php --login credentials.yaml
//
/* File credentials.yaml is a YAML file.  Here's an example.
host: https://api.salsalabs.org
token: <PASSWORD>
supporterId: "c5a60131-aae7-4103-8f5e-227e0b1ad2c9"
*/
/* Returns an array of fundraising activity records like this.
Note that you need to traverse the payload to get them.

    {
        "activityType": "FUNDRAISE",
        "activityId": "5767f46b-e7fb-4c01-9128-381daf934a2f",
        "supporterId": "b5309ac4-15d9-4257-995b-45c32f97cbe6",
        "personName": "<NAME>",
        "personEmail": "<EMAIL>",
        "newSupporter": true,
        "activityDate": "2019-08-08T07:38:00.000Z",
        "lastModified": "2020-01-22T19:21:06.927Z",
        "customFieldValues": [
            {
                "fieldId": "379f185a-d71a-4c1a-acfb-ba931e4db294",
                "name": "Recurring Donation",
                "value": "True",
                "type": "STRING"
            }
        ],
        "donationId": "be82225e-75e9-4c78-bf67-3eddeddf53e3",
        "totalReceivedAmount": 10,
        "oneTimeAmount": 10,
        "donationType": "ONE_TIME",
        "accountType": "CREDIT_CARD",
        "accountNumber": "",
        "accountProvider": "paypal",
        "wasImported": true,
        "wasAPIImported": true,
        "transactions": [
            {
                "transactionId": "b1b1fa23-e05c-41fa-9276-d85e7190594a",
                "reason": "DONATION",
                "type": "CHARGE",
                "date": "2019-08-08T07:38:00.000Z",
                "amount": 10,
                "gatewayTransactionId": "3401358",
                "gatewayAuthorizationCode": "3401358"
            }
        ]
    }
*/
// See: https://api.salsalabs.org/help/integration#operation/activitySearch
//

// Function to use the command-line parameters for a YAML file.
// Reads and validates the YAML file.  Errors are noisily fatal.
function initialize()
{
    $shortopts = "";
    $longopts = array(
        "login:"
    );
    $options = getopt($shortopts, $longopts);
    if (false == array_key_exists('login', $options)) {
        exit("\nYou must provide a parameter file with --login!\n");
    }
    $filename = $options['login'];
    $cred = Yaml::parseFile($filename);
    validateCredentials($cred, $filename);
    return $cred;
}

// Validate the contents of the provided credential file.
// All fields are required.  Exits on errors.
function validateCredentials($cred, $filename) {
    $errors = false;
    $fields = array(
        "token",
        "host",
        "supporterId"
    );
    foreach ($fields as $f) {
        if (false == array_key_exists($f, $cred)) {
            printf("Error: %s must contain a %s.\n", $filename, $f);
            $errors = true;
        }
    }
    if ($errors) {
        exit("Too many errors, terminating.\n");
    }
}

// The app starts here...
function main()
{
    $cred = initialize();
    $headers = [
        'authToken' => $cred["token"],
        'Content-Type' => 'application/json',
{'fraction_non_alphanumeric': 0.14996696762827572, 'fraction_numerical': 0.041620788372605154, 'mean_word_length': 2.384500745156483, 'pattern_counts': {'":': 30, '<': 8, '<?xml version=': 0, '>': 10, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3012531', 'n_tokens_mistral': 1571, 'n_tokens_neox': 1455, 'n_words': 334}