Skip to content

Commit

Permalink
Initial commit of package
Browse files Browse the repository at this point in the history
  • Loading branch information
inserve-paul committed Mar 21, 2024
1 parent 642c2b3 commit dd890cf
Show file tree
Hide file tree
Showing 17 changed files with 2,065 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/build-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Unit tests and checkstyle
on: [push]
jobs:
phpunit:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: ['ubuntu-latest']
php-versions: ['8.2', '8.3']
phpunit-versions: ['latest']
include:
- operating-system: 'ubuntu-latest'
php-versions: '8.2'
phpunit-versions: 10
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring
coverage: xdebug
tools: composer:v2, php-cs-fixer, phpunit:${{ matrix.phpunit-versions }}

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --prefer-dist

- name: Run PHPCS
run: ./vendor/bin/phpcs src tests -v --standard=PSR2

- name: Run Psalm
run: ./vendor/bin/psalm --show-info=true

- name: Run PHPStan
run: ./vendor/bin/phpstan analyse --level=5 src tests

- name: Run PHPUnit
run: ./vendor/bin/phpunit --coverage-text --colors
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# IDE
/.idea/

# PHP Unit
.phpunit.cache
.phpunit.result.cache

# Composer
composer.lock
composer.phar
/vendor/
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Requirements
[![PHP Version Require](http://poser.pugx.org/inserve/also-cloud-marketplace-api-php/require/php)](https://packagist.org/packages/inserve/also-cloud-marketplace-api-php)

## Installation
`composer require inserve/also-cloud-marketplace-api-php`

37 changes: 37 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "inserve/also-cloud-marketplace-api-php",
"description": "A PHP wrapper ALSO Cloud Marketplace",
"license": "MIT",
"type": "library",
"require": {
"php": "^8.2",
"guzzlehttp/guzzle": "^7.7",
"symfony/serializer": "^6.3|^7",
"symfony/property-access": "^6.3|^7",
"psr/log": "^3.0",
"phpdocumentor/reflection-docblock": "^5.3"
},
"require-dev": {
"phpunit/phpunit": "^10.2",
"squizlabs/php_codesniffer": "^3.7",
"phpstan/phpstan": "^1.10",
"vimeo/psalm": "^5.22"
},
"autoload": {
"psr-4": {
"Inserve\\ALSOCloudMarketplaceAPI\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Inserve\\ALSOCloudMarketplaceAPI\\Tests\\": "tests/"
}
},
"authors": [
{
"name": "Inserve",
"email": "[email protected]"
}
],
"minimum-stability": "stable"
}
25 changes: 25 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd"
backupGlobals="false"
beStrictAboutTestsThatDoNotTestAnything="false"
colors="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
>
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<source restrictDeprecations="true" restrictNotices="true" restrictWarnings="true">
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
18 changes: 18 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<psalm
errorLevel="3"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedBaselineEntry="true"
findUnusedCode="false"
>
<projectFiles>
<directory name="src" />
<directory name="tests" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
18 changes: 18 additions & 0 deletions src/API/AbstractAPIClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Inserve\ALSOCloudMarketplaceAPI\API;

use Inserve\ALSOCloudMarketplaceAPI\Client\APIClient;

/**
*
*/
abstract class AbstractAPIClient
{
/**
* @param APIClient $apiClient
*/
public function __construct(#[\SensitiveParameter] protected APIClient $apiClient)
{
}
}
52 changes: 52 additions & 0 deletions src/API/CompanyAPI.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Inserve\ALSOCloudMarketplaceAPI\API;

use Inserve\ALSOCloudMarketplaceAPI\Exception\MarketplaceAPIException;
use Inserve\ALSOCloudMarketplaceAPI\Model\Company;
use Symfony\Component\Serializer\Exception\ExceptionInterface;

/**
*
*/
class CompanyAPI extends AbstractAPIClient
{
/**
* @param int $accountId
*
* @return Company|null
*
* @throws MarketplaceAPIException|ExceptionInterface
*/
public function get(int $accountId): ?Company
{
$response = $this->apiClient->call(
'/GetCompany',
json_encode(compact('accountId'))
);

return $this->apiClient->denormalize($response, Company::class);
}

/**
* @param int $parentAccountId
*
* @return Company[]
*
* @throws MarketplaceAPIException|ExceptionInterface
*/
public function list(int $parentAccountId): array
{
$response = $this->apiClient->call(
'/GetCompanies',
json_encode(compact('parentAccountId'))
);

$companies = [];
foreach ($response as $item) {
$companies[] = $this->apiClient->denormalize($item, Company::class);
}

return $companies;
}
}
53 changes: 53 additions & 0 deletions src/API/SubscriptionsAPI.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Inserve\ALSOCloudMarketplaceAPI\API;

use Inserve\ALSOCloudMarketplaceAPI\Exception\MarketplaceAPIException;
use Inserve\ALSOCloudMarketplaceAPI\Model\Subscription;
use Symfony\Component\Serializer\Exception\ExceptionInterface;

/**
*
*/
class SubscriptionsAPI extends AbstractAPIClient
{
/**
* @param int $accountId
*
* @return Subscription|null
*
* @throws MarketplaceAPIException|ExceptionInterface
*/
public function get(int $accountId): ?Subscription
{
$response = $this->apiClient->call(
'/GetSubscription',
json_encode(compact('accountId'))
);

return $this->apiClient->denormalize($response, Subscription::class);
}

/**
* @param int $parentAccountId
* @param bool $excludeUserLevel
*
* @return Subscription[]
*
* @throws MarketplaceAPIException|ExceptionInterface
*/
public function list(int $parentAccountId, bool $excludeUserLevel = false): array
{
$response = $this->apiClient->call(
'/GetSubscriptions',
json_encode(compact('parentAccountId', 'excludeUserLevel'))
);

$subscriptions = [];
foreach ($response as $item) {
$subscriptions[] = $this->apiClient->denormalize($item, Subscription::class);
}

return $subscriptions;
}
}
Loading

0 comments on commit dd890cf

Please sign in to comment.