Skip to content

Commit

Permalink
Abstract out model boilerplate to BaseModel class
Browse files Browse the repository at this point in the history
  • Loading branch information
jlevers committed Nov 14, 2022
1 parent 0468c10 commit 24e6823
Show file tree
Hide file tree
Showing 1,122 changed files with 3,860 additions and 217,550 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ composer.phar
/vendor/
/.openapi-generator/
/.openapi-generator-ignore
/.version

# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
Expand All @@ -18,3 +19,6 @@ composer.lock
# IDE
.idea
.vscode

# OS X
**/.DS_Store
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2021, Jesse Evers
Copyright (c) 2022, Highside Labs
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ class CustomAuthorizationSigner implements AuthorizationSignerContract
<?php
require_once(__DIR__ . '/vendor/autoload.php');

use SellingPartnerApi\Api;
use SellingPartnerApi\Api\SellersV1Api as SellersApi;
use SellingPartnerApi\Configuration;
use SellingPartnerApi\Endpoint;
use CustomAuthorizationSigner;
Expand All @@ -438,15 +438,13 @@ $config = new Configuration([
...,
'authorizationSigner' => new CustomAuthorizationSigner(),
]);
$api = new Api\SellersApi($config);
$api = new SellersApi($config);
try {
$result = $api->getMarketplaceParticipations();
$headers = $result->headers;
print_r($headers);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling SellersApi->getMarketplaceParticipations: ', $e->getMessage(), PHP_EOL;
}

