Skip to content

Commit acd9776

Browse files
authored
Merge pull request #23 from atk4/release/0.3
Releasing 0.3 into master
2 parents ade49be + 9cb7707 commit acd9776

15 files changed

Lines changed: 628 additions & 131 deletions

.codeclimate.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
engines:
2+
duplication:
3+
enabled: true
4+
config:
5+
languages:
6+
- php
7+
fixme:
8+
enabled: true
9+
phpmd:
10+
enabled: true
11+
exclude_fingerprints:
12+
- 42b4b225a9c6cf44b27182f397e2b7ad # REMOVE this one when replacing with something useful
13+
checks:
14+
CyclomaticComplexity:
15+
enabled: false
16+
Design/TooManyPublicMethods:
17+
enabled: false
18+
Design/TooManyMethods:
19+
enabled: false
20+
Design/NpathComplexity:
21+
enabled: false
22+
Design/WeightedMethodCount:
23+
enabled: false
24+
Design/LongClass:
25+
enabled: false
26+
Controversial/CamelCaseMethodName:
27+
enabled: false
28+
Controversial/CamelCaseParameterName:
29+
enabled: false
30+
Controversial/CamelCasePropertyName:
31+
enabled: false
32+
Controversial/CamelCaseVariableName:
33+
enabled: false
34+
Controversial/CamelCaseClassName:
35+
enabled: false
36+
Controversial/Superglobals: # we use SESSION global
37+
enabled: false
38+
Naming/ShortVariable:
39+
enabled: false
40+
CleanCode/ElseExpression:
41+
enabled: false
42+
Design/LongMethod: # sometimes we have longer methods than 100 rows
43+
enabled: false
44+
radon:
45+
enabled: true
46+
ratings:
47+
paths:
48+
- src/**
49+
exclude_paths:
50+
- docs/**
51+
- tests/**
52+
- vendor/**

.github/release-drafter.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# See https://github.com/release-drafter/release-drafter#configuration
2+
template: |
3+
## What’s Changed
4+
5+
$CHANGES

.github/workflows/bundler.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Bundler
2+
3+
on: create
4+
5+
jobs:
6+
autocommit:
7+
name: Update to stable dependencies
8+
if: startsWith(github.ref, 'refs/heads/release/')
9+
runs-on: ubuntu-latest
10+
container:
11+
image: atk4/image:latest # https://github.com/atk4/image
12+
steps:
13+
- uses: actions/checkout@master
14+
- run: echo ${{ github.ref }}
15+
- name: Update to stable dependencies
16+
run: |
17+
# replaces X keys with X-release keys
18+
jq '. as $in | reduce (keys_unsorted[] | select(endswith("-release")|not)) as $k ({}; . + {($k) : (($k + "-release") as $kr | $in | if has($kr) then .[$kr] else .[$k] end) } )' < composer.json > tmp && mv tmp composer.json
19+
v=$(echo ${{ github.ref }} | cut -d / -f 4)
20+
echo "::set-env name=version::$v"
21+
22+
- uses: teaminkling/autocommit@master
23+
with:
24+
commit-message: Setting release dependencies
25+
- uses: ad-m/github-push-action@master
26+
with:
27+
branch: ${{ github.ref }}
28+
github_token: ${{ secrets.GITHUB_TOKEN }}
29+
30+
- name: pull-request
31+
uses: romaninsh/pull-request@master
32+
with:
33+
source_branch: "release/${{ env.version }}"
34+
destination_branch: "master" # If blank, default: master
35+
pr_title: "Releasing ${{ env.version }} into master"
36+
pr_body: |
37+
- [ ] Review changes (must include stable dependencies)
38+
- [ ] Merge this PR into master (will delete ${{ github.ref }})
39+
- [ ] Go to Releases and create TAG from master
40+
Do not merge master into develop
41+
pr_reviewer: "romaninsh"
42+
pr_assignee: "romaninsh"
43+
github_token: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Release Drafter
2+
3+
on:
4+
push:
5+
# branches to consider in the event; optional, defaults to all
6+
branches:
7+
- develop
8+
9+
jobs:
10+
update_release_draft:
11+
runs-on: ubuntu-latest
12+
steps:
13+
# Drafts your next Release notes as Pull Requests are merged into "master"
14+
- uses: toolmantim/release-drafter@master
15+
env:
16+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/unit-tests.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Unit Testing
2+
3+
on:
4+
pull_request:
5+
branches: '*'
6+
push:
7+
branches:
8+
- master
9+
- develop
10+
11+
jobs:
12+
unit-test:
13+
name: Unit Testing
14+
runs-on: ubuntu-latest
15+
container:
16+
image: atk4/image:${{ matrix.php }} # https://github.com/atk4/image
17+
strategy:
18+
matrix:
19+
php: ['7.2', '7.3', 'latest']
20+
steps:
21+
- uses: actions/checkout@v1
22+
# need this to trick composer
23+
- run: php --version
24+
- run: "git branch develop; git checkout develop"
25+
- name: Get Composer Cache Directory
26+
id: composer-cache
27+
run: |
28+
echo "::set-output name=dir::$(composer config cache-files-dir)"
29+
30+
- uses: actions/cache@v1
31+
with:
32+
path: ${{ steps.composer-cache.outputs.dir }}
33+
key: ${{ runner.os }}-composer-${{ hashFiles('composer.json') }}
34+
restore-keys: |
35+
${{ runner.os }}-composer-
36+
37+
- run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
38+
39+
- name: Run Tests
40+
run: |
41+
mkdir -p build/logs
42+
43+
- name: SQLite Testing
44+
run: vendor/bin/phpunit --configuration phpunit.xml --coverage-text
45+
46+
- uses: codecov/codecov-action@v1
47+
if: matrix.php == 'latest'
48+
with:
49+
token: ${{ secrets.CODECOV_TOKEN }}
50+
file: build/logs/clover.xml

.travis.yml

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
language: php
22

33
php:
4-
- '5.6'
5-
- '7.0'
6-
- '7.1'
4+
- '7.2'
5+
- '7.3'
76

87
cache:
98
directories:
@@ -13,34 +12,31 @@ cache:
1312
# - mysql
1413

1514
before_script:
16-
- composer install
15+
- composer install
1716
# - mysql -e 'create database dsql_test;'
1817

18+
1919
after_script:
20-
- echo $TRAVIS_PHP_VERSION
21-
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.0" ]]; then echo "Sending codecov report"; bash <(curl -s https://codecov.io/bash); fi
20+
- echo $TRAVIS_BRANCH
21+
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.2" ]]; then echo "Sending coverage report"; vendor/bin/test-reporter --coverage-report build/logs/clover.xml; fi
22+
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.2" ]]; then echo "Sending codecov report"; TRAVIS_CMD="" bash <(curl -s https://codecov.io/bash) -f build/logs/clover.xml; fi
2223

2324
script:
24-
- if [[ ${TRAVIS_PHP_VERSION:0:3} != "7.0" ]]; then NC="--no-coverage"; fi
25-
- ./vendor/phpunit/phpunit/phpunit $NC
25+
- if [[ ${TRAVIS_PHP_VERSION:0:3} != "7.2" ]]; then NC="--no-coverage"; fi
26+
- ./vendor/phpunit/phpunit/phpunit $NC
2627

2728
notifications:
29+
webhooks:
2830
urls:
2931
- https://webhooks.gitter.im/e/b33a2db0c636f34bafa9
30-
on_success: change # options: [always|never|change] default: always
31-
on_failure: always # options: [always|never|change] default: always
32-
on_start: never # options: [always|never|change] default: always
33-
34-
slack:
35-
rooms:
36-
- agiletoolkit:bjrKuPBf1h4cYiNxPBQ1kF6c#dsql
37-
on_success: change
38-
39-
urls:
4032
- https://webhooks.gitter.im/e/c4000ab24556b09cb3e7
41-
4233
on_success: change # options: [always|never|change] default: always
4334
on_failure: always # options: [always|never|change] default: always
4435
on_start: never # options: [always|never|change] default: always
4536

46-
email: false
37+
slack:
38+
rooms:
39+
- agiletoolkit:bjrKuPBf1h4cYiNxPBQ1kF6c#dsql
40+
on_success: change
41+
42+
email: false

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Pre-releases
2+
3+
### 0.2 More flexible REST lookups
4+
5+
- add support for looking up by fields other than ID: "api/country/code:GB"
6+
7+
### 0.1 Initial release
8+
9+
- added post(), get(), etc
10+
- added rest() and integration with Model Data
11+
- first working prototype

README.md

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,72 @@
11
# Agile API Framework
22

33
[![Build Status](https://travis-ci.org/atk4/api.png?branch=develop)](https://travis-ci.org/atk4/api)
4-
[![Code Climate](https://codeclimate.com/github/atk4/api/badges/gpa.svg)](https://codeclimate.com/github/atk4/api)
54
[![StyleCI](https://styleci.io/repos/107142772/shield)](https://styleci.io/repos/107142772)
65
[![codecov](https://codecov.io/gh/atk4/api/branch/develop/graph/badge.svg)](https://codecov.io/gh/atk4/api)
7-
[![Issue Count](https://codeclimate.com/github/atk4/api/badges/issue_count.svg)](https://codeclimate.com/github/atk4/api)
6+
[![Code Climate](https://codeclimate.com/github/atk4/api/badges/gpa.svg)](https://codeclimate.com/github/atk4/api)
7+
[![Issue Count](https://codeclimate.com/github/atk4/api/badges/issue_count.svg)](https://codeclimate.com/github/atk4/api/issues)
88

99
[![License](https://poser.pugx.org/atk4/api/license)](https://packagist.org/packages/atk4/api)
1010
[![GitHub release](https://img.shields.io/github/release/atk4/api.svg?maxAge=2592000)](https://packagist.org/packages/atk4/api)
1111

12+
End-to-end implementation for your RESTful API and RPC. Provides a very simple means for you to define API end-points for the application that already uses [Agile Data](https://github.com/atk4/data).
13+
14+
## 1. Simple To Use
15+
16+
Agile API strives to be very simple and work out of the box. Below is a minimal code to get your basic API going, put that into `v1.php` file then invoke `composer require atk4/api` :
17+
18+
``` php
19+
include 'vendor/autoload.php';
20+
21+
$api = new \atk4\api\Api();
22+
23+
// Simple handling of GET request through a callback.
24+
$api->get('/ping', function() {
25+
return 'Pong';
26+
});
27+
28+
// Methods can accept arguments, and everything is type-safe.
29+
$api->get('/hello/:name', function ($name) {
30+
return "Hello, $name";
31+
});
32+
```
33+
34+
## 2. Agile Data Integration
35+
36+
[Agile Data](https://github.com/atk4/data) is a data persistence framework. In simple terms, you can use Agile Data to create your business models (entities) and interact with the database. Agile API is designed to be a perfect integration if you are have already defined classes and persistence in Agile Data. Next code assumes you have `Model Country` and `Persistence $db`:
37+
38+
``` php
39+
$api->rest('/countries', new Country($db));
40+
```
41+
42+
This creates a standard standard-compliant RESTful interface for interfacing the client model:
43+
44+
- `GET /countries` responds with list of all Country records from $db.
45+
- `POST /countries` adds a new Country reading data from Form data or JSON in POST body.
46+
- `GET /countries/123` loads client with specified ID.
47+
- `PATCH /countries/123` with some Form data or JSON will update existing Country.
48+
- `DELETE /countries/123` will delete a record.
49+
50+
Through Agile UI you may add conditions, limits and more. Also second argument can be a call-back:
51+
52+
``` php
53+
$api->rest('/countries', function() use($db) {
54+
$c = new Country($db));
55+
$c->addCondition('is_eu', true);
56+
$c->setLimit(20);
57+
return $c;
58+
});
59+
```
60+
61+
Field types, data conversions, validation and hooks can all be defined through Agile Data, making the API layer very transparent and simple. If you attempt to load non-existant record, API will respond with 404. Other errors will be properly mapped to the API codes or fallback to 500.
62+
63+
64+
65+
# Work in progress
66+
67+
Agile UI is still a work in progress. This readme will be further updated to reflect a current features.
68+
1269

13-
End-to-end implementation for your REST API. Provides a very simple means for you to define API end-points for the application that already uses [Agile Data](https://github.com/atk4/data).
1470

1571
## Planned Features
1672

0 commit comments

Comments
 (0)