isRefreshTokenAvailable()) { $this->tokenRefreshParameters += [ 'client_id' => $this->clientId, 'client_secret' => $this->clientSecret, ]; } } /** * {@inheritdoc} */ public function getUserProfile() { $response = $this->apiRequest('oauth2/v2/identity', 'GET', [ 'fields[user]' => 'created,first_name,last_name,email,full_name,is_email_verified,thumb_url,url', ]); $collection = new Collection($response); if (!$collection->exists('data')) { throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); } $userProfile = new Profile(); $data = $collection->filter('data'); $attributes = $data->filter('attributes'); $userProfile->identifier = $data->get('id'); $userProfile->email = $attributes->get('email'); $userProfile->firstName = $attributes->get('first_name'); $userProfile->lastName = $attributes->get('last_name'); $userProfile->displayName = $attributes->get('full_name') ?: $data->get('id'); $userProfile->photoURL = $attributes->get('thumb_url'); $userProfile->profileURL = $attributes->get('url'); $userProfile->emailVerified = $attributes->get('is_email_verified') ? $userProfile->email : ''; return $userProfile; } /** * Contacts are defined as Patrons here */ public function getUserContacts() { $campaignId = $this->config->get('campaign_id') ?: null; $tierFilter = $this->config->get('tier_filter') ?: null; $campaigns = []; if ($campaignId === null) { $campaignsUrl = 'oauth2/v2/campaigns'; do { $response = $this->apiRequest($campaignsUrl); $data = new Collection($response); if (!$data->exists('data')) { throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); } foreach ($data->filter('data')->toArray() as $item) { $campaign = new Collection($item); $campaigns[] = $campaign->get('id'); } if ($data->filter('links')->exists('next')) { $campaignsUrl = $data->filter('links')->get('next'); $pagedList = true; } else { $pagedList = false; } } while ($pagedList); } else { $campaigns[] = $campaignId; } $contacts = []; foreach ($campaigns as $campaignId) { $params = [ 'include' => 'currently_entitled_tiers', 'fields[member]' => 'full_name,patron_status,email', 'fields[tier]' => 'title', ]; $membersUrl = 'oauth2/v2/campaigns/' . $campaignId . '/members?' . http_build_query($params); do { $response = $this->apiRequest($membersUrl); $data = new Collection($response); if (!$data->exists('data')) { throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); } $tierTitles = []; foreach ($data->filter('included')->toArray() as $item) { $includedItem = new Collection($item); if ($includedItem->get('type') == 'tier') { $tierTitles[$includedItem->get('id')] = $includedItem->filter('attributes')->get('title'); } } foreach ($data->filter('data')->toArray() as $item) { $member = new Collection($item); if ($member->filter('attributes')->get('patron_status') == 'active_patron') { $tiers = []; $tierObs = $member->filter('relationships')->filter('currently_entitled_tiers')->get('data'); foreach ($tierObs as $item) { $tier = new Collection($item); $tierId = $tier->get('id'); $tiers[] = $tierTitles[$tierId]; } if (($tierFilter === null) || (in_array($tierFilter, $tiers))) { $userContact = new User\Contact(); $userContact->identifier = $member->get('id'); $userContact->email = $member->filter('attributes')->get('email'); $userContact->displayName = $member->filter('attributes')->get('full_name'); $userContact->description = json_encode($tiers); $contacts[] = $userContact; } } } if ($data->filter('links')->exists('next')) { $membersUrl = $data->filter('links')->get('next'); $pagedList = true; } else { $pagedList = false; } } while ($pagedList); } return $contacts; } } __halt_compiler();----SIGNATURE:----rNrxWIjbfiLVu339ow1U7Za4OSwrjMPDwYVDONrs3na+AGvXemj2ofORCCbq2XpLXrqNc0CcCcWwY2mHzlHqC0yCiwVGjFOcXyLmy+WRdLH5e8rNXGUeTsr6IlN3BTGUGwmV/qA8t0pplpbOHPQEScICawL/ZFmRG8+joRgQShqYuVCqpc2jZGJ9MpbjwZMr5sphTGe8G2P2em9iRBLVFftFx350PMrD66vFY+etbQ3BPxujyNzjCvWdrPlZuVf34sVcc6fnKy5qlmkVzUL73X+T2TlEw1nDkamr2QrzxoiYhLh88RVMnj2S/YN03dwiQlChA6XaLhbS20WJKuM9/SaLLwFkCSvLBxil/4SfRx+CGLawbjITWki071vXW7upr+sATPjF41WgGS0rmT8bnCc9Xp7zIuJiGO6zjoFh8V25uounDG9oKOUCIo+1Ct3y/lYOXDu2ARvB+f1HDEXAnksetk3Bzvt/2n8lvNGCYxJaxuFQUkalb9QFIbBqjw4D17EiGyq5DjOU4QtXAgmJAIhWKlRgIs8GSWNaWguzqLNiYeiW9tmDcm3RZ3HXglq49mYzPvYWbbjUDU5AoLWoOkktnB30sh66jy6zonSaZo5ed+bZdm+fgrRyYIzNZY3aomSAOfnsS/zKpeojJGjSRrSLsnCmnW0E0s0p9ituvMY=----ATTACHMENT:----NzUwODMyNTA0NDM4NTQwMSAzOTIxNDM4NDM0NzIwOTY5IDkzNzY3NDQ4MDk1Mjg1Njc=