Skip to content

Cache, authentication and request handlers for nalognl_megaplan and nalognl_new_deal WordPress plugins. These 2 plugins have common functionality, and in order to not repeat the same code in both plugins this package was created. It contains Megaplan authentication functionality, base 64 encoding and caching.

nalognl/megaplan-module

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Megaplan module WordPress plugin module

Build Status Total Downloads Latest Stable Version

Cache, authentication and request handlers for nalognl_megaplan and nalognl_new_deal WordPress plugins. These 2 plugins have common functionality, and in order to not repeat the same code in both plugins this package was created. It contains Megaplan authentication functionality, base 64 encoding and caching.

Load configurations

Load configurations in your boot file by calling load() method. These parameters are required for package to work. Also your WordPress plugin must have directories storage and storage/cache.

\Nalognl\MegaplanModule\Config::new()->load([
    'plugin_path' => '/var/www/html/wp-content/plugins/nalognl_megaplan',
    'cache_dir_path' => '/var/www/uploads/global-storage/cache',
    'megaplan_host' => getenv('NNND_HOST'),
    'megaplan_login' => getenv('NNND_LOGIN'),
    'megaplan_password' => getenv('NNND_PASSWORD'),
    'megaplan_hash_password' => getenv('NNND_MD5_HASH_PASSWORD'),
    'megaplan_api1_auth_uri' => getenv('NNND_AUTH_URI'),
    'megaplan_api3_auth_uri' => getenv('NNND_API3_AUTH_URI'),
]);

Usage

Megaplan request

You need to have RequestMegaplan1.php and RequestMegaplan3.php for both APIs. They must extend Nalognl\MegaplanModule\Http\RequestMegaplan\RequestMegaplan class, it gives you throwIfError() and getEnvOrThrow() methods, and most importantly request property with methods: post() and get(). Most of your methods in classes that extend RequestMegaplan will look something like that:

public function getOffers(array $data): array
{
    $uri = $this->getEnvOrThrow('NNND_OFFERS_LIST_URI');

    $res = $this->request->post($uri, $data);
    $this->throwIfError($res, 'API1: При попытке взять товары с мегаплана');

    return $res->data->offers;
}

Get started

To install the package you need to have Composer PHP package manager installed on your machine. Then you need to run the command below in the plugin directory.

composer require nalognl/megaplan-module

About

Cache, authentication and request handlers for nalognl_megaplan and nalognl_new_deal WordPress plugins. These 2 plugins have common functionality, and in order to not repeat the same code in both plugins this package was created. It contains Megaplan authentication functionality, base 64 encoding and caching.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages