mirror of
https://github.com/CachetHQ/Cachet.git
synced 2025-01-17 21:49:01 +01:00
commit
7384da4eba
@ -122,6 +122,8 @@ return array(
|
||||
'Illuminate\View\ViewServiceProvider',
|
||||
'Illuminate\Workbench\WorkbenchServiceProvider',
|
||||
|
||||
'Dingo\Api\ApiServiceProvider',
|
||||
|
||||
),
|
||||
|
||||
/*
|
||||
@ -190,6 +192,8 @@ return array(
|
||||
'Validator' => 'Illuminate\Support\Facades\Validator',
|
||||
'View' => 'Illuminate\Support\Facades\View',
|
||||
|
||||
'API' => 'Dingo\Api\Facades\API'
|
||||
|
||||
),
|
||||
|
||||
);
|
||||
|
153
app/config/packages/dingo/api/config.php
Normal file
153
app/config/packages/dingo/api/config.php
Normal file
@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| API Vendor
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Your vendor is used in the "Accept" request header and will be used by
|
||||
| the consumers of your API. Typically this will be the name of your
|
||||
| application or website.
|
||||
|
|
||||
*/
|
||||
|
||||
'vendor' => 'cachet',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default API Version
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When a request is made to the API and no version is specified then it
|
||||
| will default to the version specified here.
|
||||
|
|
||||
*/
|
||||
|
||||
'version' => 'v1',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default API Prefix
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| A default prefix to use for your API routes so you don't have to
|
||||
| specify it for each group.
|
||||
|
|
||||
*/
|
||||
|
||||
'prefix' => null,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default API Domain
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| A default domain to use for your API routes so you don't have to
|
||||
| specify it for each group.
|
||||
|
|
||||
*/
|
||||
|
||||
'domain' => null,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Conditional Requests
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Globally enable conditional requests so that an ETag header is added to
|
||||
| any successful response. Subsequent requests will perform a check and
|
||||
| will return a 304 Not Modified. This can also be enabled or disabled
|
||||
| on certain groups or routes.
|
||||
|
|
||||
*/
|
||||
|
||||
'conditional_request' => true,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Authentication Providers
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The authentication providers that should be used when attempting to
|
||||
| authenticate an incoming API request.
|
||||
|
|
||||
*/
|
||||
|
||||
'auth' => [
|
||||
'basic' => function ($app) {
|
||||
return new Dingo\Api\Auth\BasicProvider($app['auth']);
|
||||
}
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Rate Limiting
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Consumers of your API can be limited to the amount of requests they can
|
||||
| make. You can configure the limit based on whether the consumer is
|
||||
| authenticated or unauthenticated.
|
||||
|
|
||||
| The "limit" is the number of requests the consumer can make within a
|
||||
| certain amount time which is defined by "reset" in minutes.
|
||||
|
|
||||
| By default rate limiting is disabled.
|
||||
|
|
||||
*/
|
||||
|
||||
'rate_limiting' => [
|
||||
|
||||
'authenticated' => [
|
||||
'limit' => 0,
|
||||
'reset' => 60
|
||||
],
|
||||
|
||||
'unauthenticated' => [
|
||||
'limit' => 0,
|
||||
'reset' => 60
|
||||
],
|
||||
|
||||
'exceeded' => 'API rate limit has been exceeded.'
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Response Transformer
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Responses can be transformed so that they are easier to format. By
|
||||
| default a Fractal transformer will be used to transform any
|
||||
| responses prior to formatting. You can easily replace
|
||||
| this with your own transformer.
|
||||
|
|
||||
*/
|
||||
|
||||
'transformer' => function ($app) {
|
||||
$fractal = new League\Fractal\Manager;
|
||||
|
||||
return new Dingo\Api\Transformer\FractalTransformer($fractal);
|
||||
},
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Response Formats
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Responses can be returned in multiple formats by registering different
|
||||
| response formatters. You can also customize an existing response
|
||||
| formatter.
|
||||
|
|
||||
*/
|
||||
|
||||
'default_format' => 'json',
|
||||
|
||||
'formats' => [
|
||||
|
||||
'json' => new Dingo\Api\Http\ResponseFormat\JsonResponseFormat
|
||||
|
||||
]
|
||||
|
||||
];
|
18
app/controllers/ApiController.php
Normal file
18
app/controllers/ApiController.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
class ApiController extends Dingo\Api\Routing\Controller{
|
||||
|
||||
public function getComponents() {
|
||||
return Component::all();
|
||||
}
|
||||
|
||||
public function getComponent($id) {
|
||||
$component = Component::find($id);
|
||||
if ($component) {
|
||||
return $component;
|
||||
} else {
|
||||
App::abort(404, 'Component not found');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class Component extends Eloquent {
|
||||
class Component extends Eloquent implements Dingo\Api\Transformer\TransformableInterface {
|
||||
/**
|
||||
* Looks up the human readable version of the status.
|
||||
* @return string
|
||||
@ -26,4 +26,14 @@
|
||||
case 4: return 'text-danger';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the transformer instance.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTransformer()
|
||||
{
|
||||
return new ComponentTransformer();
|
||||
}
|
||||
}
|
||||
|
9
app/routes/api.php
Normal file
9
app/routes/api.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
Route::api(['version' => 'v1', 'prefix' => 'api'], function()
|
||||
{
|
||||
|
||||
Route::get('components', 'ApiController@getComponents');
|
||||
Route::get('components/{id}', 'ApiController@getComponent');
|
||||
|
||||
});
|
@ -16,6 +16,7 @@ ClassLoader::addDirectories(array(
|
||||
app_path().'/commands',
|
||||
app_path().'/controllers',
|
||||
app_path().'/models',
|
||||
app_path().'/transformers',
|
||||
app_path().'/database/seeds',
|
||||
app_path().'/filters',
|
||||
|
||||
|
16
app/transformers/ComponentTransformer.php
Normal file
16
app/transformers/ComponentTransformer.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
class ComponentTransformer extends League\Fractal\TransformerAbstract {
|
||||
|
||||
public function transform(Component $component)
|
||||
{
|
||||
return [
|
||||
'id' => (int) $component->id,
|
||||
'name' => $component->name,
|
||||
'description' => $component->description,
|
||||
'status_id' => (int) $component->status,
|
||||
'status' => $component->getHumanStatusAttribute(),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -6,13 +6,15 @@
|
||||
"type": "project",
|
||||
"require": {
|
||||
"laravel/framework": "4.2.*",
|
||||
"guzzlehttp/guzzle": "4.*"
|
||||
"guzzlehttp/guzzle": "4.*",
|
||||
"dingo/api": "~0.6"
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"app/commands",
|
||||
"app/controllers",
|
||||
"app/models",
|
||||
"app/transformers",
|
||||
"app/database/migrations",
|
||||
"app/database/seeds",
|
||||
"app/tests/TestCase.php",
|
||||
|
244
composer.lock
generated
244
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"hash": "cce6015a015d1aaf6f2cae97680d79b9",
|
||||
"hash": "d004b3a48b758871152fca82ba1aa988",
|
||||
"packages": [
|
||||
{
|
||||
"name": "classpreloader/classpreloader",
|
||||
@ -87,6 +87,71 @@
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"time": "2014-01-17 12:21:18"
|
||||
},
|
||||
{
|
||||
"name": "dingo/api",
|
||||
"version": "v0.6.6",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/dingo/api.git",
|
||||
"reference": "87ce1b823941deddf266d2fcbf537145c0530716"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/dingo/api/zipball/87ce1b823941deddf266d2fcbf537145c0530716",
|
||||
"reference": "87ce1b823941deddf266d2fcbf537145c0530716",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"illuminate/support": "~4.1|~5.0",
|
||||
"league/fractal": "0.8.*",
|
||||
"php": ">=5.4.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"illuminate/auth": "~4.1",
|
||||
"illuminate/console": "~4.1",
|
||||
"illuminate/database": "~4.1",
|
||||
"illuminate/events": "~4.1",
|
||||
"illuminate/pagination": "~4.1",
|
||||
"illuminate/routing": "~4.1",
|
||||
"lucadegasperi/oauth2-server-laravel": "1.0.*",
|
||||
"mockery/mockery": "~0.9",
|
||||
"phpunit/phpunit": "~4.0",
|
||||
"squizlabs/php_codesniffer": "1.*"
|
||||
},
|
||||
"suggest": {
|
||||
"lucadegasperi/oauth2-server-laravel": "Use the League OAuth 2.0 server to protect your API."
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "0.6-dev",
|
||||
"dev-develop": "0.7-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Dingo\\Api\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD-3-Clause"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jason Lewis",
|
||||
"email": "jason.lewis1991@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "A RESTful API package for the Laravel framework.",
|
||||
"keywords": [
|
||||
"api",
|
||||
"dingo",
|
||||
"laravel",
|
||||
"restful"
|
||||
],
|
||||
"time": "2014-09-29 00:06:33"
|
||||
},
|
||||
{
|
||||
"name": "filp/whoops",
|
||||
"version": "1.1.3",
|
||||
@ -145,6 +210,124 @@
|
||||
],
|
||||
"time": "2014-10-26 09:05:09"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/guzzle",
|
||||
"version": "4.2.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/guzzle.git",
|
||||
"reference": "66fd916e9f9130bc22c51450476823391cb2f67c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/66fd916e9f9130bc22c51450476823391cb2f67c",
|
||||
"reference": "66fd916e9f9130bc22c51450476823391cb2f67c",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"guzzlehttp/streams": "~2.1",
|
||||
"php": ">=5.4.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-curl": "*",
|
||||
"phpunit/phpunit": "~4.0",
|
||||
"psr/log": "~1.0"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-curl": "Guzzle will use specific adapters if cURL is present"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "4.2-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"GuzzleHttp\\": "src/"
|
||||
},
|
||||
"files": [
|
||||
"src/functions.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Michael Dowling",
|
||||
"email": "mtdowling@gmail.com",
|
||||
"homepage": "https://github.com/mtdowling"
|
||||
}
|
||||
],
|
||||
"description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients",
|
||||
"homepage": "http://guzzlephp.org/",
|
||||
"keywords": [
|
||||
"client",
|
||||
"curl",
|
||||
"framework",
|
||||
"http",
|
||||
"http client",
|
||||
"rest",
|
||||
"web service"
|
||||
],
|
||||
"time": "2014-10-05 19:29:14"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/streams",
|
||||
"version": "2.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/streams.git",
|
||||
"reference": "f91b721d73f0e561410903b3b3c90a5d0e40b534"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/streams/zipball/f91b721d73f0e561410903b3b3c90a5d0e40b534",
|
||||
"reference": "f91b721d73f0e561410903b3b3c90a5d0e40b534",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.4.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.0-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"GuzzleHttp\\Stream\\": "src/"
|
||||
},
|
||||
"files": [
|
||||
"src/functions.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Michael Dowling",
|
||||
"email": "mtdowling@gmail.com",
|
||||
"homepage": "https://github.com/mtdowling"
|
||||
}
|
||||
],
|
||||
"description": "Provides a simple abstraction over streams of data (Guzzle 4+)",
|
||||
"homepage": "http://guzzlephp.org/",
|
||||
"keywords": [
|
||||
"Guzzle",
|
||||
"stream"
|
||||
],
|
||||
"time": "2014-08-17 21:15:53"
|
||||
},
|
||||
{
|
||||
"name": "ircmaxell/password-compat",
|
||||
"version": "1.0.3",
|
||||
@ -347,6 +530,65 @@
|
||||
],
|
||||
"time": "2014-10-04 18:48:27"
|
||||
},
|
||||
{
|
||||
"name": "league/fractal",
|
||||
"version": "0.8.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/thephpleague/fractal.git",
|
||||
"reference": "9985eee7efc42ef472da07856cdd3fd29c57642c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/thephpleague/fractal/zipball/9985eee7efc42ef472da07856cdd3fd29c57642c",
|
||||
"reference": "9985eee7efc42ef472da07856cdd3fd29c57642c",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"illuminate/pagination": "~4.1",
|
||||
"mockery/mockery": "~0.9",
|
||||
"phpunit/phpunit": "~4.0",
|
||||
"squizlabs/php_codesniffer": "~1.5"
|
||||
},
|
||||
"suggest": {
|
||||
"illuminate/pagination": "The Illuminate Pagination component."
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "0.8-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"League\\Fractal\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Phil Sturgeon",
|
||||
"email": "email@philsturgeon.co.uk",
|
||||
"homepage": "http://philsturgeon.co.uk/",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "Handle the output of complex data structures ready for JSON output.",
|
||||
"homepage": "http://fractal.thephpleague.com/",
|
||||
"keywords": [
|
||||
"api",
|
||||
"json",
|
||||
"league",
|
||||
"rest"
|
||||
],
|
||||
"time": "2014-06-14 11:11:41"
|
||||
},
|
||||
{
|
||||
"name": "monolog/monolog",
|
||||
"version": "1.11.0",
|
||||
|
Loading…
x
Reference in New Issue
Block a user