Skip to content

Commit 1d2eafe

Browse files
committed
Bump minor version to 0.4.0, decrease number of places with raw package version
1 parent 4726dd8 commit 1d2eafe

8 files changed

Lines changed: 159 additions & 8 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "highsidelabs/walmart-api",
3-
"version": "0.3.2",
3+
"version": "0.4.0",
44
"description": "A PHP client for Walmart's Marketplace, Content Provider, Drop Ship Vendor, and Warehouse Supplier APIs.",
55
"keywords": [
66
"walmart",

resources/generator-config.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"artifactVersion": "0.3.2",
2+
"artifactVersion": "0.4.0",
33

44
"disallowAdditionalPropertiesIfNotPresent": false,
55
"variableNamingConvention": "camelCase",
@@ -13,6 +13,11 @@
1313
"invokerPackage": "Walmart",
1414

1515
"files": {
16+
"Walmart.hbs": {
17+
"folder": "src",
18+
"destinationFilename": "Walmart.php",
19+
"templateType": "SupportingFiles"
20+
},
1621
"BaseApi.hbs": {
1722
"folder": "src/Apis",
1823
"destinationFilename": "BaseApi.php",

resources/templates/BaseApi.hbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use GuzzleHttp\RequestOptions;
2020
use Ramsey\Uuid\Uuid;
2121
use {{invokerPackage}}\Configuration;
2222
use {{invokerPackage}}\HeaderSelector;
23+
use {{invokerPackage}}\Walmart;
2324

2425
/**
2526
* BaseApi Class Doc Comment
@@ -83,7 +84,7 @@ class BaseApi
8384
protected function getDefaultHeaders(): array
8485
{
8586
return [
86-
'WM_SVC.NAME' => 'highsidelabs/walmart-api/{{artifactVersion}}',
87+
'WM_SVC.NAME' => 'highsidelabs/walmart-api/' . Walmart::VERSION,
8788
'WM_QOS.CORRELATION_ID' => Uuid::uuid4()->toString(),
8889
// These aren't required by every endpoint, but many use them and passing the when they're
8990
// not needed doesn't adversely affect the request

resources/templates/Configuration.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class Configuration
9393
*
9494
* @var string
9595
*/
96-
protected string $userAgent = '{{{httpUserAgent}}}{{#unless httpUserAgent}}OpenAPI-Generator/{{{artifactVersion}}}{{#unless artifactVersion}}1.0.0{{/unless}}/PHP{{/unless}}';
96+
protected string $userAgent = '{{{httpUserAgent}}}';
9797

9898
/**
9999
* Debug switch (default set to false)

resources/templates/Walmart.hbs

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?php
2+
3+
/**
4+
* Walmart
5+
* PHP version 7.4
6+
*
7+
* @category Class
8+
* @package {{invokerPackage}}
9+
* @author Jesse Evers
10+
* @link https://highsidelabs.co
11+
*/
12+
13+
{{>partials/partial_header}}
14+
15+
namespace {{invokerPackage}};
16+
17+
use BadMethodCallException;
18+
use RuntimeException;
19+
use {{apiPackage}}\CP\ContentProviderApi;
20+
use {{apiPackage}}\DSV\DropShipVendorApi;
21+
use {{apiPackage}}\MP\MarketplaceApi;
22+
use {{apiPackage}}\WS\WarehouseSupplierApi;
23+
use {{invokerPackage}}\Configuration;
24+
25+
abstract class Walmart
26+
{
27+
public const VERSION = '{{artifactVersion}}';
28+
29+
/**
30+
* The configuration for this client.
31+
* @var Configuration
32+
*/
33+
protected Configuration $config;
34+
35+
/**
36+
* The country to API class map. This should be overwritten by every child class.
37+
* @var array<string, string[]>
38+
*/
39+
protected static array $countryApiMap;
40+
41+
/**
42+
* Create a new Walmart client.
43+
*
44+
* @param Configuration $config The configuration for this client.
45+
* @param ?string $country The country to use for this client.
46+
*/
47+
public function __construct(Configuration $config)
48+
{
49+
$this->config = $config;
50+
}
51+
52+
/**
53+
* Enable calling country-specific APIs as single methods on this class, without needing to
54+
* specify the country outside $this->config or manually instantiate the API class.
55+
*
56+
* @param mixed $name The name of the method being called.
57+
* @param mixed $arguments The arguments passed to the callee.
58+
* @throws BadMethodCallException
59+
* @throws RuntimeException
60+
* @return mixed
61+
*/
62+
public function __call($name, $arguments)
63+
{
64+
// Don't override existing methods
65+
if (method_exists(get_class($this), $name)) {
66+
return $this->$name(...$arguments);
67+
}
68+
69+
if (!array_key_exists($name, static::$countryApiMap)) {
70+
throw new BadMethodCallException("Method $name does not exist");
71+
}
72+
73+
if (!array_key_exists($this->config->getCountry(), static::$countryApiMap[$name])) {
74+
$supportedCountriesStr = implode(', ', array_keys(static::$countryApiMap[$name]));
75+
throw new RuntimeException(
76+
"$name API is not supported in country {$this->config->getCountry()}. Supported country(ies): $supportedCountriesStr"
77+
);
78+
}
79+
80+
$apiClass = static::$countryApiMap[$name][$this->config->getCountry()];
81+
return new $apiClass($this->config);
82+
}
83+
84+
/**
85+
* Return an instance of the Content Provider API provider.
86+
*
87+
* @param Configuration $config
88+
* @return ContentProviderApi
89+
*/
90+
public static function contentProvider(Configuration $config): ContentProviderApi
91+
{
92+
return new ContentProviderApi($config);
93+
}
94+
95+
/**
96+
* Return an instance of the Drop Ship Vendor API provider.
97+
*
98+
* @param Configuration $config
99+
* @return DropShipVendorApi
100+
*/
101+
public static function dropShipVendor(Configuration $config): DropShipVendorApi
102+
{
103+
return new DropShipVendorApi($config);
104+
}
105+
106+
/**
107+
* Return an instance of the Marketplace API provider.
108+
*
109+
* @param Configuration $config
110+
* @return MarketplaceApi
111+
*/
112+
public static function marketplace(Configuration $config): MarketplaceApi
113+
{
114+
return new MarketplaceApi($config);
115+
}
116+
117+
/**
118+
* Return an instance of the Warehouse Supplier API provider.
119+
*
120+
* @param Configuration $config
121+
* @return WarehouseSupplierApi
122+
*/
123+
public static function warehouseSupplier(Configuration $config): WarehouseSupplierApi
124+
{
125+
return new WarehouseSupplierApi($config);
126+
}
127+
}

src/Apis/BaseApi.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Ramsey\Uuid\Uuid;
2626
use Walmart\Configuration;
2727
use Walmart\HeaderSelector;
28+
use Walmart\Walmart;
2829

2930
/**
3031
* BaseApi Class Doc Comment
@@ -88,7 +89,7 @@ public function getConfig()
8889
protected function getDefaultHeaders(): array
8990
{
9091
return [
91-
'WM_SVC.NAME' => 'highsidelabs/walmart-api/0.3.2',
92+
'WM_SVC.NAME' => 'highsidelabs/walmart-api/' . Walmart::VERSION,
9293
'WM_QOS.CORRELATION_ID' => Uuid::uuid4()->toString(),
9394
// These aren't required by every endpoint, but many use them and passing the when they're
9495
// not needed doesn't adversely affect the request

src/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class Configuration
9898
*
9999
* @var string
100100
*/
101-
protected string $userAgent = 'highsidelabs/walmart-api-php/0.3.2';
101+
protected string $userAgent = 'highsidelabs/walmart-api-php/0.4.0';
102102

103103
/**
104104
* Debug switch (default set to false)

src/Walmart.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
<?php
22

3-
namespace Walmart;
3+
/**
4+
* Walmart
5+
* PHP version 7.4
6+
*
7+
* @category Class
8+
* @package Walmart
9+
* @author Jesse Evers
10+
* @link https://highsidelabs.co
11+
*/
12+
13+
/**
14+
* Authentication & Authorization Management
15+
*
16+
* This class is auto-generated by the OpenAPI generator v6.6.0 (https://openapi-generator.tech).
17+
* Do not edit the class manually.
18+
*/
419

5-
require_once __DIR__ . '/../vendor/autoload.php';
20+
namespace Walmart;
621

722
use BadMethodCallException;
823
use RuntimeException;
@@ -14,6 +29,8 @@
1429

1530
abstract class Walmart
1631
{
32+
public const VERSION = '0.4.0';
33+
1734
/**
1835
* The configuration for this client.
1936
* @var Configuration

0 commit comments

Comments
 (0)