Skip to content

Commit

Permalink
Merge pull request #2 from Gerfey/AL_update_client
Browse files Browse the repository at this point in the history
Дополнил немного клиент
  • Loading branch information
Gerfey authored Aug 2, 2022
2 parents bc67ede + fc93430 commit 39a7554
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 123 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
77 changes: 75 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,75 @@
# tecdoc
Клиент для работы c TecDoc API
# TecDoc API

[![Source Code][badge-source]][source]
[![Software License][badge-license]][license]
[![Total Downloads][badge-downloads]][downloads]

gerfey/tecdoc-client - client for working with the TecDoc API, designed to run on Laravel.

## Installation

The preferred method of installation is via [Packagist][] and [Composer][]. Run
the following command to install the package and add it as a requirement to your
project's `composer.json`:

```bash
composer require gerfey/tecdoc-client
```

### Settings

1. Use command ```php artisan vendor:publish ``` and select tag: ***tecdoc***
2. Check files ***tecdoc.php*** to path ***.../laravel-project/config/***
3. Create the ***TECDOC_PROVIDER_ID***, ***TECDOC_API_KEY***, ***TECDOC_LANGUAGE_CODE*** keys in the file ***.env***

### Run

```php
<?php

$tecDoc = new \Gerfey\TecDoc\Request\Pegasus\Pegasus_3_0(new \Gerfey\TecDoc\Http\TecDocClient());
dd($tecDoc->getAmBrands()->getJson());
```

### Result

```json
{#1821
+"data": {#1820
+"array": array:142 [
0 => {#1685
+"brandId": 1
+"brandLogoID": "100000"
+"brandName": "SPIDAN"
}
1 => {#1677
+"brandId": 2
+"brandLogoID": "200001"
+"brandName": "HELLA"
}
...
]
}
+"status": 200
}
```

## Copyright and License

The gerfey/tecdoc-client library is copyright © [Alexander Levchenkov](https://vk.com/gerfey) and
licensed for use under the MIT License (MIT). Please see [LICENSE][] for more
information.

[packagist]: https://packagist.org/packages/gerfey/tecdoc-client
[composer]: http://getcomposer.org/

[badge-source]: https://img.shields.io/badge/gerfey/tecdoc-client-blue.svg?style=flat-square
[badge-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[badge-build]: https://img.shields.io/travis/gerfey/tecdoc-client/master.svg?style=flat-square
[badge-downloads]: https://img.shields.io/packagist/dt/gerfey/tecdoc-client.svg?style=flat-square

[source]: https://github.com/gerfey/tecdoc-client
[release]: https://packagist.org/packages/gerfey/tecdoc-client
[license]: https://github.com/gerfey/tecdoc-client/blob/master/LICENSE
[build]: https://travis-ci.org/gerfey/tecdoc-client
[downloads]: https://packagist.org/packages/gerfey/tecdoc-client
78 changes: 44 additions & 34 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,46 @@
{
"name": "gerfey/tecdoc-client",
"description": "Client for working with the TecDoc API",
"keywords": [
"Gerfey",
"API",
"TecDoc"
],
"homepage": "https://github.com/Gerfey/tecdoc-client",
"license": "MIT",
"authors": [
{
"name": "Alexander Levchenkov",
"email": "sanjia@live.ru",
"homepage": "https://github.com/gerfey",
"role": "Developer"
}
],
"require": {
"guzzlehttp/guzzle": "^7.3.0",
"jms/serializer": "^1.1"
},
"autoload": {
"psr-4": {
"Gerfey\\TecDoc\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Gerfey\\TecDoc\\": "tests/"
}
},
"config": {
"sort-packages": true
}
"name": "gerfey/tecdoc-client",
"description": "Client for working with the TecDoc API",
"keywords": [
"Gerfey",
"API",
"TecDoc"
],
"homepage": "https://github.com/Gerfey/tecdoc-client",
"license": "MIT",
"authors": [
{
"name": "Alexander Levchenkov",
"email": "sanjia@live.ru",
"homepage": "https://github.com/gerfey",
"role": "Developer"
}
],
"require": {
"php": "^8.0|^8.1",
"guzzlehttp/guzzle": "^7.4.5",
"jms/serializer": "^1.1"
},
"autoload": {
"psr-4": {
"Gerfey\\TecDoc\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Gerfey\\TecDoc\\": "tests/"
}
},
"extra": {
"laravel": {
"providers": [
"Gerfey\\TecDoc\\GerfeyTecDocServiceProvider"
]
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
5 changes: 1 addition & 4 deletions config/tecdoc.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<?php

return [
'hostname' => 'https://webservice.tecalliance.services',
'endpoint' => '/pegasus-3-0/services/TecdocToCatDLB.jsonEndpoint',

'auth' => [
'provider_id' => env('TECDOC_PROVIDER_ID'),
'api_key' => env('TECDOC_API_KEY'),
'language_code' => env('TECDOC_LANGUAGE_CODE'),
]
];
];
6 changes: 3 additions & 3 deletions src/Contracts/Http/ResponseTecDocInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

interface ResponseTecDocInterface
{
public function getJson();
public function getJson(): mixed;

public function getStatusCode();
}
public function getStatusCode(): int;
}
22 changes: 22 additions & 0 deletions src/GerfeyTecDocServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Gerfey\TecDoc;

use Illuminate\Support\ServiceProvider;

class GerfeyTecDocServiceProvider extends ServiceProvider
{
public function register()
{
if ($this->app->runningInConsole()) {
$this->mergeConfigFrom(__DIR__ . '/../config/tecdoc.php', 'tecdoc');

$this->publishes(
[
__DIR__ . '/../config/tecdoc.php' => config_path('tecdoc.php'),
],
'tecdoc'
);
}
}
}
35 changes: 9 additions & 26 deletions src/Http/BaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@

class BaseClient implements BaseClientInterface
{
protected $hostname = '';
protected string $hostname = '';

protected $endpoint = '';
protected string $endpoint = '';

protected $client;
protected Client $client;

/**
* BaseClient constructor.
*/
public function __construct()
{
$this->client = new Client([
Expand All @@ -28,20 +25,13 @@ public function __construct()
]);
}

