Skip to content

Commit 4726dd8

Browse files
committed
Make clientId and clientSecret optional by moving them into constructor options array
1 parent c3bd8e6 commit 4726dd8

51 files changed

Lines changed: 1200 additions & 509 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ use Walmart\Configuration;
8484

8585
$clientId = '<YOUR CLIENT ID>';
8686
$clientSecret = '<YOUR CLIENT SECRET>';
87-
$config = new Walmart\Configuration($clientId, $clientSecret);
87+
$config = new Configuration([
88+
'clientId' => $clientId,
89+
'clientSecret' => $clientSecret,
90+
]);
8891
```
8992

9093
If you are a Marketplace Seller selling in the US (which is likely true of most people using this API), that's all the configuration you need to do to start making calls to the Marketplace API. If you want to call the Drop Ship Vendor, Content Provider, or Warehouse Supplier APIs, or if you sell goods outside the US and need to make calls to the Marketplace API for, you'll need to provide additional configuration parameters, which are detailed in the [Configuration](#configuration) section below.
@@ -97,7 +100,10 @@ Once you've created an instance of the `Configuration` class, you can start maki
97100
use Walmart\Configuration;
98101
use Walmart\Walmart;
99102

100-
$config = new Walmart\Configuration($clientId, $clientSecret);
103+
$config = new Configuration([
104+
'clientId' => $clientId,
105+
'clientSecret' => $clientSecret,
106+
]);
101107
$authApi = Walmart::marketplace($config)->auth();
102108

103109
// $authApi is an instance of Walmart\Apis\MP\US\AuthenticationApi
@@ -113,14 +119,13 @@ Similarly, the other API categories can be accessed via the `Walmart::dropShipVe
113119

114120
### Configuration
115121

