File tree Expand file tree Collapse file tree 7 files changed +220
-0
lines changed Expand file tree Collapse file tree 7 files changed +220
-0
lines changed Original file line number Diff line number Diff line change 1
1
# loyalty-php-sdk
2
2
3
+ ## 0.1.1 (18.01.2019)
4
+ * add transport ` Settings `
5
+
3
6
## 0.1.0 (2.01.2019)
4
7
* initial version
Original file line number Diff line number Diff line change
1
+ <?php
2
+ declare (strict_types=1 );
3
+
4
+ namespace B24io \Loyalty \SDK \Settings \DTO ;
5
+
6
+ use B24io \Loyalty \SDK \Cards ;
7
+ use B24io \Loyalty \SDK \Users ;
8
+ use Money \Currency ;
9
+
10
+ /**
11
+ * Class Fabric
12
+ *
13
+ * @package B24io\Loyalty\SDK\Settings\DTO
14
+ */
15
+ class Fabric
16
+ {
17
+ /**
18
+ * @param array $settings
19
+ *
20
+ * @return Settings
21
+ */
22
+ public static function initSettingsFromArray (array $ settings ): Settings
23
+ {
24
+ $ newSettings = new Settings ();
25
+ $ newSettings
26
+ ->setCurrency (new Currency ($ settings ['currency ' ]['application_currency_code ' ]));
27
+
28
+ return $ newSettings ;
29
+ }
30
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ declare (strict_types=1 );
3
+
4
+ namespace B24io \Loyalty \SDK \Settings \DTO ;
5
+
6
+ use Money \Currency ;
7
+
8
+ /**
9
+ * Class Settings
10
+ *
11
+ * @package B24io\Loyalty\SDK\Settings\DTO
12
+ */
13
+ class Settings
14
+ {
15
+ /**
16
+ * @var Currency
17
+ */
18
+ private $ currency ;
19
+
20
+ /**
21
+ * @return Currency
22
+ */
23
+ public function getCurrency (): Currency
24
+ {
25
+ return $ this ->currency ;
26
+ }
27
+
28
+ /**
29
+ * @param Currency $currency
30
+ *
31
+ * @return Settings
32
+ */
33
+ public function setCurrency (Currency $ currency ): Settings
34
+ {
35
+ $ this ->currency = $ currency ;
36
+
37
+ return $ this ;
38
+ }
39
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ declare (strict_types=1 );
3
+
4
+ namespace B24io \Loyalty \SDK \Settings \Formatters ;
5
+
6
+ use B24io \Loyalty ;
7
+
8
+ /**
9
+ * Class Settings
10
+ *
11
+ * @package B24io\Loyalty\SDK\Settings\Formatters
12
+ */
13
+ class Settings
14
+ {
15
+ /**
16
+ * @param Loyalty\SDK\Settings\DTO\Settings $settings
17
+ *
18
+ * @return array
19
+ */
20
+ public static function toArray (Loyalty \SDK \Settings \DTO \Settings $ settings ): array
21
+ {
22
+ return [
23
+ 'currency ' => [
24
+ 'application_currency_code ' => $ settings ->getCurrency ()->getCode (),
25
+ ],
26
+ ];
27
+ }
28
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ declare (strict_types=1 );
3
+
4
+ namespace B24io \Loyalty \SDK \Settings \Transport \Admin ;
5
+
6
+ use B24io \Loyalty \SDK \ApiClient ;
7
+ use Psr \Log \LoggerInterface ;
8
+
9
+ /**
10
+ * Class Fabric
11
+ *
12
+ * @package B24io\Loyalty\SDK\Cards\Transport\Admin
13
+ */
14
+ class Fabric
15
+ {
16
+ /**
17
+ * @param ApiClient $apiClient
18
+ * @param LoggerInterface $logger
19
+ *
20
+ * @return Transport
21
+ */
22
+ public static function getSettingsTransport (ApiClient $ apiClient , LoggerInterface $ logger ): Transport
23
+ {
24
+ return new Transport ($ apiClient , $ logger );
25
+ }
26
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ declare (strict_types=1 );
3
+
4
+ namespace B24io \Loyalty \SDK \Settings \Transport \Admin ;
5
+
6
+ use B24io \Loyalty \SDK ;
7
+
8
+ use Fig \Http \Message \RequestMethodInterface ;
9
+
10
+ /**
11
+ * Class Transport
12
+ *
13
+ * @package B24io\Loyalty\SDK\Settings\Transport\Admin
14
+ */
15
+ class Transport extends SDK \Transport \AbstractTransport
16
+ {
17
+ /**
18
+ * @return SDK\Settings\Transport\DTO\SettingsResponse
19
+ * @throws SDK\Exceptions\ApiClientException
20
+ * @throws SDK\Exceptions\NetworkException
21
+ * @throws SDK\Exceptions\UnknownException
22
+ */
23
+ public function getApplicationSettings (): SDK \Settings \Transport \DTO \SettingsResponse
24
+ {
25
+ $ this ->log ->debug ('b24io.loyalty.sdk.settings.transport.admin.getApplicationSettings.start ' );
26
+
27
+ $ requestResult = $ this ->apiClient ->executeApiRequest (
28
+ 'admin/settings/application ' ,
29
+ RequestMethodInterface::METHOD_GET );
30
+
31
+ $ settingsResponse = new SDK \Settings \Transport \DTO \SettingsResponse (
32
+ $ this ->initMetadata ($ requestResult ['meta ' ]),
33
+ SDK \Settings \DTO \Fabric::initSettingsFromArray ($ requestResult ['result ' ])
34
+ );
35
+
36
+ $ this ->log ->debug ('b24io.loyalty.sdk.settings.transport.admin.getApplicationSettings.finish ' , [
37
+ 'metadata ' => SDK \Transport \Formatters \Metadata::toArray ($ settingsResponse ->getMeta ()),
38
+ ]);
39
+
40
+ return $ settingsResponse ;
41
+ }
42
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ declare (strict_types=1 );
3
+
4
+ namespace B24io \Loyalty \SDK \Settings \Transport \DTO ;
5
+
6
+ use B24io \Loyalty \SDK \Settings \DTO \Settings ;
7
+ use B24io \Loyalty \SDK \Transport \DTO \Metadata ;
8
+
9
+ /**
10
+ * Class SettingsResponse
11
+ *
12
+ * @package B24io\Loyalty\SDK\Settings\Transport\DTO
13
+ */
14
+ class SettingsResponse
15
+ {
16
+ /**
17
+ * @var Metadata
18
+ */
19
+ private $ meta ;
20
+ /**
21
+ * @var Settings
22
+ */
23
+ private $ settings ;
24
+
25
+ /**
26
+ * SettingsResponse constructor.
27
+ *
28
+ * @param Metadata $meta
29
+ * @param Settings $settings
30
+ */
31
+ public function __construct (Metadata $ meta , Settings $ settings )
32
+ {
33
+ $ this ->meta = $ meta ;
34
+ $ this ->settings = $ settings ;
35
+ }
36
+
37
+ /**
38
+ * @return Metadata
39
+ */
40
+ public function getMeta (): Metadata
41
+ {
42
+ return $ this ->meta ;
43
+ }
44
+
45
+ /**
46
+ * @return Settings
47
+ */
48
+ public function getSettings (): Settings
49
+ {
50
+ return $ this ->settings ;
51
+ }
52
+ }
You can’t perform that action at this time.
0 commit comments