/**
* @param string $method
* @param string $uri
* @param array $options
* @return ResponseTecDocInterface
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function createRequest(string $method = 'POST', array $options = []): ResponseTecDocInterface
{
try {
$response = $this->client->request($method, $this->endpoint, [
'content-type' => 'application/json',
'query' => [
'api_key' => getenv('TECDOC_API_KEY')
'api_key' => config('tecdoc.auth.api_key')
],
'body' => json_encode($this->getQueryOptions($options))
]);
Expand All @@ -51,10 +41,6 @@ public function createRequest(string $method = 'POST', array $options = []): Res
}
}

/**
* @param array $options
* @return array
*/
private function getQueryOptions(array $options = []): array
{
$correct_options = [];
Expand All @@ -64,17 +50,14 @@ private function getQueryOptions(array $options = []): array
return $correct_options;
}

/**
* @return array
*/
private function getDefaultOptions(): array
{
return [
'provider' => getenv('TECDOC_PROVIDER_ID'),
'country' => getenv('TECDOC_LANGUAGE_CODE'),
'lang' => getenv('TECDOC_LANGUAGE_CODE'),
'articleCountry' => getenv('TECDOC_LANGUAGE_CODE'),
'countriesCarSelection' => getenv('TECDOC_LANGUAGE_CODE')
'provider' => config('tecdoc.auth.provider_id'),
'country' => config('tecdoc.auth.language_code'),
'lang' => config('tecdoc.auth.language_code'),
'articleCountry' => config('tecdoc.auth.language_code'),
'countriesCarSelection' => config('tecdoc.auth.language_code')
];
}
}
8 changes: 4 additions & 4 deletions src/Http/ResponseTecDoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@

class ResponseTecDoc implements ResponseTecDocInterface
{
private $response;
private ResponseInterface $response;

public function __construct(ResponseInterface $response)
{
$this->response = $response;
}

public function getJson()
public function getJson(): mixed
{
return json_decode($this->response->getBody()->getContents());
}

public function getStatusCode()
public function getStatusCode(): int
{
return $this->response->getStatusCode();
}
}
}
6 changes: 3 additions & 3 deletions src/Http/TecDocClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class TecDocClient extends BaseClient
{
protected $hostname = 'https://webservice.tecalliance.services';
protected string $hostname = 'https://webservice.tecalliance.services';

protected $endpoint = '/pegasus-3-0/services/TecdocToCatDLB.jsonEndpoint';
}
protected string $endpoint = '/pegasus-3-0/services/TecdocToCatDLB.jsonEndpoint';
}
33 changes: 0 additions & 33 deletions src/Request/Pegasus/Pegasus_3_0.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,6 @@ public function getArticleIdsWithState(
);
}

/**
* Получаем список производителей
*
* @param int $articleId
* @param string $linkingTargetType
*
* @return ResponseTecDocInterface|mixed
*/
public function getArticleLinkedAllLinkingTargetManufacturer(int $articleId, string $linkingTargetType = 'P')
{
$this->function = 'getArticleLinkedAllLinkingTargetManufacturer';
Expand All @@ -210,15 +202,6 @@ public function getArticleLinkedAllLinkingTargetManufacturer(int $articleId, str
);
}

/**
* Получаем список модификаций производителя
*
* @param int $articleId
* @param int $linkingTargetManuId
* @param string $linkingTargetType
*
* @return ResponseTecDocInterface|mixed
*/
public function getArticleLinkedAllLinkingTarget3(
int $articleId,
int $linkingTargetManuId,
Expand All @@ -236,15 +219,6 @@ public function getArticleLinkedAllLinkingTarget3(
);
}

/**
* Получаем информацию по выбранным модификациям производителя
*
* @param int $articleId
* @param array $linkedArticlePairs
* @param string $linkingTargetType
*
* @return ResponseTecDocInterface|mixed
*/
public function getArticleLinkedAllLinkingTargetsByIds3(
int $articleId,
array $linkedArticlePairs,
Expand All @@ -264,13 +238,6 @@ public function getArticleLinkedAllLinkingTargetsByIds3(
);
}

/**
* Получаем наименования по идентификатору модели машины
*
* @param array $carIds
*
* @return ResponseTecDocInterface|mixed
*/
public function getVehicleByIds4(array $carIds)
{
$this->function = 'getVehicleByIds4';
Expand Down
Loading

0 comments on commit 39a7554

Please sign in to comment.