116-
The `Configuration` class is used to configure the client library. It takes three arguments:
117-
- `$clientId`: Your Walmart Client ID
118-
- `$clientSecret`: Your Walmart Client Secret
119-
- `$options`: An optional associative array of additional configuration parameters. Valid options are:
120-
- `country`: The country you are selling in. One of `Country::US`, `Country::CA`, or `Country::MX`. Defaults to `US`.
121-
- `consumerId`: Your Walmart Consumer ID. Required if you are making requests to endpoints that use signature-based auth (see the [Authorization](#authorization) section)
122-
- `privateKey`: Your Walmart private key. Ditto the requirements for the `consumerId` option.
123-
- `accessToken`: An instance of `Walmart\AccessToken`, containing an access token and its expiration time. If provided, this will be used instead of the client ID and secret to authenticate API calls, until the token expires. This is useful if you want to reuse an access token that you've already retrieved from Walmart. More details on access token auth [below](#access-token-auth).
122+
The `Configuration` class is used to configure the client library. It takes a single options array as its only argument, which can contain the following keys:
123+
- `clientId`: Your Walmart Client ID
124+
- `clientSecret`: Your Walmart Client Secret
125+
- `country`: The country you are selling in. One of `Country::US`, `Country::CA`, or `Country::MX`. Defaults to `Country::US`.
126+
- `consumerId`: Your Walmart Consumer ID. Required if you are making requests to endpoints that use signature-based auth (see the [Authorization](#authorization) section)
127+
- `privateKey`: Your Walmart private key. Ditto the requirements for the `consumerId` option.
128+
- `accessToken`: An instance of `Walmart\AccessToken`, containing an access token and its expiration time. If provided, this will be used instead of the client ID and secret to authenticate API calls, until the token expires. This is useful if you want to reuse an access token that you've already retrieved from Walmart. More details on access token auth [below](#access-token-auth).
124129

125130
If you try to instantiate an instance of an API class that is not supported in the country you've specified, an exception will be thrown.
126131

@@ -139,7 +144,10 @@ Some endpoints have a LOT of parameters. If you're using PHP 8 or later, you can
139144
use Walmart\Configuration;
140145
use Walmart\Walmart;
141146

142-
$config = new Configuration($clientId, $clientSecret);
147+
$config = new Configuration([
148+
'clientId' => $clientId,
149+
'clientSecret' => $clientSecret,
150+
]);
143151
$itemsApi = Walmart::marketplace($config)->items();
144152

145153
$response = $itemsApi->getAllItems(
@@ -155,7 +163,10 @@ Instead of this:
155163
use Walmart\Configuration;
156164
use Walmart\Walmart;
157165

158-
$config = new Configuration($clientId, $clientSecret);
166+
$config = new Configuration([
167+
'clientId' => $clientId,
168+
'clientSecret' => $clientSecret,
169+
]);
159170
$itemsApi = Walmart::marketplace($config)->items();
160171

161172
$response = $itemsApi->getAllItems(
@@ -200,7 +211,10 @@ require_once __DIR__ . '/vendor/autoload.php';
200211

201212
use Walmart\Configuration;
202213

203-
$config = new Configuration($clientId, $clientSecret);
214+
$config = new Configuration([
215+
'clientId' => $clientId,
216+
'clientSecret' => $clientSecret,
217+
]);
204218
$config->setDebug(true);
205219
// To redirect debug info to a file:
206220
$config->setDebugFile('debug.log');

docs/Apis/CP/US/FeedsApi.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ You can update 10,000 items at once; updates with more than 10,000 items are not
2323
```php
2424
<?php
2525
use Walmart\Configuration;
26+
use Walmart\Country;
2627
use Walmart\Walmart;
2728

2829
require_once __DIR__ . '/vendor/autoload.php';
2930

30-
$config = new Walmart\Configuration('CLIENT_ID', 'CLIENT_SECRET', [
31-
'country' => 'US', // Default US if not set
31+
$config = new Walmart\Configuration([
32+
'clientId' => 'CLIENT_ID', // May not be necessary for all endpoints, particularly outside the US
33+
'clientSecret' => 'CLIENT_SECRET', // Ditto above
34+
'country' => Country::US, // Default Country::US if not set
3235
'privateKey' => 'PRIVATE_KEY',
3336
'consumerId' => 'CONSUMER_ID',
3437
]);
@@ -85,12 +88,15 @@ You can display an item status for a specific feed ID. Use the feed ID returned
8588
```php
8689
<?php
8790
use Walmart\Configuration;
91+
use Walmart\Country;
8892
use Walmart\Walmart;
8993

9094
require_once __DIR__ . '/vendor/autoload.php';
9195

92-
$config = new Walmart\Configuration('CLIENT_ID', 'CLIENT_SECRET', [
93-
'country' => 'US', // Default US if not set
96+
$config = new Walmart\Configuration([
97+
'clientId' => 'CLIENT_ID', // May not be necessary for all endpoints, particularly outside the US
98+
'clientSecret' => 'CLIENT_SECRET', // Ditto above
99+
'country' => Country::US, // Default Country::US if not set
94100
'privateKey' => 'PRIVATE_KEY',
95101
'consumerId' => 'CONSUMER_ID',
96102
]);
@@ -149,12 +155,15 @@ You can display the status of all items for a specific feed ID. Use the feed ID
149155
```php
150156
<?php
151157
use Walmart\Configuration;
158+
use Walmart\Country;
152159
use Walmart\Walmart;
153160

154161
require_once __DIR__ . '/vendor/autoload.php';
155162

156-
$config = new Walmart\Configuration('CLIENT_ID', 'CLIENT_SECRET', [
157-
'country' => 'US', // Default US if not set
163+
$config = new Walmart\Configuration([
164+
'clientId' => 'CLIENT_ID', // May not be necessary for all endpoints, particularly outside the US
165+
'clientSecret' => 'CLIENT_SECRET', // Ditto above
166+
'country' => Country::US, // Default Country::US if not set
158167
'privateKey' => 'PRIVATE_KEY',
159168
'consumerId' => 'CONSUMER_ID',
160169
]);
@@ -215,12 +224,15 @@ Rich Media includes material such as videos, comparison tables, and view360 medi
215224
```php
216225
<?php
217226
use Walmart\Configuration;
227+
use Walmart\Country;
218228
use Walmart\Walmart;
219229

220230
require_once __DIR__ . '/vendor/autoload.php';
221231

222-
$config = new Walmart\Configuration('CLIENT_ID', 'CLIENT_SECRET', [
223-
'country' => 'US', // Default US if not set
232+
$config = new Walmart\Configuration([
233+
'clientId' => 'CLIENT_ID', // May not be necessary for all endpoints, particularly outside the US
234+
'clientSecret' => 'CLIENT_SECRET', // Ditto above
235+
'country' => Country::US, // Default Country::US if not set
224236
'privateKey' => 'PRIVATE_KEY',
225237
'consumerId' => 'CONSUMER_ID',
226238
]);

docs/Apis/DSV/US/CostApi.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ This API allows DSV to update cost for items in bulk.
2020
```php
2121
<?php
2222
use Walmart\Configuration;
23+
use Walmart\Country;
2324
use Walmart\Walmart;
2425

2526
require_once __DIR__ . '/vendor/autoload.php';
2627

27-
$config = new Walmart\Configuration('CLIENT_ID', 'CLIENT_SECRET', [
28-
'country' => 'US', // Default US if not set
28+
$config = new Walmart\Configuration([
29+
'clientId' => 'CLIENT_ID', // May not be necessary for all endpoints, particularly outside the US
30+
'clientSecret' => 'CLIENT_SECRET', // Ditto above
31+
'country' => Country::US, // Default Country::US if not set
2932
'privateKey' => 'PRIVATE_KEY',
3033
'consumerId' => 'CONSUMER_ID',
3134
]);

docs/Apis/DSV/US/FeedsApi.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ Displays an item status for a specific Feed ID. Use the Feed ID returned from th
2121
```php
2222
<?php
2323
use Walmart\Configuration;
24+
use Walmart\Country;
2425
use Walmart\Walmart;
2526

2627
require_once __DIR__ . '/vendor/autoload.php';
2728

28-
$config = new Walmart\Configuration('CLIENT_ID', 'CLIENT_SECRET', [
29-
'country' => 'US', // Default US if not set
29+
$config = new Walmart\Configuration([
30+
'clientId' => 'CLIENT_ID', // May not be necessary for all endpoints, particularly outside the US
31+
'clientSecret' => 'CLIENT_SECRET', // Ditto above
32+
'country' => Country::US, // Default Country::US if not set
3033
'privateKey' => 'PRIVATE_KEY',
3134
'consumerId' => 'CONSUMER_ID',
3235
]);
@@ -85,12 +88,15 @@ Returns the status of all items for a specific feedId. We do not recommend usin
8588
```php
8689
<?php
8790
use Walmart\Configuration;
91+
use Walmart\Country;
8892
use Walmart\Walmart;
8993

9094
require_once __DIR__ . '/vendor/autoload.php';
9195

92-
$config = new Walmart\Configuration('CLIENT_ID', 'CLIENT_SECRET', [
93-
'country' => 'US', // Default US if not set
96+
$config = new Walmart\Configuration([
97+
'clientId' => 'CLIENT_ID', // May not be necessary for all endpoints, particularly outside the US
98+
'clientSecret' => 'CLIENT_SECRET', // Ditto above
99+
'country' => Country::US, // Default Country::US if not set
94100
'privateKey' => 'PRIVATE_KEY',
95101
'consumerId' => 'CONSUMER_ID',
96102
]);

docs/Apis/DSV/US/InventoryApi.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ This request retrieves the inventory count for a single item for one specific sh
2323
```php
2424
<?php
2525
use Walmart\Configuration;
26+
use Walmart\Country;
2627
use Walmart\Walmart;
2728

2829
require_once __DIR__ . '/vendor/autoload.php';
2930

30-
$config = new Walmart\Configuration('CLIENT_ID', 'CLIENT_SECRET', [
31-
'country' => 'US', // Default US if not set
31+
$config = new Walmart\Configuration([
32+
'clientId' => 'CLIENT_ID', // May not be necessary for all endpoints, particularly outside the US
33+
'clientSecret' => 'CLIENT_SECRET', // Ditto above
34+
'country' => Country::US, // Default Country::US if not set
3235
'privateKey' => 'PRIVATE_KEY',
3336
'consumerId' => 'CONSUMER_ID',
3437
]);
@@ -87,12 +90,15 @@ This request retrieves the inventory count for an item across multiple ship node
8790
```php
8891
<?php
8992
use Walmart\Configuration;
93+
use Walmart\Country;
9094
use Walmart\Walmart;
9195

9296
require_once __DIR__ . '/vendor/autoload.php';
9397

94-
$config = new Walmart\Configuration('CLIENT_ID', 'CLIENT_SECRET', [
95-
'country' => 'US', // Default US if not set
98+
$config = new Walmart\Configuration([
99+
'clientId' => 'CLIENT_ID', // May not be necessary for all endpoints, particularly outside the US
100+
'clientSecret' => 'CLIENT_SECRET', // Ditto above
101+
'country' => Country::US, // Default Country::US if not set
96102
'privateKey' => 'PRIVATE_KEY',
97103
'consumerId' => 'CONSUMER_ID',
98104
]);
@@ -151,12 +157,15 @@ This request updates inventory for items in bulk. The seller can either use feed
151157
```php
152158
<?php
153159
use Walmart\Configuration;
160+
use Walmart\Country;
154161
use Walmart\Walmart;
155162

156163
require_once __DIR__ . '/vendor/autoload.php';
157164

158-
$config = new Walmart\Configuration('CLIENT_ID', 'CLIENT_SECRET', [
159-
'country' => 'US', // Default US if not set
165+
$config = new Walmart\Configuration([
166+
'clientId' => 'CLIENT_ID', // May not be necessary for all endpoints, particularly outside the US
167+
'clientSecret' => 'CLIENT_SECRET', // Ditto above
168+
'country' => Country::US, // Default Country::US if not set
160169
'privateKey' => 'PRIVATE_KEY',
161170
'consumerId' => 'CONSUMER_ID',
162171
]);
@@ -215,12 +224,15 @@ This request updates the inventory for an item, with the item global trade item
215224
```php
216225
<?php
217226
use Walmart\Configuration;
227+
use Walmart\Country;
218228
use Walmart\Walmart;
219229

220230
require_once __DIR__ . '/vendor/autoload.php';
221231

222-
$config = new Walmart\Configuration('CLIENT_ID', 'CLIENT_SECRET', [
223-
'country' => 'US', // Default US if not set
232+
$config = new Walmart\Configuration([
233+
'clientId' => 'CLIENT_ID', // May not be necessary for all endpoints, particularly outside the US
234+
'clientSecret' => 'CLIENT_SECRET', // Ditto above
235+
'country' => Country::US, // Default Country::US if not set
224236
'privateKey' => 'PRIVATE_KEY',
225237
'consumerId' => 'CONSUMER_ID',
226238
]);

docs/Apis/DSV/US/ItemsApi.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ Displays a list of all items. If no SKU is included in this request, all items a
2323
```php
2424
<?php
2525
use Walmart\Configuration;
26+
use Walmart\Country;
2627
use Walmart\Walmart;
2728

2829
require_once __DIR__ . '/vendor/autoload.php';
2930

30-
$config = new Walmart\Configuration('CLIENT_ID', 'CLIENT_SECRET', [
31-
'country' => 'US', // Default US if not set
31+
$config = new Walmart\Configuration([
32+
'clientId' => 'CLIENT_ID', // May not be necessary for all endpoints, particularly outside the US
33+
'clientSecret' => 'CLIENT_SECRET', // Ditto above
34+
'country' => Country::US, // Default Country::US if not set
3235
'privateKey' => 'PRIVATE_KEY',
3336
'consumerId' => 'CONSUMER_ID',
3437
]);
@@ -85,12 +88,15 @@ Retrieves an item and displays the item details.
8588
```php
8689
<?php
8790
use Walmart\Configuration;
91+
use Walmart\Country;
8892
use Walmart\Walmart;
8993

9094
require_once __DIR__ . '/vendor/autoload.php';
9195

92-
$config = new Walmart\Configuration('CLIENT_ID', 'CLIENT_SECRET', [
93-
'country' => 'US', // Default US if not set
96+
$config = new Walmart\Configuration([
97+
'clientId' => 'CLIENT_ID', // May not be necessary for all endpoints, particularly outside the US
98+
'clientSecret' => 'CLIENT_SECRET', // Ditto above
99+
'country' => Country::US, // Default Country::US if not set
94100
'privateKey' => 'PRIVATE_KEY',
95101
'consumerId' => 'CONSUMER_ID',
96102
]);
@@ -145,12 +151,15 @@ Updates items in bulk. You can update 10,000 items at once; updates with more t
145151
```php
146152
<?php
147153
use Walmart\Configuration;
154+
use Walmart\Country;
148155
use Walmart\Walmart;
149156

150157
require_once __DIR__ . '/vendor/autoload.php';
151158

152-
$config = new Walmart\Configuration('CLIENT_ID', 'CLIENT_SECRET', [
153-
'country' => 'US', // Default US if not set
159+
$config = new Walmart\Configuration([
160+
'clientId' => 'CLIENT_ID', // May not be necessary for all endpoints, particularly outside the US
161+
'clientSecret' => 'CLIENT_SECRET', // Ditto above
162+
'country' => Country::US, // Default Country::US if not set
154163
'privateKey' => 'PRIVATE_KEY',
155164
'consumerId' => 'CONSUMER_ID',
156165
]);
@@ -207,12 +216,15 @@ Rich Media includes material such as videos, comparison tables, and view360 medi
207216
```php
208217
<?php
209218
use Walmart\Configuration;
219+
use Walmart\Country;
210220
use Walmart\Walmart;
211221

212222
require_once __DIR__ . '/vendor/autoload.php';
213223

214-
$config = new Walmart\Configuration('CLIENT_ID', 'CLIENT_SECRET', [
215-
'country' => 'US', // Default US if not set
224+
$config = new Walmart\Configuration([
225+
'clientId' => 'CLIENT_ID', // May not be necessary for all endpoints, particularly outside the US
226+
'clientSecret' => 'CLIENT_SECRET', // Ditto above
227+
'country' => Country::US, // Default Country::US if not set
216228
'privateKey' => 'PRIVATE_KEY',
217229
'consumerId' => 'CONSUMER_ID',
218230
]);

docs/Apis/DSV/US/LagTimeApi.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ This request retrieves the lag time for an item with a given product identifier
2121
```php
2222
<?php
2323
use Walmart\Configuration;
24+
use Walmart\Country;
2425
use Walmart\Walmart;
2526

2627
require_once __DIR__ . '/vendor/autoload.php';
2728

28-
$config = new Walmart\Configuration('CLIENT_ID', 'CLIENT_SECRET', [
29-
'country' => 'US', // Default US if not set
29+
$config = new Walmart\Configuration([
30+
'clientId' => 'CLIENT_ID', // May not be necessary for all endpoints, particularly outside the US
31+
'clientSecret' => 'CLIENT_SECRET', // Ditto above
32+
'country' => Country::US, // Default Country::US if not set
3033
'privateKey' => 'PRIVATE_KEY',
3134
'consumerId' => 'CONSUMER_ID',
3235
]);
@@ -85,12 +88,15 @@ This request updates the lag time for items in bulk. Lag time is the number of d
8588
```php
8689
<?php
8790
use Walmart\Configuration;
91+
use Walmart\Country;
8892
use Walmart\Walmart;
8993

9094
require_once __DIR__ . '/vendor/autoload.php';
9195

92-
$config = new Walmart\Configuration('CLIENT_ID', 'CLIENT_SECRET', [
93-
'country' => 'US', // Default US if not set
96+
$config = new Walmart\Configuration([
97+
'clientId' => 'CLIENT_ID', // May not be necessary for all endpoints, particularly outside the US
98+
'clientSecret' => 'CLIENT_SECRET', // Ditto above
99+
'country' => Country::US, // Default Country::US if not set
94100
'privateKey' => 'PRIVATE_KEY',
95101
'consumerId' => 'CONSUMER_ID',
96102
]);

0 commit comments

Comments
 (0)