Skip to content

Commit 0b041fb

Browse files
authored
Merge pull request #3 from answear/data-fetching
Data fetching
2 parents a76544d + cfaa4df commit 0b041fb

26 files changed

+1192
-4
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"license": "MIT",
66
"require": {
77
"php": "^7.4 || ^8.0",
8-
"ext-xml": "*",
8+
"ext-simplexml": "*",
99
"guzzlehttp/guzzle": "^6.0",
1010
"marc-mabe/php-enum": "^4.3",
1111
"symfony/http-kernel": "^4.4 || ^5.0",

src/DependencyInjection/AnswearDpdPlPickupServicesExtension.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,17 @@ public function load(array $configs, ContainerBuilder $container): void
1919
new FileLocator(__DIR__ . '/../Resources/config')
2020
);
2121
$loader->load('services.yaml');
22+
23+
$configuration = $this->getConfiguration($configs, $container);
24+
$config = $this->processConfiguration($configuration, $configs);
25+
26+
$definition = $container->getDefinition(ConfigProvider::class);
27+
$definition->setArguments(
28+
[
29+
$config['url'],
30+
$config['key'],
31+
$config['requestTimeout'],
32+
]
33+
);
2234
}
2335
}

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99

1010
class Configuration implements ConfigurationInterface
1111
{
12-
private const API_URL = 'https://mypudo.dpd.com.pl/api/';
13-
private const CONNECTION_TIMEOUT = 10.0;
12+
public const API_URL = 'https://mypudo.dpd.com.pl/api/pudo/';
1413
private const REQUEST_TIMEOUT = 10.0;
1514

1615
public function getConfigTreeBuilder(): TreeBuilder
@@ -21,7 +20,6 @@ public function getConfigTreeBuilder(): TreeBuilder
2120
->children()
2221
->scalarNode('url')->defaultValue(self::API_URL)->end()
2322
->scalarNode('key')->cannotBeEmpty()->end()
24-
->floatNode('connectionTimeout')->defaultValue(self::CONNECTION_TIMEOUT)->end()
2523
->floatNode('requestTimeout')->defaultValue(self::REQUEST_TIMEOUT)->end()
2624
->end();
2725

src/Enum/Day.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Answear\DpdPlPickupServicesBundle\Enum;
6+
7+
use MabeEnum\Enum;
8+
9+
class Day extends Enum
10+
{
11+
public const MONDAY = '1';
12+
public const TUESDAY = '2';
13+
public const WEDNESDAY = '3';
14+
public const THURSDAY = '4';
15+
public const FRIDAY = '5';
16+
public const SATURDAY = '6';
17+
public const SUNDAY = '7';
18+
19+
public static function monday(): self
20+
{
21+
return static::get(static::MONDAY);
22+
}
23+
24+
public static function tuesday(): self
25+
{
26+
return static::get(static::TUESDAY);
27+
}
28+
29+
public static function wednesday(): self
30+
{
31+
return static::get(static::WEDNESDAY);
32+
}
33+
34+
public static function thursday(): self
35+
{
36+
return static::get(static::THURSDAY);
37+
}
38+
39+
public static function friday(): self
40+
{
41+
return static::get(static::FRIDAY);
42+
}
43+
44+
public static function saturday(): self
45+
{
46+
return static::get(static::SATURDAY);
47+
}
48+
49+
public static function sunday(): self
50+
{
51+
return static::get(static::SUNDAY);
52+
}
53+
}

src/Enum/Service.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Answear\DpdPlPickupServicesBundle\Enum;
6+
7+
use MabeEnum\Enum;
8+
9+
class Service extends Enum
10+
{
11+
public const DELIVERY = '100';
12+
public const COD = '101';
13+
public const SWAP = '300';
14+
public const DROPOFF_ONLINE = '200';
15+
public const DROPOFF_OFFLINE = '201';
16+
public const MONITORED_DOCUMENTS = 'P10';
17+
public const ROD = 'P20';
18+
public const TYRES = 'P30';
19+
public const PALLET = 'P90';
20+
21+
public static function delivery(): self
22+
{
23+
return static::get(static::DELIVERY);
24+
}
25+
26+
public static function cod(): self
27+
{
28+
return static::get(static::COD);
29+
}
30+
31+
public static function swap(): self
32+
{
33+
return static::get(static::SWAP);
34+
}
35+
36+
public static function dropoffOnline(): self
37+
{
38+
return static::get(static::DROPOFF_ONLINE);
39+
}
40+
41+
public static function dropoffOffline(): self
42+
{
43+
return static::get(static::DROPOFF_OFFLINE);
44+
}
45+
46+
public static function monitoredDocuments(): self
47+
{
48+
return static::get(static::MONITORED_DOCUMENTS);
49+
}
50+
51+
public static function rod(): self
52+
{
53+
return static::get(static::ROD);
54+
}
55+
56+
public static function tyres(): self
57+
{
58+
return static::get(static::TYRES);
59+
}
60+
61+
public static function pallet(): self
62+
{
63+
return static::get(static::PALLET);
64+
}
65+
}

src/Enum/Type.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Answear\DpdPlPickupServicesBundle\Enum;
6+
7+
use MabeEnum\Enum;
8+
9+
class Type extends Enum
10+
{
11+
public const STANDARD = '100';
12+
public const CHAIN = '200';
13+
public const DPD = '300';
14+
public const SWIP_BOX_1 = '400401';
15+
public const SWIP_BOX_2 = '400402';
16+
public const POINT_PACK = '500501';
17+
public const FOREIGN_LOCKER = '400';
18+
19+
public static function standard(): self
20+
{
21+
return self::get(self::STANDARD);
22+
}
23+
24+
public static function chain(): self
25+
{
26+
return self::get(self::CHAIN);
27+
}
28+
29+
public static function dpd(): self
30+
{
31+
return self::get(self::DPD);
32+
}
33+
34+
public static function swipBox1(): self
35+
{
36+
return self::get(self::SWIP_BOX_1);
37+
}
38+
39+
public static function swipBox2(): self
40+
{
41+
return self::get(self::SWIP_BOX_2);
42+
}
43+
44+
public static function pointPack(): self
45+
{
46+
return self::get(self::POINT_PACK);
47+
}
48+
49+
public static function foreignLocker(): self
50+
{
51+
return self::get(self::FOREIGN_LOCKER);
52+
}
53+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Answear\DpdPlPickupServicesBundle\Exception;
6+
7+
class MalformedResponseException extends \RuntimeException
8+
{
9+
private string $response;
10+
11+
public function __construct(string $response)
12+
{
13+
parent::__construct('Response is not a valid XML');
14+
$this->response = $response;
15+
}
16+
17+
public function getResponse(): string
18+
{
19+
return $this->response;
20+
}
21+
}

src/Exception/ServiceException.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Answear\DpdPlPickupServicesBundle\Exception;
6+
7+
class ServiceException extends \RuntimeException
8+
{
9+
}

src/Resources/config/services.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ services:
44
autoconfigure: true
55
public: false
66

7+
Answear\DpdPlPickupServicesBundle\:
8+
resource: '../../{Service}'

src/Service/ConfigProvider.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Answear\DpdPlPickupServicesBundle\Service;
6+
7+
class ConfigProvider
8+
{
9+
private string $url;
10+
private string $key;
11+
private float $requestTimeout;
12+
13+
public function __construct(string $url, string $key, float $requestTimeout)
14+
{
15+
$this->url = rtrim($url, '/') . '/';
16+
$this->key = $key;
17+
$this->requestTimeout = $requestTimeout;
18+
}
19+
20+
public function getUrl(): string
21+
{
22+
return $this->url;
23+
}
24+
25+
public function getKey(): string
26+
{
27+
return $this->key;
28+
}
29+
30+
public function getRequestTimeout(): float
31+
{
32+
return $this->requestTimeout;
33+
}
34+
}

0 commit comments

Comments
 (0)