Skip to content

Commit 5fa60e8

Browse files
author
Valerii Maslenykov
committed
Initial commit – v0.0.1-beta.1
0 parents  commit 5fa60e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+8106
-0
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
indent_size = 4
9+
indent_style = space
10+
end_of_line = lf
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
13+
14+
[*.md]
15+
trim_trailing_whitespace = false

.github/workflows/main.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Tests
2+
3+
on: [ push ]
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
name: "Static analysis"
9+
steps:
10+
- name: Checkout code
11+
uses: actions/checkout@v2
12+
13+
- uses: actions/cache@v2
14+
id: cache-db
15+
with:
16+
path: ~/.symfony/cache
17+
key: db
18+
- uses: symfonycorp/security-checker-action@v4
19+
20+
- name: Setup PHP
21+
uses: shivammathur/setup-php@v2
22+
with:
23+
php-version: 8.2
24+
25+
- name: Install dependencies
26+
run: composer install --no-interaction
27+
28+
- name: Lint code
29+
run: ./vendor/bin/phpcs --standard=PSR12 ./src ./tests
30+
31+
test:
32+
runs-on: ${{ matrix.os }}
33+
strategy:
34+
fail-fast: true
35+
matrix:
36+
os: [ ubuntu-latest, windows-latest ]
37+
php:
38+
- version: 7.2
39+
- version: 7.3
40+
- version: 7.4
41+
- version: 8.0
42+
- version: 8.1
43+
- version: 8.2
44+
45+
stability: [ prefer-stable ]
46+
47+
name: P${{ matrix.php.version }} - ${{ matrix.stability }} - ${{ matrix.os }}
48+
49+
steps:
50+
- name: Checkout code
51+
uses: actions/checkout@v2
52+
53+
- name: Setup PHP
54+
uses: shivammathur/setup-php@v2
55+
with:
56+
php-version: ${{ matrix.php.version }}
57+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
58+
coverage: pcov
59+
60+
- name: Setup problem matchers
61+
run: |
62+
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
63+
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
64+
- name: Install dependencies (and remove local phpunit)
65+
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction
66+
67+
- name: Remove PHPUnit from library composer.json
68+
run: composer remove --dev phpunit/phpunit
69+
70+
- name: Install PHPUnit globally
71+
run: composer global require phpunit/phpunit '^8.5.33'
72+
73+
- name: Execute tests
74+
run: phpunit --version && phpunit

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
build
2+
docs
3+
vendor
4+
coverage
5+
.idea
6+
7+
# Caches
8+
.phpunit.result.cache
9+
.php-cs-fixer.cache

