Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
abalsh
/
Garlix
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
bb696f31
authored
May 04, 2019
by
Florian Shllaku
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Crypto Backend. Done by Abalsh on Flshll's PC
parent
88e51250
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
127 additions
and
0 deletions
app/Console/Commands/updatecrypto.php
app/Http/Controllers/Controller.php
database/migrations/2019_05_03_230115_create_crypto_table.php
vendor/composer/autoload_classmap.php
vendor/composer/autoload_static.php
app/Console/Commands/updatecrypto.php
0 → 100644
View file @
bb696f31
<?php
namespace
App\Console\Commands
;
use
Illuminate\Console\Command
;
use
Illuminate\Support\Facades\DB
;
class
updatecrypto
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'update:crypto'
;
/**
* The console command description.
*
* @var string
*/
protected
$description
=
'Command description'
;
/**
* Create a new command instance.
*
* @return void
*/
public
function
__construct
()
{
parent
::
__construct
();
}
/**
* Execute the console command.
*
* @return mixed
*/
public
function
handle
()
{
$client
=
new
\GuzzleHttp\Client
([
'headers'
=>
[
'X-CMC_PRO_API_KEY'
=>
env
(
"CMC_API_KEY"
,
null
),
'Accept-Encoding'
=>
'deflate, gzip'
]
]);
$res
=
$client
->
request
(
'GET'
,
'https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest'
,
[
'query'
=>
[
'limit'
=>
'100'
,
'convert'
=>
'EUR'
],
'Filter'
=>
[
'data'
]
]);
//$res->getStatusCode();
$result
=
json_decode
(
$res
->
getBody
(),
true
);
DB
::
beginTransaction
();
foreach
(
$result
[
"data"
]
as
$item
)
{
DB
::
table
(
'crypto'
)
->
updateOrInsert
(
[
'name'
=>
$item
[
"name"
],
'symbol'
=>
$item
[
"symbol"
]],
[
'rate'
=>
$item
[
"quote"
][
"EUR"
][
"price"
]]
);
}
DB
::
commit
();
}
}
app/Http/Controllers/Controller.php
View file @
bb696f31
...
...
@@ -6,8 +6,27 @@ use Illuminate\Foundation\Bus\DispatchesJobs;
use
Illuminate\Routing\Controller
as
BaseController
;
use
Illuminate\Foundation\Validation\ValidatesRequests
;
use
Illuminate\Foundation\Auth\Access\AuthorizesRequests
;
use
Illuminate\Support\Facades\DB
;
class
Controller
extends
BaseController
{
use
AuthorizesRequests
,
DispatchesJobs
,
ValidatesRequests
;
}
class
CryptoController
extends
Controller
{
public
function
convert
(
$convertFrom
,
$convertFromValue
,
$convertTo
)
{
$dbCryptoTable
=
'crypto'
;
$convertFromRate
=
DB
::
table
(
$dbCryptoTable
)
->
where
(
'symbol'
,
$convertFrom
)
->
value
(
'rate'
);
$convertToRate
=
DB
::
table
(
$dbCryptoTable
)
->
where
(
'symbol'
,
$convertTo
)
->
value
(
'rate'
);
if
(
$convertFromRate
&&
$convertToRate
)
{
$converted
=
(
$convertFromRate
*
$convertFromValue
)
/
$convertToRate
;
return
$converted
;
}
else
{
return
NULL
;
}
}
}
\ No newline at end of file
database/migrations/2019_05_03_230115_create_crypto_table.php
0 → 100644
View file @
bb696f31
<?php
use
Illuminate\Support\Facades\Schema
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Database\Migrations\Migration
;
class
CreateCryptoTable
extends
Migration
{
/**
* Run the migrations.
*
* @return void
*/
public
function
up
()
{
Schema
::
create
(
'crypto'
,
function
(
Blueprint
$table
)
{
$table
->
bigIncrements
(
'id'
);
$table
->
string
(
'symbol'
,
100
);
$table
->
string
(
'name'
,
100
);
$table
->
double
(
'rate'
);
$table
->
timestamp
(
'updated_at'
);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public
function
down
()
{
Schema
::
dropIfExists
(
'crypto'
);
}
}
vendor/composer/autoload_classmap.php
View file @
bb696f31
...
...
@@ -7,6 +7,7 @@ $baseDir = dirname($vendorDir);
return
array
(
'App\\Admin'
=>
$baseDir
.
'/app/Admin.php'
,
'App\\Console\\Commands\\updatecrypto'
=>
$baseDir
.
'/app/Console/Commands/updatecrypto.php'
,
'App\\Console\\Kernel'
=>
$baseDir
.
'/app/Console/Kernel.php'
,
'App\\CurrencyListing'
=>
$baseDir
.
'/app/CurrencyListing.php'
,
'App\\Exceptions\\Handler'
=>
$baseDir
.
'/app/Exceptions/Handler.php'
,
...
...
@@ -16,6 +17,7 @@ return array(
'App\\Http\\Controllers\\Auth\\ResetPasswordController'
=>
$baseDir
.
'/app/Http/Controllers/Auth/ResetPasswordController.php'
,
'App\\Http\\Controllers\\Auth\\VerificationController'
=>
$baseDir
.
'/app/Http/Controllers/Auth/VerificationController.php'
,
'App\\Http\\Controllers\\Controller'
=>
$baseDir
.
'/app/Http/Controllers/Controller.php'
,
'App\\Http\\Controllers\\CryptoController'
=>
$baseDir
.
'/app/Http/Controllers/Controller.php'
,
'App\\Http\\Controllers\\HomeController'
=>
$baseDir
.
'/app/Http/Controllers/HomeController.php'
,
'App\\Http\\Controllers\\NewsletterController'
=>
$baseDir
.
'/app/Http/Controllers/NewsLetterController.php'
,
'App\\Http\\Controllers\\SendEmailController'
=>
$baseDir
.
'/app/Http/Controllers/SendEmailController.php'
,
...
...
vendor/composer/autoload_static.php
View file @
bb696f31
...
...
@@ -413,6 +413,7 @@ class ComposerStaticInitaaf7a2d0aa0540e4f74d52dc30d67caa
public
static
$classMap
=
array
(
'App\\Admin'
=>
__DIR__
.
'/../..'
.
'/app/Admin.php'
,
'App\\Console\\Commands\\updatecrypto'
=>
__DIR__
.
'/../..'
.
'/app/Console/Commands/updatecrypto.php'
,
'App\\Console\\Kernel'
=>
__DIR__
.
'/../..'
.
'/app/Console/Kernel.php'
,
'App\\CurrencyListing'
=>
__DIR__
.
'/../..'
.
'/app/CurrencyListing.php'
,
'App\\Exceptions\\Handler'
=>
__DIR__
.
'/../..'
.
'/app/Exceptions/Handler.php'
,
...
...
@@ -422,6 +423,7 @@ class ComposerStaticInitaaf7a2d0aa0540e4f74d52dc30d67caa
'App\\Http\\Controllers\\Auth\\ResetPasswordController'
=>
__DIR__
.
'/../..'
.
'/app/Http/Controllers/Auth/ResetPasswordController.php'
,
'App\\Http\\Controllers\\Auth\\VerificationController'
=>
__DIR__
.
'/../..'
.
'/app/Http/Controllers/Auth/VerificationController.php'
,
'App\\Http\\Controllers\\Controller'
=>
__DIR__
.
'/../..'
.
'/app/Http/Controllers/Controller.php'
,
'App\\Http\\Controllers\\CryptoController'
=>
__DIR__
.
'/../..'
.
'/app/Http/Controllers/Controller.php'
,
'App\\Http\\Controllers\\HomeController'
=>
__DIR__
.
'/../..'
.
'/app/Http/Controllers/HomeController.php'
,
'App\\Http\\Controllers\\NewsletterController'
=>
__DIR__
.
'/../..'
.
'/app/Http/Controllers/NewsLetterController.php'
,
'App\\Http\\Controllers\\SendEmailController'
=>
__DIR__
.
'/../..'
.
'/app/Http/Controllers/SendEmailController.php'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment