Commit 3f39aab0 authored by Utz, Wolf-Peter's avatar Utz, Wolf-Peter
Browse files

Initial commit.

parent 0b650d65
composer.lock
vendor/
.idea/
.php_cs.cache
real_test.php
qs.sh
.env
\ No newline at end of file
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- vendor/
stages:
- build
- code_quallity
- test
composer:
image: php:5.6-alpine
stage: build
before_script:
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
script:
- composer validate
- composer -q -n install
artifacts:
expire_in: 1 hour
paths:
- vendor/
only:
- merge_requests
codesniffer:
image: php:5.6-alpine
stage: code_quallity
script:
- vendor/bin/phpcs --error-severity=1 --warning-severity=8 --extensions=php src tests
only:
- merge_requests
allow_failure: true
phpmd:
image: php:5.6-alpine
stage: code_quallity
script:
- vendor/bin/phpmd src text phpmd.xml
only:
- merge_requests
allow_failure: true
unittests:
image: php:5.6-alpine
stage: test
script:
vendor/bin/phpunit -c phpunit.xml
only:
- merge_requests
\ No newline at end of file
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [1.0.0]
### Added
- Initial release
MIT License
Copyright (c) 2019 Wolf Utz <utz@riconet.de>, Hees riconet GmbH
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
\ No newline at end of file
# Talenstorm API client
## Overview
A simple client for the api of talentstorm.
This client works with PHP >= 5.6.
## How to use
```php
require_once __DIR__.'/vendor/autoload.php';
use \Riconet\TalenstormApiClient\Client;
use \Riconet\TalenstormApiClient\Request\ApiRequest;
// Create the client
$client = new Client(new ApiRequest(
"my-api-key"
));
// Fetch all jobs.
$jobs = $client->fetchJobs();
```
## Supported endpoints
#!/usr/bin/env bash
#
# TYPO3 core test runner based on docker and docker-compose.
#
# Function to write a .env file in Build/testing-docker/local
# This is read by docker-compose and vars defined here are
# used in Build/testing-docker/local/docker-compose.yml
setUpDockerComposeDotEnv() {
# Delete possibly existing local .env file if exists
[ -e .env ] && rm .env
echo "ROOT_DIR"=${ROOT_DIR} >> .env
echo "EXTRA_TEST_OPTIONS=${EXTRA_TEST_OPTIONS}" >> .env
echo "PHP_VERSION=${PHP_VERSION}" >> .env
}
# Test if docker-compose exists, else exit out with error
if ! type "docker-compose" > /dev/null; then
echo "This script relies on docker and docker-compose. Please install" >&2
exit 1
fi
# Load help text into $HELP
read -r -d '' HELP <<EOF
Test runner.
Usage: $0 [options] [file]
No arguments: Run all acceptance tests (not .side files)
Options:
-s <...>
Specifies which test suite to run
- build: Test if the project can be build with errors.
- unit: Runs the unit tests
- quality: Runs the code quality tests.
-e "<test options>"
Only with -s acceptance
Additional options to send to codeception tests.
-p <5.6|7.0|7.1|7.2|7.3>
Specifies the PHP version to be used
-h
Show this help.
Examples:
build/scripts/console.sh -s quality -p 5.6
build/scripts/console.sh -s unit -p 7.0 -e "--verbose"
EOF
# Gets the realpath.
realpath() {
if ! pushd $1 &> /dev/null; then
pushd ${1##*/} &> /dev/null
echo $( pwd -P )/${1%/*}
else
pwd -P
fi
popd > /dev/null
}
# Go to the directory this script is located, so everything else is relative
# to this dir, no matter from where this script is called.
THIS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
cd "$THIS_SCRIPT_DIR" || exit 1
# Go to directory that contains the local docker-compose.yml file
cd ../testing-docker || exit 1
# Option defaults
ROOT_DIR=$(realpath $PWD"/../..")
OPTION="unit"
PHP_VERSION="5.6"
EXTRA_TEST_OPTIONS=""
# Option parsing
# Reset in case getopts has been used previously in the shell
OPTIND=1
# Array for invalid options
INVALID_OPTIONS=();
# Simple option parsing based on getopts (! not getopt)
while getopts ":s:d:p:e:xy:huv" OPT; do
case ${OPT} in
s)
OPTION=${OPTARG}
;;
e)
EXTRA_TEST_OPTIONS=${OPTARG}
;;
p)
PHP_VERSION=${OPTARG}
;;
h)
echo "${HELP}"
exit 0
;;
\?)
INVALID_OPTIONS+=(${OPTARG})
;;
:)
INVALID_OPTIONS+=(${OPTARG})
;;
esac
done
# Suite execution
case ${OPTION} in
build)
setUpDockerComposeDotEnv
docker-compose run build
SUITE_EXIT_CODE=$?
docker-compose down
;;
unit)
setUpDockerComposeDotEnv
docker-compose run unit
SUITE_EXIT_CODE=$?
docker-compose down
;;
quality)
setUpDockerComposeDotEnv
docker-compose run quality
SUITE_EXIT_CODE=$?
docker-compose down
;;
*)
echo "Invalid -s option argument ${OPTARG}" >&2
echo >&2
echo "${HELP}" >&2
exit 1
esac
version: '2.3'
services:
#======================================================
# Build
#======================================================
build:
image: php:${PHP_VERSION}-alpine
volumes:
- ${ROOT_DIR}:${ROOT_DIR}
working_dir: ${ROOT_DIR}
command: >
/bin/sh -c "
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
composer validate
composer install
"
#======================================================
# Quality
#======================================================
quality:
image: php:${PHP_VERSION}-alpine
volumes:
- ${ROOT_DIR}:${ROOT_DIR}
working_dir: ${ROOT_DIR}
command: >
/bin/sh -c "
echo \"Running phpcs...\";
vendor/bin/phpcs --error-severity=1 --warning-severity=8 --extensions=php src tests;
echo \"Running phpmd...\";
vendor/bin/phpmd src text phpmd.xml;
"
#======================================================
# Unit
#======================================================
unit:
image: php:${PHP_VERSION}-alpine
volumes:
- ${ROOT_DIR}:${ROOT_DIR}
working_dir: ${ROOT_DIR}
command: >
/bin/sh -c "
vendor/bin/phpunit -c phpunit.xml
"
{
"name": "riconet/talentstorm-api-client",
"description": "A simple client for the api of talentstorm.",
"homepage": "https://git.riconnect.de/riconet-public/talenstorm-api-client",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "wolf.utz",
"email": "utz@riconet.de"
}
],
"autoload": {
"psr-4": {
"Riconet\\TalenstormApiClient\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Riconet\\TalenstormApiClient\\Tests\\": "tests/"
}
},
"require": {
"php": ">= 5.6",
"guzzlehttp/guzzle": "^6.3",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"squizlabs/php_codesniffer": "^3.4",
"phpmd/phpmd": "^2.6",
"kint-php/kint": "^3.2"
},
"config": {
"platform": {
"php": "5.6"
}
}
}
<?xml version="1.0"?>
<ruleset name="PSR2">
<description>The PSR1 and PSR2 coding standard.</description>
<rule ref="PSR1"/>
<rule ref="PSR2"/>
<file>src/</file>
<file>tests/</file>
<exclude-pattern>vendor</exclude-pattern>
</ruleset>
\ No newline at end of file
<?xml version="1.0"?>
<ruleset name="My first PHPMD rule set"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>talenstorm-api-client ruleset</description>
<rule ref="rulesets/cleancode.xml">
<exclude name="StaticAccess"/>
</rule>
<rule ref="rulesets/unusedcode.xml"/>
<rule ref="rulesets/codesize.xml"/>
<rule ref="rulesets/controversial.xml"/>
<rule ref="rulesets/design.xml"/>
<rule ref="rulesets/naming.xml"/>
</ruleset>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests/Unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</phpunit>
\ No newline at end of file
<?php
/**
* This file is part of the "talenstorm-api-client" library.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* @author Wolf Utz <utz@riconet.de>, Hees riconet GmbH
* @copyright 2019 Hees riconet GmbH
* @license https://opensource.org/licenses/MIT MIT
*/
namespace Riconet\TalenstormApiClient;
/**
* Class ApiInterface.
*/
interface ApiInterface
{
/**
* @return mixed
*/
public function fetchJobs();
/**
* @param string $identification
*
* @return mixed
*/
public function fetchJob($identification);
/**
* @return mixed
*/
public function fetchJobTypes();
/**
* @param string $idOrSlug
*
* @return mixed
*/
public function fetchJobPortal($idOrSlug);
/**
* @return mixed
*/
public function fetchJobPortals();
/**
* @param string $identification
*
* @return mixed
*/
public function fetchApplicationForm($identification);
}
<?php
/**
* This file is part of the "talenstorm-api-client" library.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* @author Wolf Utz <utz@riconet.de>, Hees riconet GmbH
* @copyright 2019 Hees riconet GmbH
* @license https://opensource.org/licenses/MIT MIT
*/
namespace Riconet\TalenstormApiClient;
use GuzzleHttp\Exception\GuzzleException;
use Riconet\TalenstormApiClient\Request\ApiRequest;
use Riconet\TalenstormApiClient\Utility\JsonUtility;
/**
* Class Client.
*/
class Client implements ApiInterface
{
const BASE_URL = 'https://api.talentstorm.de/';
/**
* The low level request to the api.
*
* @var ApiRequest
*/
private $request;
/**
* Client constructor.
*
* @param ApiRequest $request
*/
public function __construct(ApiRequest $request)
{
$this->request = $request;
$this->request->setBaseUrl(self::BASE_URL);
}
/**
* Fetches all job data.
*
* @return array the parsed json response of the api
*
* @throws GuzzleException
*/
public function fetchJobs()
{
return $this->fetch('api/v1/joboffers/basic');
}
/**
* Fetches a single job.
*
* @param string $identification the id of a job
*
* @return array the parsed json response of the api
*
* @throws GuzzleException
*/
public function fetchJob($identification)
{
return $this->fetch('api/v1/joboffers/basic', $identification);
}
/**
* Fetches all job types.
*
* @return array the parsed json response of the api
*
* @throws GuzzleException
*/
public function fetchJobTypes()
{
return $this->fetch('api/v1/jobtypes');
}
/**
* Fetches all job portals.
*
* @return array the parsed json response of the api
*
* @throws GuzzleException
*/
public function fetchJobPortals()
{
return $this->fetch('api/v1/jobportals');
}
/**
* Fetches a single job portal.
*
* @param string $idOrSlug the id or slug of a job or portal
*
* @return array the parsed json response of the api
*
* @throws GuzzleException
*/
public function fetchJobPortal($idOrSlug)
{
return $this->fetch('api/v1/jobportals', $idOrSlug);
}
/**
* Fetches a link to the application form, by a given id of a job.
*
* @param string $identification the id or of a job
*
* @return array the parsed json response of the api
*
* @throws GuzzleException
*/
public function fetchApplicationForm($identification)
{
return $this->fetch('api/v1/applicationform-url', $identification);
}
/**
* Generic fetch method, to request data from the api, by a given endpoint.
*
* @param string $endPoint the endpoint to request
* @param string $idOrSlug the id or slug of a job or portal
*
* @return array the parsed json response of the api
*
* @throws GuzzleException
*/
private function fetch($endPoint, $idOrSlug = '')
{
return JsonUtility::parseJsonStringAssoc($this->request->get(rtrim($endPoint.'/'.$idOrSlug, '/')));
}
}
<?php
/**
* This file is part of the "talenstorm-api-client" library.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* @author Wolf Utz <utz@riconet.de>, Hees riconet GmbH
* @copyright 2019 Hees riconet GmbH
* @license https://opensource.org/licenses/MIT MIT
*/
namespace Riconet\TalenstormApiClient\Request;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
/**
* Class ApiRequest.
*/
class ApiRequest
{
/**
* The api key.
*
* @var string
*/
private $apiKey = '';
/**
* The base url of the api.
*
* @var string
*/
private $baseUrl = '';
/**
* ApiRequest constructor.
*
* @param string $apiKey the api key
* @param string $baseUrl the base url
*/
public function __construct($apiKey, $baseUrl = "")
{
$this->apiKey = $apiKey;
$this->baseUrl = $baseUrl;
}
/**
* @param string $endPoint a valid endpoint, like `api/v1/joboffers/basic`
*
* @return string
*
* @throws GuzzleException