Dingo/Laravel server to provide data to ok-p2p clients. The main purpose of this server is to provide fake data and not be in need to use client server.
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable, creative experience to be truly fulfilling. Laravel attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as:
- Simple, fast routing engine.
- Powerful dependency injection container.
- Multiple back-ends for session and cache storage.
- Expressive, intuitive database ORM.
- Database agnostic schema migrations.
- Robust background job processing.
- Real-time event broadcasting.
Laravel is accessible, yet powerful, providing tools needed for large, robust applications. A superb combination of simplicity, elegance, and innovation give you tools you need to build any application with which you are tasked.
The Dingo API package is meant to provide you, the developer, with a set of tools to help you easily and quickly build your own API. While the goal of this package is to remain as flexible as possible it still won't cover all situations and solve all problems.
This package provides tools for the following, and more:
- Content Negotiation
- Multiple Authentication Adapters
- API Versioning
- Rate Limiting
- Response Transformers and Formatters
- Error and Exception Handling
- Internal Requests
- API Blueprint Documentation
- PHP 5.6+
- Composer
- PHP curl extension
First install dependencies via composer.
$ composer install //Install dependencies
$ php artisan vendor:publish --provider="Dingo\Api\Provider\LaravelServiceProvider"
$ php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\JWTAuthServiceProvider" //Add JWTAuth for authentication
$ php artisan jwt:generate //Generate a key
There are a couple of steps to do before executing for the first time.
The server requires a couple of environment variables to launch. This values should be located on a file called .env.
$ touch .env
Copy the following values in this file
DB_CONNECTION=sqlite
API_PREFIX='api'
JWT_TTL=5256000
SMS_EMISOR_NAME=<the name you want as SMS emisor>
SMS_API_KEY=<API key for sending SMS>
SMS_API_SECRET=<Secret API Key for sending SMS>
SMS_PROVIDER=<SMS provider>
This values reference to the database used, the endpoint of the REST services, and the expiration date of the token (set to 10 years, currently JWTAuth does not support permanent token within the stable version) For information about SMS keys, refer to SMS Provider
There are more environment variables. See Dingo Configuration for more info.
You need to create a database with associated tables in order to query elements. Go to the project folder and execute the following
$ touch database/database.sqlite // Create an empty file
$ php artisan migrate //This will execute the migration files
Now the database is created, but it is empty.
Since the application does not allow to add users or accounts, you should store the data manually on the database. The first option is to run the database seeds provided with the project. This will add users, accounts, transactions and contacts.
$ php artisan migrate
Users would be created with a default password of 0000. You might need to check user's document value, though.
Another option, is to run an artisan command for adding users. This way, you have control over required user info, like name and login credentials.
The execution script will ask for some input. When it has finished, an output will be displayed in the screen, with info about user, his account and performed transactions.
$ php artisan user:add
Specify user name:
> Foo Bar
Specify user NIF?:
> 11223344A
Specify user password:
>
This will create a user with fake account, contacts and transactions. Proceed? (yes/no) [no]:
> yes
Feeding data
10/10 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
+---------+-------------+-----------+---------+-------------------------+
| User ID | Name | Document | DocType | Email |
+---------+-------------+-----------+---------+--------------------------+
| 3 | Foo Bar | 11223344A | N | [email protected] |
+---------+-------------+-----------+---------+--------------------------+
+------------+----------------------------------+-----------+----------+
| Account ID | Number | Amount | Currency |
+------------+----------------------------------+-----------+----------+
| 3 | ES376508099128672015618101486163 | 321310.82 | EUR |
+------------+----------------------------------+-----------+----------+
+------------+--------------------------+--------------+---------------+
| Contact ID | Name | Phone | Country |
+------------+--------------------------+--------------+-------------+
| 26 | Prof. Treva Baumbach DDS | 34-617280197 | Singapore |
| 27 | Roma Ondricka PhD | 34-643505558 | Georgia |
| 28 | Vita Eichmann | 34-603742780 | Estonia |
| 29 | Felix Grady | 34-673370724 | Iraq |
| 30 | Rollin Veum MD | 34-699204544 | Paraguay |
| 31 | Lempi Considine | 34-613669767 | Estonia |
| 32 | Brielle Franecki | 34-627955125 | Timor-Leste |
+------------+--------------------------+--------------+-------------+
+----------------+----------+---------+-------+-------------------+
| Transaction ID | Concept | Amount | State | Agent destination |
+----------------+----------+---------+-------+-------------------+
| 27 | dolores | 415.344 | 8 | 26 |
| 28 | suscipit | 193.669 | 0 | 27 |
| 29 | est | 319.185 | 0 | 28 |
| 30 | non | 264.162 | 3 | 29 |
| 31 | dolor | 343.67 | 6 | 30 |
| 32 | ratione | 53.23 | 7 | 31 |
| 33 | aut | 14.783 | 4 | 32 |
+----------------+----------+---------+-------+-------------------+
A not required but recommended action is to mimic the transaction's state updates. After performing a new transaction in the app, it will be saved with an in_process state. This is ok for demo purposes, but it could be even better if this "processing" transactions would automatically update to a definitive state after a while. For this, an Scheduled task has been added, that will update every processing transaction to completed after a couple of hours. You just need to add the following cron job to your machine.
$ php artisan schedule:run
This will execute every artisan command scheduled in the server.
If you'd like to execute the command manually:
$ php artisan transaction:update
The server uses an external SMS provider in order to send confirmation code transactions to users. Currently, the server supports the following providers:
You can define your desired provider by specifying the value SMS_PROVIDER within your environment variables. The supported values are:
- TWILIO
- NEXMO
- SMSPUBLI
You will also need to define your SMS_API_KEY, and in, some providers, your SMS_API_SECRET. The last value you need to define is SMS_EMISOR_NAME. If your selected provider supports it, you can specify the name of the sender of the SMS. Refer to the external documentation of your provider for more info.
Now that you have configured the server for the first time, it can be launched:
$ php artisan serve
This command will launch on localhost on port 8000. If you would like to launch in an specific host, you should run
$ php artisan serve --host=188.226.223.252 --port=4563
This command will launch the server within specified host at port 4563. You can, of course, specify your desired values.