Skip to content

Commit

Permalink
Auth methods changed
Browse files Browse the repository at this point in the history
  • Loading branch information
vldiark committed Dec 28, 2019
1 parent ef37c73 commit 04a806a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ $amo->queries->logs('path_to_log/queries'); // to custom path
```php
$amo->queries->setDelay(0.5); // default: 1 sec
```
Кеширование запросов сервиса, в секундах
Зарпос /api/v2/account кешируется в файлах, время указывается в секундах
```php
\Ufee\Amo\Services\Account::setCacheTime(1800); // default: 600 sec
```
Свой путь для кеширования запросов
```php
$amo->queries->cachePath('path_to/cache');
```
Пользовательская отладка запросов
```php
$amo->queries->listen(function(\Ufee\Amo\Api\Query $query) {
Expand All @@ -57,12 +61,6 @@ $amo->queries->listen(function(\Ufee\Amo\Api\Query $query) {
echo $query->endDate().' - ['.$query->response->getCode().'] '.$query->response->getData()."\n\n";
});
```
Зарпос /api/v2/account кешируется, время кеширования задается в Services\Account.php

Свой путь для кеширования запросов
```php
$amo->queries->cachePath('path_to/cache');
```
## Поиск сущностей
Поиск по дополнительному полю
```php
Expand Down Expand Up @@ -123,12 +121,12 @@ $entity->cf('Организация')->addValue([
```php
foreach ($amo->leads as $lead) { ... }
$amo->leads->each(function(&$lead) { ... });
$leads = $amo->leads->find('name', 'Трубы гофрированные');
$leads = $amo->leads->filter(function($lead) {
$leadsByCf = $amo->leads->find('name', 'Трубы гофрированные');
$leadsBySale = $amo->leads->filter(function($lead) {
return $lead->sale > 0;
});
$lead = $lead->first();
$lead = $lead->last();
$firstLead = $lead->first();
$lastLead = $lead->last();
```
Сортировка
```php
Expand All @@ -146,7 +144,7 @@ $leads = $leads->transform(function($lead) {
'name' => $lead->name
];
});
$leads = $leads->toArray();
$leads_array = $leads->toArray();
```
## Работа со сделками
Получение всех сделок
Expand Down
2 changes: 1 addition & 1 deletion src/Amoapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
class Amoapi
{
const VERSION = 8;
const SESS_LIFETIME = 800;
const SESS_LIFETIME = 900;
const AUTH_URL = '/private/api/auth.php';

private static $_instances = [];
Expand Down
7 changes: 3 additions & 4 deletions src/Api/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Query extends QueryModel
*/
public function execute()
{
$this->retries++;
$instance = $this->instance();
$last_time = 1;
if ($last_query = $instance->queries->last()) {
Expand All @@ -35,15 +36,13 @@ public function execute()
if (!in_array($this->response->getCode(), [200, 204]) && file_exists($instance->queries->getCookiePath())) {
@unlink($instance->queries->getCookiePath());
}
if ($this->response->getCode() == 401 && $this->url != $instance::AUTH_URL && $this->retry && $instance->hasAutoAuth()) {
while ($this->response->getCode() == 401 && $this->url != $instance::AUTH_URL && $this->retries <= 3 && $instance->hasAutoAuth()) {
$instance->authorize();
usleep(0.5*1000000);
$instance->queries->refreshSession();
$this->setCurl();
$this->setRetry(false);
return $this->execute();
}
while ($this->response->getCode() == 429) {
while ($this->response->getCode() == 429 && $this->retries <= 32) {
sleep(1);
$this->setCurl()->execute();
}
Expand Down
1 change: 1 addition & 0 deletions src/Base/Models/QueryModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class QueryModel
'response'
],
$attributes = [],
$retries = 0,
$cookie = [];

/**
Expand Down
3 changes: 3 additions & 0 deletions src/Base/Services/Traits/SearchByEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ trait SearchByEmail
*/
public function searchByEmail($email)
{
if (strlen($email) < 6 || !strpos($email, '@')) {
throw new \Exception('Invalid search email value: '.$email);
}
$clearEmail = function($email) {
return mb_strtoupper(trim($email));
};
Expand Down
3 changes: 3 additions & 0 deletions src/Base/Services/Traits/SearchByPhone.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ protected function searchBy_ru_mob($phone)
};
$field_name = $this->instance->getAuth('lang') == 'ru' ? 'Телефон' : 'Phone';
$query = $clearPhone($phone);
if (strlen($query) < 6) {
throw new \Exception('Invalid search phone value: '.$phone);
}
$results = $this->list->where('query', $query)->recursiveCall();

return $results->filter(function($model) use($query, $field_name, $clearPhone) {
Expand Down

0 comments on commit 04a806a

Please sign in to comment.