diff --git a/.gitignore b/.gitignore index 582640226..6d6bf13f5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,116 @@ -/vendor +# Created by https://www.gitignore.io + +### Laravel ### +/bootstrap/compiled.php +.env.*.php +.env.php + + +### Composer ### composer.phar -composer.lock +vendor/ + +# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file +# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file +# composer.lock + + +### PhpStorm ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm + +*.iml + +## Directory-based project format: +.idea/ +# if you remove the above rule, at least ignore the following: + +# User-specific stuff: +# .idea/workspace.xml +# .idea/tasks.xml +# .idea/dictionaries + +# Sensitive or high-churn files: +# .idea/dataSources.ids +# .idea/dataSources.xml +# .idea/sqlDataSources.xml +# .idea/dynamic.xml +# .idea/uiDesigner.xml + +# Gradle: +# .idea/gradle.xml +# .idea/libraries + +# Mongo Explorer plugin: +# .idea/mongoSettings.xml + +## File-based project format: +*.ipr +*.iws + +## Plugin-specific files: + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties + + +### Linux ### +*~ + +# KDE directory preferences +.directory + + +### OSX ### .DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear on external disk +.Spotlight-V100 +.Trashes + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + + +### Windows ### +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk diff --git a/composer.lock b/composer.lock new file mode 100644 index 000000000..83856a141 --- /dev/null +++ b/composer.lock @@ -0,0 +1,372 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" + ], + "hash": "de693e9c95478a6b0f41e7711ccac56f", + "packages": [ + { + "name": "ellipsesynergie/api-response", + "version": "0.7.0", + "source": { + "type": "git", + "url": "https://github.com/ellipsesynergie/api-response.git", + "reference": "1effd67d13b336da51d299f2f314ed7bf00a927c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ellipsesynergie/api-response/zipball/1effd67d13b336da51d299f2f314ed7bf00a927c", + "reference": "1effd67d13b336da51d299f2f314ed7bf00a927c", + "shasum": "" + }, + "require": { + "league/fractal": "0.9.*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "EllipseSynergie\\ApiResponse\\": "src", + "EllipseSynergie\\ApiResponse\\Tests\\": "tests" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Maxime Beaudoin", + "email": "maxime.beaudoin@ellipse-synergie.com", + "role": "Developer" + }, + { + "name": "Phil Sturgeon", + "email": "email@philsturgeon.co.uk", + "role": "Developer" + } + ], + "description": "Simple package to handle response properly in your API", + "homepage": "https://github.com/ellipsesynergie/api-response", + "keywords": [ + "api", + "fractal", + "json" + ], + "time": "2014-10-07 12:51:37" + }, + { + "name": "illuminate/container", + "version": "v4.2.9", + "target-dir": "Illuminate/Container", + "source": { + "type": "git", + "url": "https://github.com/illuminate/container.git", + "reference": "5c43bd3bd5eea2ed2061cd0dd57d72404aceb978" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/container/zipball/5c43bd3bd5eea2ed2061cd0dd57d72404aceb978", + "reference": "5c43bd3bd5eea2ed2061cd0dd57d72404aceb978", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.2-dev" + } + }, + "autoload": { + "psr-0": { + "Illuminate\\Container": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylorotwell@gmail.com" + } + ], + "time": "2014-09-11 19:02:16" + }, + { + "name": "illuminate/database", + "version": "v4.2.9", + "target-dir": "Illuminate/Database", + "source": { + "type": "git", + "url": "https://github.com/illuminate/database.git", + "reference": "b66a7173ca6a81de3b2ccbd84372bee8624215f1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/database/zipball/b66a7173ca6a81de3b2ccbd84372bee8624215f1", + "reference": "b66a7173ca6a81de3b2ccbd84372bee8624215f1", + "shasum": "" + }, + "require": { + "illuminate/container": "4.2.*", + "illuminate/events": "4.2.*", + "illuminate/support": "4.2.*", + "nesbot/carbon": "~1.0", + "php": ">=5.4.0" + }, + "require-dev": { + "illuminate/cache": "4.2.*", + "illuminate/console": "4.2.*", + "illuminate/filesystem": "4.2.*", + "illuminate/pagination": "4.2.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.2-dev" + } + }, + "autoload": { + "psr-0": { + "Illuminate\\Database": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylorotwell@gmail.com" + } + ], + "keywords": [ + "database", + "laravel", + "orm", + "sql" + ], + "time": "2014-09-11 14:10:29" + }, + { + "name": "illuminate/events", + "version": "v4.2.9", + "target-dir": "Illuminate/Events", + "source": { + "type": "git", + "url": "https://github.com/illuminate/events.git", + "reference": "19f93bcd692a52b39f1bd125f6f112eda0c1b8b0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/events/zipball/19f93bcd692a52b39f1bd125f6f112eda0c1b8b0", + "reference": "19f93bcd692a52b39f1bd125f6f112eda0c1b8b0", + "shasum": "" + }, + "require": { + "illuminate/container": "4.2.*", + "illuminate/support": "4.2.*", + "php": ">=5.4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.2-dev" + } + }, + "autoload": { + "psr-0": { + "Illuminate\\Events": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylorotwell@gmail.com" + } + ], + "time": "2014-08-17 14:08:00" + }, + { + "name": "illuminate/support", + "version": "v4.2.9", + "target-dir": "Illuminate/Support", + "source": { + "type": "git", + "url": "https://github.com/illuminate/support.git", + "reference": "b6716d34afce6e69523725f2534a5c3a54dba964" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/support/zipball/b6716d34afce6e69523725f2534a5c3a54dba964", + "reference": "b6716d34afce6e69523725f2534a5c3a54dba964", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "jeremeamia/superclosure": "~1.0", + "patchwork/utf8": "1.1.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.2-dev" + } + }, + "autoload": { + "psr-0": { + "Illuminate\\Support": "" + }, + "files": [ + "Illuminate/Support/helpers.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylorotwell@gmail.com" + } + ], + "time": "2014-09-12 21:42:43" + }, + { + "name": "league/fractal", + "version": "0.9.1", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/fractal.git", + "reference": "a91cdcfe399a6d330a9285885a9a2a1a7855a915" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/fractal/zipball/a91cdcfe399a6d330a9285885a9a2a1a7855a915", + "reference": "a91cdcfe399a6d330a9285885a9a2a1a7855a915", + "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.9-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-07-06 16:48:26" + }, + { + "name": "nesbot/carbon", + "version": "1.13.0", + "source": { + "type": "git", + "url": "https://github.com/briannesbitt/Carbon.git", + "reference": "5cb6e71055f7b0b57956b73d324cc4de31278f42" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/5cb6e71055f7b0b57956b73d324cc4de31278f42", + "reference": "5cb6e71055f7b0b57956b73d324cc4de31278f42", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "autoload": { + "psr-0": { + "Carbon": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Brian Nesbitt", + "email": "brian@nesbot.com", + "homepage": "http://nesbot.com" + } + ], + "description": "A simple API extension for DateTime.", + "homepage": "https://github.com/briannesbitt/Carbon", + "keywords": [ + "date", + "datetime", + "time" + ], + "time": "2014-09-26 02:52:02" + } + ], + "packages-dev": [ + + ], + "aliases": [ + + ], + "minimum-stability": "stable", + "stability-flags": [ + + ], + "platform": { + "php": ">=5.4.0" + }, + "platform-dev": [ + + ] +} diff --git a/public/.gitkeep b/public/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/Chrisbjr/ApiGuard/Controllers/ApiGuardController.php b/src/Chrisbjr/ApiGuard/Controllers/ApiGuardController.php new file mode 100644 index 000000000..3015c9bd6 --- /dev/null +++ b/src/Chrisbjr/ApiGuard/Controllers/ApiGuardController.php @@ -0,0 +1,202 @@ +beforeFilter($this->apiGuard(), ['apiMethods' => $this->apiMethods]); + } + + private function apiGuard() + { + // Let's instantiate the response class first + $this->manager = new Manager; + + $this->manager->parseIncludes(Input::get(Config::get('api-guard::includeKeyword', 'include'), array())); + + $this->response = new Response($this->manager); + + // api-guard might not be the only before filter on the controller + // loop through any before filters and pull out $apiMethods in the controller + $beforeFilters = $this->getBeforeFilters(); + foreach ($beforeFilters as $filter) { + if (!empty($filter['options']['apiMethods'])) { + $apiMethods = $filter['options']['apiMethods']; + } + } + + // This is the actual request object used + $request = Route::getCurrentRequest(); + + // Let's get the method + Str::parseCallback(Route::currentRouteAction(), null); + $routeArray = Str::parseCallback(Route::currentRouteAction(), null); + + if (last($routeArray) == null) { + // There is no method? + return $this->response->errorMethodNotAllowed(); + } + + $method = last($routeArray); + + // We should check if key authentication is enabled for this method + $keyAuthentication = true; + if (isset($apiMethods[$method]['keyAuthentication']) && $apiMethods[$method]['keyAuthentication'] === false) { + $keyAuthentication = false; + } + + if ($keyAuthentication === true) { + + $key = $request->header(Config::get('api-guard::keyName')); + + if (empty($key)) { + // Try getting the key from elsewhere + $key = Input::get(Config::get('api-guard::keyName')); + } + + if (empty($key)) { + // It's still empty! + return $this->response->errorUnauthorized(); + } + + $this->apiKey = ApiKey::where('key', '=', $key)->first(); + + if (!isset($this->apiKey->id)) { + // ApiKey not found + return $this->response->errorUnauthorized(); + } + + // API key exists + // Check level of API + if (!empty($apiMethods[$method]['level'])) { + if ($this->apiKey->level < $apiMethods[$method]['level']) { + return $this->response->errorForbidden(); + } + } + } + + // Then check the limits of this method + if (!empty($apiMethods[$method]['limits'])) { + + if (Config::get('api-guard::logging') === false) { + Log::warning("[Chrisbjr/ApiGuard] You specified a limit in the $method method but API logging needs to be enabled in the configuration for this to work."); + } + + $limits = $apiMethods[$method]['limits']; + + // We get key level limits first + if ($this->apiKey != null && !empty($limits['key'])) { + + Log::info("key limits found"); + + $keyLimit = (!empty($limits['key']['limit'])) ? $limits['key']['limit'] : 0; + if ($keyLimit == 0 || is_integer($keyLimit) == false) { + Log::warning("[Chrisbjr/ApiGuard] You defined a key limit to the " . Route::currentRouteAction() . " route but you did not set a valid number for the limit variable."); + } else { + if (!$this->apiKey->ignore_limits) { + // This means the apikey is not ignoring the limits + + $keyIncrement = (!empty($limits['key']['increment'])) ? $limits['key']['increment'] : Config::get('api-guard::keyLimitIncrement'); + + $keyIncrementTime = strtotime('-' . $keyIncrement); + + if ($keyIncrementTime == false) { + Log::warning("[Chrisbjr/ApiGuard] You have specified an invalid key increment time. This value can be any value accepted by PHP's strtotime() method"); + } else { + // Count the number of requests for this method using this api key + $apiLogCount = ApiLog::where('api_key_id', '=', $this->apiKey->id) + ->where('route', '=', Route::currentRouteAction()) + ->where('method', '=', $request->getMethod()) + ->where('created_at', '>=', date('Y-m-d H:i:s', $keyIncrementTime)) + ->where('created_at', '<=', date('Y-m-d H:i:s')) + ->count(); + + if ($apiLogCount >= $keyLimit) { + Log::warning("[Chrisbjr/ApiGuard] The API key ID#{$this->apiKey->id} has reached the limit of {$keyLimit} in the following route: " . Route::currentRouteAction()); + return $this->response->errorUnwillingToProcess('You have reached the limit for using this API.'); + } + } + } + } + } + + // Then the overall method limits + if (!empty($limits['method'])) { + $methodLimit = (!empty($limits['method']['limit'])) ? $limits['method']['limit'] : 0; + if ($methodLimit == 0 || is_integer($methodLimit) == false) { + Log::warning("[Chrisbjr/ApiGuard] You defined a method limit to the " . Route::currentRouteAction() . " route but you did not set a valid number for the limit variable."); + } else { + if ($this->apiKey != null && $this->apiKey->ignore_limits == true) { + // then we skip this + } else { + + $methodIncrement = (!empty($limits['method']['increment'])) ? $limits['method']['increment'] : Config::get('api-guard::keyLimitIncrement'); + + $methodIncrementTime = strtotime('-' . $methodIncrement); + + if ($methodIncrementTime == false) { + Log::warning("[Chrisbjr/ApiGuard] You have specified an invalid method increment time. This value can be any value accepted by PHP's strtotime() method"); + } else { + // Count the number of requests for this method + $apiLogCount = ApiLog::where('route', '=', Route::currentRouteAction()) + ->where('method', '=', $request->getMethod()) + ->where('created_at', '>=', date('Y-m-d H:i:s', $methodIncrementTime)) + ->where('created_at', '<=', date('Y-m-d H:i:s')) + ->count(); + + if ($apiLogCount >= $methodLimit) { + Log::warning("[Chrisbjr/ApiGuard] The API has reached the method limit of {$methodLimit} in the following route: " . Route::currentRouteAction()); + return $this->response->errorUnwillingToProcess('The limit for using this API method has been reached'); + } + } + } + } + } + } + // End of cheking limits + + if (Config::get('api-guard::logging') && $keyAuthentication == true) { + // Log this API request + $apiLog = new ApiLog; + $apiLog->api_key_id = $this->apiKey->id; + $apiLog->route = Route::currentRouteAction(); + $apiLog->method = $request->getMethod(); + $apiLog->params = http_build_query(Input::all()); + $apiLog->ip_address = $request->getClientIp(); + $apiLog->save(); + } + } + +} \ No newline at end of file diff --git a/src/controllers/ApiKeyController.php b/src/Chrisbjr/ApiGuard/Controllers/ApiKeyController.php similarity index 100% rename from src/controllers/ApiKeyController.php rename to src/Chrisbjr/ApiGuard/Controllers/ApiKeyController.php diff --git a/src/migrations/2014_06_12_084423_create_api_keys_table.php b/src/Chrisbjr/ApiGuard/Migrations/2014_06_12_084423_create_api_keys_table.php similarity index 100% rename from src/migrations/2014_06_12_084423_create_api_keys_table.php rename to src/Chrisbjr/ApiGuard/Migrations/2014_06_12_084423_create_api_keys_table.php diff --git a/src/models/ApiKey.php b/src/Chrisbjr/ApiGuard/Models/ApiKey.php similarity index 51% rename from src/models/ApiKey.php rename to src/Chrisbjr/ApiGuard/Models/ApiKey.php index be2cb3065..ba715689c 100644 --- a/src/models/ApiKey.php +++ b/src/Chrisbjr/ApiGuard/Models/ApiKey.php @@ -1,18 +1,31 @@ -belongsTo('User'); + return $this->belongsTo(Config::get('auth.model')); } + /** + * A sure method to generate a unique API key + * + * @return string + */ public function generateKey() { do { @@ -24,6 +37,12 @@ public function generateKey() return $newKey; } + /** + * Checks whether a key exists in the database or not + * + * @param $key + * @return bool + */ private function keyExists($key) { $apiKeyCount = ApiKey::where('key', '=', $key)->limit(1)->count(); diff --git a/src/models/ApiLog.php b/src/Chrisbjr/ApiGuard/Models/ApiLog.php similarity index 100% rename from src/models/ApiLog.php rename to src/Chrisbjr/ApiGuard/Models/ApiLog.php diff --git a/src/controllers/.gitkeep b/src/controllers/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/controllers/ApiGuardController.php b/src/controllers/ApiGuardController.php deleted file mode 100644 index f5e464301..000000000 --- a/src/controllers/ApiGuardController.php +++ /dev/null @@ -1,201 +0,0 @@ -beforeFilter(function () { - - // Let's instantiate the response class first - $this->manager = new Manager; - - $this->manager->parseIncludes(Input::get(Config::get('api-guard::includeKeyword', 'include'), array())); - - $this->response = new Response($this->manager); - - // api-guard might not be the only before filter on the controller - // loop through any before filters and pull out $apiMethods in the controller - $beforeFilters = $this->getBeforeFilters(); - foreach ($beforeFilters as $filter) { - if (!empty($filter['options']['apiMethods'])) { - $apiMethods = $filter['options']['apiMethods']; - } - } - - // This is the actual request object used - $request = Route::getCurrentRequest(); - - // Let's get the method - Str::parseCallback(Route::currentRouteAction(), null); - $routeArray = Str::parseCallback(Route::currentRouteAction(), null); - - if (last($routeArray) == null) { - // There is no method? - return $this->response->errorMethodNotAllowed(); - } - - $method = last($routeArray); - - // We should check if key authentication is enabled for this method - $keyAuthentication = true; - if (isset($apiMethods[$method]['keyAuthentication']) && $apiMethods[$method]['keyAuthentication'] === false) { - $keyAuthentication = false; - } - - if ($keyAuthentication === true) { - - $key = $request->header(Config::get('api-guard::keyName')); - - if (empty($key)) { - // Try getting the key from elsewhere - $key = Input::get(Config::get('api-guard::keyName')); - } - - if (empty($key)) { - // It's still empty! - return $this->response->errorUnauthorized(); - } - - $this->apiKey = ApiKey::where('key', '=', $key)->first(); - - if (!isset($this->apiKey->id)) { - // ApiKey not found - return $this->response->errorUnauthorized(); - } - - // API key exists - // Check level of API - if (!empty($apiMethods[$method]['level'])) { - if ($this->apiKey->level < $apiMethods[$method]['level']) { - return $this->response->errorForbidden(); - } - } - } - - // Then check the limits of this method - if (!empty($apiMethods[$method]['limits'])) { - - if (Config::get('api-guard::logging') === false) { - Log::warning("[Chrisbjr/ApiGuard] You specified a limit in the $method method but API logging needs to be enabled in the configuration for this to work."); - } - - $limits = $apiMethods[$method]['limits']; - - // We get key level limits first - if ($this->apiKey != null && !empty($limits['key'])) { - - Log::info("key limits found"); - - $keyLimit = (!empty($limits['key']['limit'])) ? $limits['key']['limit'] : 0; - if ($keyLimit == 0 || is_integer($keyLimit) == false) { - Log::warning("[Chrisbjr/ApiGuard] You defined a key limit to the " . Route::currentRouteAction() . " route but you did not set a valid number for the limit variable."); - } else { - if (!$this->apiKey->ignore_limits) { - // This means the apikey is not ignoring the limits - - $keyIncrement = (!empty($limits['key']['increment'])) ? $limits['key']['increment'] : Config::get('api-guard::keyLimitIncrement'); - - $keyIncrementTime = strtotime('-' . $keyIncrement); - - if ($keyIncrementTime == false) { - Log::warning("[Chrisbjr/ApiGuard] You have specified an invalid key increment time. This value can be any value accepted by PHP's strtotime() method"); - } else { - // Count the number of requests for this method using this api key - $apiLogCount = ApiLog::where('api_key_id', '=', $this->apiKey->id) - ->where('route', '=', Route::currentRouteAction()) - ->where('method', '=', $request->getMethod()) - ->where('created_at', '>=', date('Y-m-d H:i:s', $keyIncrementTime)) - ->where('created_at', '<=', date('Y-m-d H:i:s')) - ->count(); - - if ($apiLogCount >= $keyLimit) { - Log::warning("[Chrisbjr/ApiGuard] The API key ID#{$this->apiKey->id} has reached the limit of {$keyLimit} in the following route: " . Route::currentRouteAction()); - return $this->response->errorUnwillingToProcess('You have reached the limit for using this API.'); - } - } - } - } - } - - // Then the overall method limits - if (!empty($limits['method'])) { - $methodLimit = (!empty($limits['method']['limit'])) ? $limits['method']['limit'] : 0; - if ($methodLimit == 0 || is_integer($methodLimit) == false) { - Log::warning("[Chrisbjr/ApiGuard] You defined a method limit to the " . Route::currentRouteAction() . " route but you did not set a valid number for the limit variable."); - } else { - if ($this->apiKey != null && $this->apiKey->ignore_limits == true) { - // then we skip this - } else { - - $methodIncrement = (!empty($limits['method']['increment'])) ? $limits['method']['increment'] : Config::get('api-guard::keyLimitIncrement'); - - $methodIncrementTime = strtotime('-' . $methodIncrement); - - if ($methodIncrementTime == false) { - Log::warning("[Chrisbjr/ApiGuard] You have specified an invalid method increment time. This value can be any value accepted by PHP's strtotime() method"); - } else { - // Count the number of requests for this method - $apiLogCount = ApiLog::where('route', '=', Route::currentRouteAction()) - ->where('method', '=', $request->getMethod()) - ->where('created_at', '>=', date('Y-m-d H:i:s', $methodIncrementTime)) - ->where('created_at', '<=', date('Y-m-d H:i:s')) - ->count(); - - if ($apiLogCount >= $methodLimit) { - Log::warning("[Chrisbjr/ApiGuard] The API has reached the method limit of {$methodLimit} in the following route: " . Route::currentRouteAction()); - return $this->response->errorUnwillingToProcess('The limit for using this API method has been reached'); - } - } - } - } - } - } - // End of cheking limits - - if (Config::get('api-guard::logging') && $keyAuthentication == true) { - // Log this API request - $apiLog = new ApiLog; - $apiLog->api_key_id = $this->apiKey->id; - $apiLog->route = Route::currentRouteAction(); - $apiLog->method = $request->getMethod(); - $apiLog->params = http_build_query(Input::all()); - $apiLog->ip_address = $request->getClientIp(); - $apiLog->save(); - } - }, ['apiMethods' => $this->apiMethods]); - } - -} \ No newline at end of file diff --git a/src/lang/.gitkeep b/src/lang/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/migrations/.gitkeep b/src/migrations/.gitkeep deleted file mode 100644 index e69de29bb..000000000