Skip to content

Commit

Permalink
Merge pull request #67 from fleetbase/dev-v1.4.7
Browse files Browse the repository at this point in the history
v1.4.7
  • Loading branch information
roncodes authored Feb 21, 2024
2 parents 795c90c + 0a785af commit 1bd34c5
Show file tree
Hide file tree
Showing 12 changed files with 409 additions and 44 deletions.
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fleetbase/core-api",
"version": "1.4.5",
"version": "1.4.7",
"description": "Core Framework and Resources for Fleetbase API",
"keywords": [
"fleetbase",
Expand Down Expand Up @@ -44,7 +44,10 @@
"spatie/laravel-responsecache": "^7.4",
"spatie/laravel-sluggable": "^3.5",
"sqids/sqids": "^0.4.1",
"xantios/mimey": "^2.2.0"
"xantios/mimey": "^2.2.0",
"laravel-notification-channels/apn": "^5.0",
"laravel-notification-channels/fcm": "^4.1",
"laravel-notification-channels/twilio": "^3.3"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.34.1",
Expand Down
221 changes: 221 additions & 0 deletions config/firebase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
<?php

declare(strict_types=1);

return [
/*
* ------------------------------------------------------------------------
* Default Firebase project
* ------------------------------------------------------------------------
*/

'default' => env('FIREBASE_PROJECT', 'app'),

/*
* ------------------------------------------------------------------------
* Firebase project configurations
* ------------------------------------------------------------------------
*/

'projects' => [
'app' => [

/*
* ------------------------------------------------------------------------
* Credentials / Service Account
* ------------------------------------------------------------------------
*
* In order to access a Firebase project and its related services using a
* server SDK, requests must be authenticated. For server-to-server
* communication this is done with a Service Account.
*
* If you don't already have generated a Service Account, you can do so by
* following the instructions from the official documentation pages at
*
* https://firebase.google.com/docs/admin/setup#initialize_the_sdk
*
* Once you have downloaded the Service Account JSON file, you can use it
* to configure the package.
*
* If you don't provide credentials, the Firebase Admin SDK will try to
* auto-discover them
*
* - by checking the environment variable FIREBASE_CREDENTIALS
* - by checking the environment variable GOOGLE_APPLICATION_CREDENTIALS
* - by trying to find Google's well known file
* - by checking if the application is running on GCE/GCP
*
* If no credentials file can be found, an exception will be thrown the
* first time you try to access a component of the Firebase Admin SDK.
*
*/

'credentials' => env('FIREBASE_CREDENTIALS', env('GOOGLE_APPLICATION_CREDENTIALS')),

/*
* ------------------------------------------------------------------------
* Firebase Auth Component
* ------------------------------------------------------------------------
*/

'auth' => [
'tenant_id' => env('FIREBASE_AUTH_TENANT_ID'),
],

/*
* ------------------------------------------------------------------------
* Firestore Component
* ------------------------------------------------------------------------
*/

'firestore' => [

/*
* If you want to access a Firestore database other than the default database,
* enter its name here.
*
* By default, the Firestore client will connect to the `(default)` database.
*
* https://firebase.google.com/docs/firestore/manage-databases
*/

// 'database' => env('FIREBASE_FIRESTORE_DATABASE'),
],

/*
* ------------------------------------------------------------------------
* Firebase Realtime Database
* ------------------------------------------------------------------------
*/

'database' => [

/*
* In most of the cases the project ID defined in the credentials file
* determines the URL of your project's Realtime Database. If the
* connection to the Realtime Database fails, you can override
* its URL with the value you see at
*
* https://console.firebase.google.com/u/1/project/_/database
*
* Please make sure that you use a full URL like, for example,
* https://my-project-id.firebaseio.com
*/

'url' => env('FIREBASE_DATABASE_URL'),

/*
* As a best practice, a service should have access to only the resources it needs.
* To get more fine-grained control over the resources a Firebase app instance can access,
* use a unique identifier in your Security Rules to represent your service.
*
* https://firebase.google.com/docs/database/admin/start#authenticate-with-limited-privileges
*/

// 'auth_variable_override' => [
// 'uid' => 'my-service-worker'
// ],

],

'dynamic_links' => [

/*
* Dynamic links can be built with any URL prefix registered on
*
* https://console.firebase.google.com/u/1/project/_/durablelinks/links/
*
* You can define one of those domains as the default for new Dynamic
* Links created within your project.
*
* The value must be a valid domain, for example,
* https://example.page.link
*/

'default_domain' => env('FIREBASE_DYNAMIC_LINKS_DEFAULT_DOMAIN'),
],

/*
* ------------------------------------------------------------------------
* Firebase Cloud Storage
* ------------------------------------------------------------------------
*/

'storage' => [

/*
* Your project's default storage bucket usually uses the project ID
* as its name. If you have multiple storage buckets and want to
* use another one as the default for your application, you can
* override it here.
*/

'default_bucket' => env('FIREBASE_STORAGE_DEFAULT_BUCKET'),

],

/*
* ------------------------------------------------------------------------
* Caching
* ------------------------------------------------------------------------
*
* The Firebase Admin SDK can cache some data returned from the Firebase
* API, for example Google's public keys used to verify ID tokens.
*
*/

'cache_store' => env('FIREBASE_CACHE_STORE', 'file'),

/*
* ------------------------------------------------------------------------
* Logging
* ------------------------------------------------------------------------
*
* Enable logging of HTTP interaction for insights and/or debugging.
*
* Log channels are defined in config/logging.php
*
* Successful HTTP messages are logged with the log level 'info'.
* Failed HTTP messages are logged with the log level 'notice'.
*
* Note: Using the same channel for simple and debug logs will result in
* two entries per request and response.
*/

'logging' => [
'http_log_channel' => env('FIREBASE_HTTP_LOG_CHANNEL'),
'http_debug_log_channel' => env('FIREBASE_HTTP_DEBUG_LOG_CHANNEL'),
],

/*
* ------------------------------------------------------------------------
* HTTP Client Options
* ------------------------------------------------------------------------
*
* Behavior of the HTTP Client performing the API requests
*/

'http_client_options' => [

/*
* Use a proxy that all API requests should be passed through.
* (default: none)
*/

'proxy' => env('FIREBASE_HTTP_CLIENT_PROXY'),

/*
* Set the maximum amount of seconds (float) that can pass before
* a request is considered timed out
*
* The default time out can be reviewed at
* https://github.com/kreait/firebase-php/blob/6.x/src/Firebase/Http/HttpClientOptions.php
*/

'timeout' => env('FIREBASE_HTTP_CLIENT_TIMEOUT'),

'guzzle_middlewares' => [],
],
],
],
];
36 changes: 36 additions & 0 deletions config/twilio-notification-channel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

return [
'username' => env('TWILIO_USERNAME'), // optional when using auth token
'password' => env('TWILIO_PASSWORD'), // optional when using auth token
'auth_token' => env('TWILIO_TOKEN'), // optional when using username and password
'account_sid' => env('TWILIO_SID'),

'from' => env('TWILIO_FROM'), // optional
'alphanumeric_sender' => env('TWILIO_ALPHA_SENDER'),

/**
* See https://www.twilio.com/docs/sms/services.
*/
'sms_service_sid' => env('TWILIO_SMS_SERVICE_SID'),

/**
* Specify a number where all calls/messages should be routed. This can be used in development/staging environments
* for testing.
*/
'debug_to' => env('TWILIO_DEBUG_TO'),

/**
* If an exception is thrown with one of these error codes, it will be caught & suppressed.
* To replicate the 2.x behaviour, specify '*' in the array, which will cause all exceptions to be suppressed.
* Suppressed errors will not be logged or reported, but the `NotificationFailed` event will be emitted.
*
* @see https://www.twilio.com/docs/api/errors
*/
'ignored_error_codes' => [
21608, // The 'to' phone number provided is not yet verified for this account.
21211, // Invalid 'To' Phone Number
21614, // 'To' number is not a valid mobile number
21408, // Permission to send an SMS has not been enabled for the region indicated by the 'To' number
],
];
2 changes: 2 additions & 0 deletions src/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public function time()
*/
public function test()
{
dd(config('firebase.projects.app'), config('broadcasting.connections.apn'));

return response()->json(['status' => 'ok']);
}
}
35 changes: 35 additions & 0 deletions src/Http/Controllers/Internal/v1/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace Fleetbase\Http\Controllers\Internal\v1;

use Fleetbase\Exceptions\FleetbaseRequestValidationException;
use Fleetbase\Http\Controllers\FleetbaseController;
use Fleetbase\Http\Requests\Internal\CreateCategoryRequest;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class CategoryController extends FleetbaseController
{
Expand All @@ -12,4 +16,35 @@ class CategoryController extends FleetbaseController
* @var string
*/
public $resource = 'category';

/**
* Creates a record with request payload.
*
* @return \Illuminate\Http\Response
*/
public function createRecord(Request $request)
{
// create validation request
$createCategoryRequest = CreateCategoryRequest::createFrom($request);
$rules = $createCategoryRequest->rules();

// manually validate request
$validator = Validator::make($request->all(), $rules);

if ($validator->fails()) {
return $createCategoryRequest->responseWithErrors($validator);
}

try {
$record = $this->model->createRecordFromRequest($request);

return ['category' => new $this->resource($record)];
} catch (\Exception $e) {
return response()->error($e->getMessage());
} catch (\Illuminate\Database\QueryException $e) {
return response()->error($e->getMessage());
} catch (FleetbaseRequestValidationException $e) {
return response()->error($e->getErrors());
}
}
}
Loading

0 comments on commit 1bd34c5

Please sign in to comment.