```

## Custom Request Signer
Expand Down Expand Up @@ -476,7 +474,7 @@ class RemoteRequestSigner implements RequestSignerContract
<?php
require_once(__DIR__ . '/vendor/autoload.php');

use SellingPartnerApi\Api;
use SellingPartnerApi\Api\SellersV1Api as SellersApi;
use SellingPartnerApi\Configuration;
use SellingPartnerApi\Endpoint;
use RemoteRequestSigner;
Expand All @@ -485,13 +483,11 @@ $config = new Configuration([
...,
'requestSigner' => new RemoteRequestSigner(),
]);
$api = new Api\SellersApi($config);
$api = new SellersApi($config);
try {
$result = $api->getMarketplaceParticipations();
$headers = $result->headers;
print_r($headers);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling SellersApi->getMarketplaceParticipations: ', $e->getMessage(), PHP_EOL;
}

```
13 changes: 12 additions & 1 deletion lib/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class Endpoint
'url' => 'https://sellingpartnerapi-na.amazon.com',
'region' => 'us-east-1',
];
public const NA_BUSINESS = [
'url' => 'https://na.business-api.amazon.com',
'region' => 'us-east-1',
];
public const NA_SANDBOX = [
'url' => 'https://sandbox.sellingpartnerapi-na.amazon.com',
'region' => 'us-east-1',
Expand All @@ -25,6 +29,10 @@ class Endpoint
'url' => 'https://sellingpartnerapi-eu.amazon.com',
'region' => 'eu-west-1',
];
public const EU_BUSINESS = [
'url' => 'https://eu.business-api.amazon.com',
'region' => 'eu-west-1',
];
public const EU_SANDBOX = [
'url' => 'https://sandbox.sellingpartnerapi-eu.amazon.com',
'region' => 'eu-west-1',
Expand All @@ -35,6 +43,10 @@ class Endpoint
'url' => 'https://sellingpartnerapi-fe.amazon.com',
'region' => 'us-west-2',
];
public const FE_BUSINESS = [
'url' => 'https://jp.business-api.amazon.com/',
'region' => 'us-west-2',
];
public const FE_SANDBOX = [
'url' => 'https://sandbox.sellingpartnerapi-fe.amazon.com',
'region' => 'us-west-2',
Expand All @@ -49,7 +61,6 @@ class Endpoint
* @throws InvalidArgumentException
* @return array of the endpoint details
*
* @throws InvalidArgumentException
*
* @link https://docs.developer.amazonservices.com/en_US/dev_guide/DG_Endpoints.html
*/
Expand Down
3 changes: 0 additions & 3 deletions lib/HeaderSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@

namespace SellingPartnerApi;

use \Exception;
use SellingPartnerApi\Authentication;

/**
* ApiException Class Doc Comment
*
Expand Down
212 changes: 2 additions & 210 deletions lib/Model/AplusContentV20201101/AplusPaginatedResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/

namespace SellingPartnerApi\Model\AplusContentV20201101;

use SellingPartnerApi\Model\BaseModel;
use \ArrayAccess;
use \SellingPartnerApi\Model\ModelInterface;
use \SellingPartnerApi\ObjectSerializer;
Expand All @@ -42,7 +42,7 @@
* @template TKey int|null
* @template TValue mixed|null
*/
class AplusPaginatedResponse implements ModelInterface, ArrayAccess, \JsonSerializable, \IteratorAggregate
class AplusPaginatedResponse extends BaseModel implements ModelInterface, ArrayAccess, \JsonSerializable, \IteratorAggregate
{
public const DISCRIMINATOR = null;

Expand Down Expand Up @@ -75,25 +75,7 @@ class AplusPaginatedResponse implements ModelInterface, ArrayAccess, \JsonSerial
'next_page_token' => null
];

/**
* Array of property to type mappings. Used for (de)serialization
*
* @return array
*/
public static function openAPITypes()
{
return self::$openAPITypes;
}

/**
* Array of property to format mappings. Used for (de)serialization
*
* @return array
*/
public static function openAPIFormats()
{
return self::$openAPIFormats;
}

/**
* Array of attributes where the key is the local name,
Expand Down Expand Up @@ -126,46 +108,7 @@ public static function openAPIFormats()
'next_page_token' => 'getNextPageToken'
];

/**
* Array of attributes where the key is the local name,
* and the value is the original name
*
* @return array
*/
public static function attributeMap()
{
return self::$attributeMap;
}

/**
* Array of attributes to setter functions (for deserialization of responses)
*
* @return array
*/
public static function setters()
{
return self::$setters;
}

/**
* Array of attributes to getter functions (for serialization of requests)
*
* @return array
*/
public static function getters()
{
return self::$getters;
}

/**
* The original name of the model.
*
* @return string
*/
public function getModelName()
{
return self::$openAPIModelName;
}

/**
* Associative array for storing property values
Expand Down Expand Up @@ -201,17 +144,6 @@ public function listInvalidProperties()
return $invalidProperties;
}

/**
* Validate all the properties in the model
* return true if all passed
*
* @return bool True if all properties are valid
*/
public function valid()
{
return count($this->listInvalidProperties()) === 0;
}


/**
* Gets warnings
Expand Down Expand Up @@ -266,146 +198,6 @@ public function setNextPageToken($next_page_token)

return $this;
}

/**
* Returns true if offset exists. False otherwise.
*
* @param integer $offset Offset
*
* @return boolean
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return isset($this->container[$offset]);
}

/**
* Gets offset.
*
* @param integer $offset Offset
*
* @return mixed|null
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->container[$offset] ?? null;
}

/**
* Sets value based on offset.
*
* @param int|null $offset Offset
* @param mixed $value Value to be set
*
* @return void
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
if (is_null($offset)) {
$this->container[] = $value;
} else {
$this->container[$offset] = $value;
}
}

/**
* Unsets offset.
*
* @param integer $offset Offset
*
* @return void
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
unset($this->container[$offset]);
}

/**
* Serializes the object to a value that can be serialized natively by json_encode().
* @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php
*
* @return mixed Returns data which can be serialized by json_encode(), which is a value
* of any type other than a resource.
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return ObjectSerializer::sanitizeForSerialization($this);
}

/**
* Gets the string presentation of the object
*
* @return string
*/
public function __toString()
{
return json_encode(
ObjectSerializer::sanitizeForSerialization($this),
JSON_PRETTY_PRINT
);
}

/**
* Gets a header-safe presentation of the object
*
* @return string
*/
public function toHeaderValue()
{
return json_encode(ObjectSerializer::sanitizeForSerialization($this));
}

/**
* Enable iterating over all of the model's attributes in $key => $value format
*
* @return \Traversable
*/
public function getIterator(): \Traversable
{
return (function () {
foreach ($this->container as $key => $value) {
yield $key => $value;
}
})();
}

/**
* Retrieves the property with the given name by converting the property accession
* to a getter call.
*
* @param string $propertyName
* @return mixed
*/
public function __get($propertyName)
{
// This doesn't make a syntactical difference since PHP is case-insensitive, but
// makes error messages clearer (e.g. "Call to undefined method getFoo()" rather
// than "Call to undefined method getfoo()").
$ucProp = ucfirst($propertyName);
$getter = "get$ucProp";
return $this->$getter();
}

/**
* Sets the property with the given name by converting the property accession
* to a setter call.
*
* @param string $propertyName
* @param mixed $propertyValue
* @return SellingPartnerApi\Model\AplusContentV20201101\AplusPaginatedResponse
*/
public function __set($propertyName, $propertyValue)
{
$ucProp = ucfirst($propertyName);
$setter = "set$ucProp";
$this->$setter($propertyValue);
return $this;
}
}


Loading

0 comments on commit 24e6823

Please sign in to comment.