Skip to content

Commit

Permalink
Merge pull request #110 from sensereen/master
Browse files Browse the repository at this point in the history
Api 1.2, gzip and api-token support, saleschannel entity
  • Loading branch information
tooyz authored Jun 7, 2024
2 parents abab694 + 41ff402 commit f9e26cc
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
15 changes: 12 additions & 3 deletions src/Components/Http/MoySkladHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,22 @@ public function delete($method, $payload = [], $options = null){
*/
public function getRaw($link, $options) {
if (empty($options['headers']['Authorization'])) {
$options['headers']['Authorization'] = "Basic " . base64_encode($this->login . ':' . $this->password);
$options['headers']['Authorization'] = $this->getAuthorizationHeader();
}

$client = new Client();
return $client->get($link, $options);
}

private function getAuthorizationHeader() {
if (is_null($this->password)) {
$authorizationHeader = 'Bearer '.$this->login;
} else {
$authorizationHeader = "Basic " . base64_encode($this->login . ':' . $this->password);
}
return $authorizationHeader;
}

public function getLastRequest(){
return RequestLog::getLast();
}
Expand Down Expand Up @@ -157,8 +166,8 @@ private function makeRequest(
}

$headers = [
"Content-Encoding" => "gzip",
"Authorization" => "Basic " . base64_encode($this->login . ':' . $password)
"Accept-Encoding" => "gzip",
"Authorization" => $this->getAuthorizationHeader()
];
$config = [
"base_uri" => $endpoint,
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Specs/QuerySpecs/QuerySpecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class QuerySpecs extends AbstractSpecs {
protected static $cachedDefaultSpecs = null;
const MAX_LIST_LIMIT = 100;
const MAX_LIST_LIMIT = 1000;

/**
* Get possible variables for spec, will be sent as query string
Expand Down
11 changes: 11 additions & 0 deletions src/Entities/Saleschannel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace MoySklad\Entities;

use MoySklad\Entities\AbstractEntity;

class Saleschannel extends AbstractEntity
{
public static
$entityName = 'saleschannel';
}
14 changes: 9 additions & 5 deletions src/MoySklad.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MoySklad{
*/
private static $instances = [];

private function __construct($login, $password, $posToken, $hashCode, $subdomain = "online")
private function __construct($login, $password, $posToken, $hashCode, $subdomain = "api")
{
$this->client = new MoySkladHttpClient($login, $password, $posToken, $subdomain);
$this->hashCode = $hashCode;
Expand All @@ -40,16 +40,20 @@ private static function makeHash($login, $password){

/**
* Use it instead of constructor
* @param $login
* @param $loginOrToken
* @param $password
* @param string $subdomain
* @param $posToken
* @return MoySklad
*/
public static function getInstance($login, $password, $subdomain = "online", $posToken = null){
$hash = static::makeHash($login, $password);
public static function getInstance($loginOrToken, $password = null, $subdomain = "api", $posToken = null){
if (is_null($password)) {
$hash = $loginOrToken;
} else {
$hash = static::makeHash($loginOrToken, $password);
}
if ( empty(static::$instances[$hash]) ){
static::$instances[$hash] = new static($login, $password, $posToken, $hash, $subdomain);
static::$instances[$hash] = new static($loginOrToken, $password, $posToken, $hash, $subdomain);
EntityRegistry::instance()->bootEntities();
}
return static::$instances[$hash];
Expand Down
4 changes: 3 additions & 1 deletion src/Registers/EntityRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
use MoySklad\Entities\Products\Variant;
use MoySklad\Entities\Project;
use MoySklad\Entities\RetailStore;
use MoySklad\Entities\Saleschannel;
use MoySklad\Entities\Store;
use MoySklad\Entities\Uom;
use MoySklad\Entities\Bonustransaction;
Expand Down Expand Up @@ -195,7 +196,8 @@ class EntityRegistry extends AbstractSingleton{
ProcessingProduct::class,
ProcessingMaterial::class,
Bonustransaction::class,
Bonusprogram::class
Bonusprogram::class,
Saleschannel::class
];
public $entityNames = [];

Expand Down

0 comments on commit f9e26cc

Please sign in to comment.