skeeks/yii2-dadata-suggest-api

Suggest yii2 api dadata.ru

1.0.0 2016-11-10 12:19 UTC

README

Info

Installation

The preferred way to install this extension is through composer.

add to composer.json

"repositories": [
    {
        "type": "git",
        "url":  "https://github.com/skeeks-semenov/yii2-dadata-suggest-api.git"
    }
],

Either run

php composer.phar require --prefer-dist skeeks/yii2-dadata-suggest-api "*"

or add

"skeeks/yii2-dadata-suggest-api": "*"

How to use

//App config
[
    'components'    =>
    [
    //....
        'dadataSuggestApi' =>
        [
            'class'                 => 'skeeks\yii2\dadataSuggestApi\DadataSuggestApi',
            'authorization_token'   => 'token',
            'timeout'               => 12,
        ],
    //....
    ]
]

Examples

Адресные подсказки

$response = \Yii::$app->dadataSuggestApi->send('/rs/suggest/address', [
    'query' => 'Хабар',
    'count' => 10
]);

print_r($response->httpClientRequest->url);     //Full api url
print_r($response->httpClientRequest->data);    //Request data
print_r($response->httpClientRequest->method);  //Request method
print_r($response->httpClientRequest->headers); //Request headers

print_r($response->httpClientResponse->statusCode); //Server response code
print_r($response->httpClientResponse->content);    //Original api response

if ($response->isError)
{
    print_r($response->errorMessage); //Расшифровка кода
    print_r($response->errorData);
    print_r($response->errorCode);
} else
{
    print_r($response->data); //Array response data
}

Определение положения пользователя по ip

$response = \Yii::$app->dadataSuggestApi->detectAddressByIp(\Yii::$app->request->userIP);

Подсказки email

$response = \Yii::$app->dadataSuggestApi->getEmail([
    'query' => 'info@',
    'count' => 10
]);

Подсказки фио

$response = \Yii::$app->dadataSuggestApi->getFio([
    'query' => 'Семен',
    'count' => 10
]);

skeeks!
SkeekS CMS (Yii2) — fast, simple, effective!
skeeks.com | cms.skeeks.com | marketplace.cms.skeeks.com