-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #376 from olapsema/feature/subsc_talks_api
talks and subscriptions api
- Loading branch information
Showing
11 changed files
with
830 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use AmoCRM\Exceptions\AmoCRMApiException; | ||
use AmoCRM\Filters\PagesFilter; | ||
use AmoCRM\Helpers\EntityTypesInterface; | ||
use League\OAuth2\Client\Token\AccessTokenInterface; | ||
|
||
include_once __DIR__ . '/bootstrap.php'; | ||
|
||
/** @var \AmoCRM\Client\AmoCRMApiClient $apiClient */ | ||
$accessToken = getToken(); | ||
$apiClient | ||
->setAccessToken($accessToken) | ||
->setAccountBaseDomain($accessToken->getValues()['baseDomain']) | ||
->onAccessTokenRefresh( | ||
function (AccessTokenInterface $accessToken, string $baseDomain) { | ||
saveToken( | ||
[ | ||
'accessToken' => $accessToken->getToken(), | ||
'refreshToken' => $accessToken->getRefreshToken(), | ||
'expires' => $accessToken->getExpires(), | ||
'baseDomain' => $baseDomain, | ||
] | ||
); | ||
} | ||
); | ||
|
||
$subscriptionsService = $apiClient->entitySubscriptions(EntityTypesInterface::LEADS); | ||
|
||
try { | ||
$filer = (new PagesFilter()) | ||
->setLimit(3); | ||
$subscriptions = $subscriptionsService->getByParentId(667999631, $filer); | ||
} catch (AmoCRMApiException $exception) { | ||
printError($exception); | ||
die; | ||
} | ||
|
||
var_dump($subscriptions->toArray()); | ||
|
||
try { | ||
$nextSubscriptions = $subscriptionsService->nextPage($subscriptions); | ||
} catch (AmoCRMApiException $exception) { | ||
printError($exception); | ||
die; | ||
} | ||
|
||
var_dump($nextSubscriptions->toArray()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use AmoCRM\AmoCRM\Models\Talks\TalkCloseActionModel; | ||
use AmoCRM\Exceptions\AmoCRMApiException; | ||
use League\OAuth2\Client\Token\AccessTokenInterface; | ||
|
||
include_once __DIR__ . '/bootstrap.php'; | ||
|
||
/** @var \AmoCRM\Client\AmoCRMApiClient $apiClient */ | ||
$accessToken = getToken(); | ||
$apiClient | ||
->setAccessToken($accessToken) | ||
->setAccountBaseDomain($accessToken->getValues()['baseDomain']) | ||
->onAccessTokenRefresh( | ||
function (AccessTokenInterface $accessToken, string $baseDomain) { | ||
saveToken( | ||
[ | ||
'accessToken' => $accessToken->getToken(), | ||
'refreshToken' => $accessToken->getRefreshToken(), | ||
'expires' => $accessToken->getExpires(), | ||
'baseDomain' => $baseDomain, | ||
] | ||
); | ||
} | ||
); | ||
|
||
$talksService = $apiClient->talks(); | ||
|
||
try { | ||
$talk = $talksService->getOne('114'); | ||
} catch (AmoCRMApiException $exception) { | ||
printError($exception); | ||
die; | ||
} | ||
|
||
try { | ||
$talksService->close(new TalkCloseActionModel($talk->getTalkId(), true)); | ||
} catch (AmoCRMApiException $exception) { | ||
printError($exception); | ||
die; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace AmoCRM\Collections; | ||
|
||
use AmoCRM\AmoCRM\Models\SubscriptionModel; | ||
use AmoCRM\Collections\Interfaces\HasPagesInterface; | ||
use AmoCRM\Collections\Traits\PagesTrait; | ||
use AmoCRM\Models\RoleModel; | ||
|
||
/** | ||
* @method null|SubscriptionModel current() | ||
* @method null|SubscriptionModel last() | ||
* @method null|SubscriptionModel first() | ||
* @method null|SubscriptionModel offsetGet($offset) | ||
* @method self offsetSet($offset, RoleModel $value) | ||
* @method self prepend(RoleModel $value) | ||
* @method self add(RoleModel $value) | ||
* @method null|SubscriptionModel getBy($key, $value) | ||
*/ | ||
class SubscriptionsCollection extends BaseApiCollection implements HasPagesInterface | ||
{ | ||
use PagesTrait; | ||
|
||
public const ITEM_CLASS = SubscriptionModel::class; | ||
} |
Oops, something went wrong.