Skip to content

Commit

Permalink
Merge pull request #23 from atk4/release/0.3
Browse files Browse the repository at this point in the history
Releasing 0.3 into master
  • Loading branch information
DarkSide666 committed Feb 11, 2020
2 parents ade49be + 9cb7707 commit acd9776
Show file tree
Hide file tree
Showing 15 changed files with 628 additions and 131 deletions.
52 changes: 52 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
engines:
duplication:
enabled: true
config:
languages:
- php
fixme:
enabled: true
phpmd:
enabled: true
exclude_fingerprints:
- 42b4b225a9c6cf44b27182f397e2b7ad # REMOVE this one when replacing with something useful
checks:
CyclomaticComplexity:
enabled: false
Design/TooManyPublicMethods:
enabled: false
Design/TooManyMethods:
enabled: false
Design/NpathComplexity:
enabled: false
Design/WeightedMethodCount:
enabled: false
Design/LongClass:
enabled: false
Controversial/CamelCaseMethodName:
enabled: false
Controversial/CamelCaseParameterName:
enabled: false
Controversial/CamelCasePropertyName:
enabled: false
Controversial/CamelCaseVariableName:
enabled: false
Controversial/CamelCaseClassName:
enabled: false
Controversial/Superglobals: # we use SESSION global
enabled: false
Naming/ShortVariable:
enabled: false
CleanCode/ElseExpression:
enabled: false
Design/LongMethod: # sometimes we have longer methods than 100 rows
enabled: false
radon:
enabled: true
ratings:
paths:
- src/**
exclude_paths:
- docs/**
- tests/**
- vendor/**
5 changes: 5 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# See https://github.com/release-drafter/release-drafter#configuration
template: |
## What’s Changed
$CHANGES
43 changes: 43 additions & 0 deletions .github/workflows/bundler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Bundler

on: create

jobs:
autocommit:
name: Update to stable dependencies
if: startsWith(github.ref, 'refs/heads/release/')
runs-on: ubuntu-latest
container:
image: atk4/image:latest # https://github.com/atk4/image
steps:
- uses: actions/checkout@master
- run: echo ${{ github.ref }}
- name: Update to stable dependencies
run: |
# replaces X keys with X-release keys
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
v=$(echo ${{ github.ref }} | cut -d / -f 4)
echo "::set-env name=version::$v"
- uses: teaminkling/autocommit@master
with:
commit-message: Setting release dependencies
- uses: ad-m/github-push-action@master
with:
branch: ${{ github.ref }}
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: pull-request
uses: romaninsh/pull-request@master
with:
source_branch: "release/${{ env.version }}"
destination_branch: "master" # If blank, default: master
pr_title: "Releasing ${{ env.version }} into master"
pr_body: |
- [ ] Review changes (must include stable dependencies)
- [ ] Merge this PR into master (will delete ${{ github.ref }})
- [ ] Go to Releases and create TAG from master
Do not merge master into develop
pr_reviewer: "romaninsh"
pr_assignee: "romaninsh"
github_token: ${{ secrets.GITHUB_TOKEN }}
16 changes: 16 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Release Drafter

on:
push:
# branches to consider in the event; optional, defaults to all
branches:
- develop

jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: toolmantim/release-drafter@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50 changes: 50 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Unit Testing

on:
pull_request:
branches: '*'
push:
branches:
- master
- develop

jobs:
unit-test:
name: Unit Testing
runs-on: ubuntu-latest
container:
image: atk4/image:${{ matrix.php }} # https://github.com/atk4/image
strategy:
matrix:
php: ['7.2', '7.3', 'latest']
steps:
- uses: actions/checkout@v1
# need this to trick composer
- run: php --version
- run: "git branch develop; git checkout develop"
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('composer.json') }}
restore-keys: |
${{ runner.os }}-composer-
- run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader

- name: Run Tests
run: |
mkdir -p build/logs
- name: SQLite Testing
run: vendor/bin/phpunit --configuration phpunit.xml --coverage-text

- uses: codecov/codecov-action@v1
if: matrix.php == 'latest'
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: build/logs/clover.xml
36 changes: 16 additions & 20 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
language: php

php:
- '5.6'
- '7.0'
- '7.1'
- '7.2'
- '7.3'

cache:
directories:
Expand All @@ -13,34 +12,31 @@ cache:
# - mysql

before_script:
- composer install
- composer install
# - mysql -e 'create database dsql_test;'


after_script:
- echo $TRAVIS_PHP_VERSION
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.0" ]]; then echo "Sending codecov report"; bash <(curl -s https://codecov.io/bash); fi
- echo $TRAVIS_BRANCH
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.2" ]]; then echo "Sending coverage report"; vendor/bin/test-reporter --coverage-report build/logs/clover.xml; fi
- 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

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

notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/b33a2db0c636f34bafa9
on_success: change # options: [always|never|change] default: always
on_failure: always # options: [always|never|change] default: always
on_start: never # options: [always|never|change] default: always

slack:
rooms:
- agiletoolkit:bjrKuPBf1h4cYiNxPBQ1kF6c#dsql
on_success: change

urls:
- https://webhooks.gitter.im/e/c4000ab24556b09cb3e7

on_success: change # options: [always|never|change] default: always
on_failure: always # options: [always|never|change] default: always
on_start: never # options: [always|never|change] default: always

email: false
slack:
rooms:
- agiletoolkit:bjrKuPBf1h4cYiNxPBQ1kF6c#dsql
on_success: change

email: false
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Pre-releases

### 0.2 More flexible REST lookups

- add support for looking up by fields other than ID: "api/country/code:GB"

### 0.1 Initial release

- added post(), get(), etc
- added rest() and integration with Model Data
- first working prototype
62 changes: 59 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,72 @@
# Agile API Framework

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

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

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).

## 1. Simple To Use

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` :

``` php
include 'vendor/autoload.php';

$api = new \atk4\api\Api();

// Simple handling of GET request through a callback.
$api->get('/ping', function() {
return 'Pong';
});

// Methods can accept arguments, and everything is type-safe.
$api->get('/hello/:name', function ($name) {
return "Hello, $name";
});
```

## 2. Agile Data Integration

[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`:

``` php
$api->rest('/countries', new Country($db));
```

This creates a standard standard-compliant RESTful interface for interfacing the client model:

- `GET /countries` responds with list of all Country records from $db.
- `POST /countries` adds a new Country reading data from Form data or JSON in POST body.
- `GET /countries/123` loads client with specified ID.
- `PATCH /countries/123` with some Form data or JSON will update existing Country.
- `DELETE /countries/123` will delete a record.

Through Agile UI you may add conditions, limits and more. Also second argument can be a call-back:

``` php
$api->rest('/countries', function() use($db) {
$c = new Country($db));
$c->addCondition('is_eu', true);
$c->setLimit(20);
return $c;
});
```

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.



# Work in progress

Agile UI is still a work in progress. This readme will be further updated to reflect a current features.


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).

## Planned Features

Expand Down
Loading

0 comments on commit acd9776

Please sign in to comment.