.php-cs-fixer.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in([__DIR__ . '/src', __DIR__ . '/tests']);
5+
6+
$config = new PhpCsFixer\Config();
7+
return $config->setRules([
8+
'@PSR12' => true,
9+
'declare_strict_types' => true,
10+
'strict_param' => true,
11+
])
12+
->setRiskyAllowed((true))
13+
->setFinder($finder);

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) Joystick letsgo@getjoystick.com
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# PHP client for [Joystick](https://www.getjoystick.com/)
2+
3+
[![GitHub Actions](https://github.com/getjoystick/joystick-php/actions/workflows/main.yml/badge.svg)](<(https://github.com/getjoystick/joystick-php/actions?query=branch%3Amaster)>)
4+
[![Latest Stable Version](https://poser.pugx.org/getjoystick/joystick-php/v/stable.svg)](https://packagist.org/packages/getjoystick/joystick-php)
5+
[![Total Downloads](https://poser.pugx.org/getjoystick/joystick-php/downloads.svg)](https://packagist.org/packages/getjoystick/joystick-php)
6+
[![License](https://poser.pugx.org/getjoystick/joystick-php/license.svg)](https://packagist.org/packages/getjoystick/joystick-php)
7+
8+
This is the library that simplifies the way how you can communicate with [Joystick API](https://docs.getjoystick.com/).
9+
10+
## Requirements
11+
12+
PHP 7.2 and later
13+
14+
## Installation
15+
16+
You can install the package via [Composer](http://getcomposer.org/):
17+
18+
```bash
19+
composer require getjoystick/joystick-php
20+
```
21+
22+
We will try to find the PSR-18 compatible HTTP client within your dependencies using
23+
[`php-http/discovery`](https://docs.php-http.org/en/latest/discovery.html), if you don't have one
24+
installed, just run this command to install
25+
[Guzzle HTTP client](https://docs.guzzlephp.org/en/stable/):
26+
27+
```bash
28+
composer require guzzlehttp/guzzle
29+
```
30+
31+
## Usage
32+
33+
To use the client, use Composer's [autoload](https://getcomposer.org/doc/01-basic-usage.md#autoloading):
34+
35+
```php
36+
require_once 'vendor/autoload.php';
37+
```
38+
39+
Simple usage looks like this:
40+
41+
```php
42+
$config = \Joystick\ClientConfig::create()->setApiKey(getenv('JOYSTICK_API_KEY'));
43+
44+
$client = \Joystick\Client::create($config);
45+
46+
$getContentsResponse = $client->getContents(['content-id1', 'content-id2']);
47+
48+
$getContentsResponse->myProperty1
49+
$getContentsResponse->myProperty2
50+
```
51+
52+
### Requesting Content by single Content Id
53+
54+
```php
55+
$getContentResponse = $client->getContent('content-id1');
56+
$getContentResponse->myProperty1
57+
```
58+
59+
### Specifying additional parameters:
60+
61+
When creating the `ClientConfig` object, you can specify additional parameters which will be used
62+
by all API calls from the client, for more details see
63+
[API documentation](https://docs.getjoystick.com/api-reference/):
64+
65+
```php
66+
$config = \Joystick\ClientConfig::create()
67+
->setApiKey(getenv('JOYSTICK_API_KEY'))
68+
->setCacheExpirationSeconds(600) // 10 mins
69+
->setSerialized(true)
70+
->setParams([
71+
'param1' => 'value1',
72+
'param2' => 'value2',
73+
])
74+
->setSemVer('0.0.1')
75+
->setUserId('user-id-1');
76+
```
77+
78+
### Options
79+
80+
#### `fullResponse`
81+
82+
In most of the cases you will be not interested in the full response from the API, but if you're you can specify
83+
`fullResponse` option to the client methods. The client will return you raw API response:
84+
```php
85+
$getContentResponse = $client->getContent('content-id1', ['fullResponse' => true]);
86+
// OR
87+
$getContentsResponse = $client->getContents(['content-id1', 'content-id2'], ['fullResponse' => true]);
88+
```
89+
90+
#### `serialized`
91+
92+
When `true`, we will pass query parameter `responseType=serialized`
93+
to [Joystick API](https://docs.getjoystick.com/api-reference-combine/).
94+
95+
```php
96+
$getContentResponse = $client->getContent('content-id1', ['serialized' => true]);
97+
// OR
98+
$getContentsResponse = $client->getContents(['content-id1', 'content-id2'], ['serialized' => true]);
99+
```
100+
101+
#### `refresh`
102+
103+
If you want to ignore existing cache and request the new config – pass this option as `true`.
104+
105+
```php
106+
$getContentResponse = $client->getContent('content-id1', ['refresh' => true]);
107+
// OR
108+
$getContentsResponse = $client->getContents(['content-id1', 'content-id2'], ['refresh' => true]);
109+
```
110+
111+
This option can be set for every API call from the client by setting `setSerialized(true)`:
112+
113+
```php
114+
$config = \Joystick\ClientConfig::create()
115+
->setApiKey(getenv('JOYSTICK_API_KEY'))
116+
->setSerialized(true)
117+
```
118+
119+
### Caching
120+
121+
By default, the client uses [array caching](https://packagist.org/packages/cache/array-adapter),
122+
which means that if you build the HTTP application where each process exits after the request
123+
has been processed – the cache will be erased after the process is finished.
124+
125+
You can specify your [cache implementation which conforms PSR-16](https://packagist.org/providers/psr/simple-cache-implementation).
126+
127+
128+
See [`examples/file-cache`](./examples/file-cache) for more details.
129+
130+
#### Clear the cache
131+
132+
If you want to clear the cache – run `$client->clearCache()`.
133+
134+
> Note that we will call `clear()` on the PSR-16 interface.
135+
> Make sure that you use different cache instances in different places of your app
136+
137+
138+
### HTTP Client
139+
140+
If you want to provide custom HTTP client, which may be useful for use-cases like specifying custom proxy,
141+
collecting detailed metrics about HTTP requests,
142+
143+
You can specify your [HTTP client implementation which conforms PSR-18](https://packagist.org/providers/psr/simple-cache-implementation).
144+
145+
See [`examples/custom-http-client`](./examples/custom-http-client) for more details.
146+
147+
## Testing
148+
149+
To run unit tests, just run:
150+
```bash
151+
phpunit
152+
```
153+
154+
### Security
155+
156+
If you discover any security related issues, please email [letsgo@getjoystick.com](letsgo@getjoystick.com)
157+
instead of using the issue tracker.
158+
159+
## Credits
160+
161+
- [Joystick](https://github.com/getjoystick)
162+
- [All Contributors](../../contributors)
163+
164+
## License
165+
166+
The MIT. Please see [License File](LICENSE.md) for more information.

composer.json

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"name": "getjoystick/joystick-php",
3+
"description": "Joystick is a modern remote configuration and dynamic content service designed specifically for operating apps and games. Upgrade to more agility and evolve your product faster. Change or hot-update your content and configurations instantly at scale without code. Segment, ab test, feature flag, schedule events and more. Joystick is a breeze to use yet powerful.",
4+
"keywords": [
5+
"Remote configuration",
6+
"feature flagging",
7+
"dynamic content",
8+
"remote configs",
9+
"live-ops",
10+
"game ops",
11+
"ab testing",
12+
"segmentation",
13+
"dynamic json",
14+
"update json",
15+
"remote json"
16+
],
17+
"homepage": "https://github.com/getjoystick/joystick-php",
18+
"license": "MIT",
19+
"type": "library",
20+
"authors": [
21+
{
22+
"name": "Joystick and contributors",
23+
"homepage": "https://getjoystick.com"
24+
}
25+
],
26+
"require": {
27+
"php": ">=7.2",
28+
"ext-curl": "*",
29+
"ext-json": "*",
30+
"beberlei/assert": "^3.3",
31+
"cache/array-adapter": "^1.1",
32+
"php-http/discovery": "^1.15",
33+
"psr/http-client": "^1.0",
34+
"psr/http-message": "^1.0",
35+
"psr/simple-cache": "^1.0|^2.0|^3.0"
36+
},
37+
"require-dev": {
38+
"guzzlehttp/guzzle": "^7.5",
39+
"phpspec/prophecy": "^1.17",
40+
"phpunit/phpunit": "^8.5",
41+
"squizlabs/php_codesniffer": "^3.7"
42+
},
43+
"minimum-stability": "stable",
44+
"autoload": {
45+
"psr-4": {
46+
"Joystick\\": "src"
47+
}
48+
},
49+
"autoload-dev": {
50+
"psr-4": {
51+
"Joystick\\Tests\\": "tests"
52+
}
53+
},
54+
"scripts": {
55+
"test": "vendor/bin/phpunit",
56+
"test-coverage": "vendor/bin/phpunit --coverage-html coverage",
57+
"lint": "./vendor/bin/phpcs --standard=./phpcs.xml ./src ./tests",
58+
"lint-fix": "./tools/php-cs-fixer/vendor/bin/php-cs-fixer fix"
59+
},
60+
"config": {
61+
"sort-packages": true,
62+
"allow-plugins": {
63+
"php-http/discovery": true,
64+
"dealerdirect/phpcodesniffer-composer-installer": true
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)