Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
store-locator
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ajay Barthwal
store-locator
Commits
ff68cd98
Commit
ff68cd98
authored
Jul 16, 2019
by
Arpit Jain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented condition if key file does not exist then create file and update key
parent
b8ea506e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
28 deletions
+64
-28
Apitraits.php
application/app/Traits/Apitraits.php
+64
-28
No files found.
application/app/Traits/Apitraits.php
View file @
ff68cd98
...
...
@@ -6,47 +6,83 @@ use Illuminate\Support\Facades\Storage;
Trait
Apitraits
{
private
function
createFileAndPutApiKey
(){
Storage
::
disk
(
'public'
)
->
put
(
'key/apikey.dba'
,
''
);
$api_key_url
=
config
(
'app.api_key_url'
);
$client
=
new
Client
();
$response
=
$client
->
request
(
'POST'
,
$api_key_url
,[
'form_params'
=>
[
'client_id'
=>
1
,
'client_secret'
=>
'DJXCYjyCRDt5IHMbiKYbiKqjVWdeNKo1VixHYQaL'
]
]);
$body
=
$response
->
getBody
()
->
getContents
();
$keyDetailAPIdata
=
json_decode
(
$body
,
true
);
$updateKey
=
Storage
::
disk
(
'public'
)
->
put
(
'key/apikey.dba'
,
$keyDetailAPIdata
[
'access_token'
]);
if
(
$updateKey
==
true
){
$api_key
=
Storage
::
get
(
'key/apikey.dba'
);
}
else
{
return
false
;
}
return
$api_key
;
}
public
function
getAPiKey
(){
$modifiedtime
=
Storage
::
lastModified
(
'key/apikey.dba'
);
$time
=
date
(
'd-m-Y'
,
$modifiedtime
);
$expieryDate
=
date
(
'd-m-Y'
,
strtotime
(
$time
.
' + 15 days'
));
$expieryUpdationDate
=
date
(
'd-m-Y'
,
strtotime
(
$expieryDate
.
' - 1 days'
));
$currentDate
=
date
(
'd-m-Y'
);
$file
=
Storage
::
disk
(
'public'
)
->
exists
(
'key/apikey.dba'
);
if
(
strtotime
(
$currentDate
)
==
strtotime
(
$expieryUpdationDate
)){
$file
=
Storage
::
disk
(
'public'
)
->
exists
(
'key/apikey.dba'
);
if
(
$file
==
false
){
$api_key
=
$this
->
createFileAndPutApiKey
();
$api_key_url
=
config
(
'app.api_key_url'
);
}
else
{
$modifiedtime
=
Storage
::
lastModified
(
'key/apikey.dba'
);
$time
=
date
(
'd-m-Y'
,
$modifiedtime
);
$expieryDate
=
date
(
'd-m-Y'
,
strtotime
(
$time
.
' + 15 days'
));
$expieryUpdationDate
=
date
(
'd-m-Y'
,
strtotime
(
$expieryDate
.
' - 1 days'
));
$currentDate
=
date
(
'd-m-Y'
);
$client
=
new
Client
();
if
(
strtotime
(
$currentDate
)
==
strtotime
(
$expieryUpdationDate
)){
$file
=
Storage
::
disk
(
'public'
)
->
exists
(
'key/apikey.dba'
);
$response
=
$client
->
request
(
'POST'
,
$api_key_url
,[
'form_params'
=>
[
'client_id'
=>
1
,
'client_secret'
=>
'DJXCYjyCRDt5IHMbiKYbiKqjVWdeNKo1VixHYQaL'
]
]);
$api_key_url
=
config
(
'app.api_key_url'
);
$body
=
$response
->
getBody
()
->
getContents
();
$keyDetailAPIdata
=
json_decode
(
$body
,
true
);
$client
=
new
Client
();
$updateKey
=
Storage
::
disk
(
'public'
)
->
put
(
'key/apikey.dba'
,
$keyDetailAPIdata
[
'access_token'
]);
$response
=
$client
->
request
(
'POST'
,
$api_key_url
,[
'form_params'
=>
[
'client_id'
=>
1
,
'client_secret'
=>
'DJXCYjyCRDt5IHMbiKYbiKqjVWdeNKo1VixHYQaL'
]
]);
if
(
$updateKey
==
true
){
$api_key
=
Storage
::
get
(
'key/apikey.dba'
);
}
else
{
return
false
;
}
}
else
{
$file
=
Storage
::
disk
(
'public'
)
->
exists
(
'key/apikey.dba'
);
if
(
$file
==
true
){
$api_key
=
Storage
::
get
(
'key/apikey.dba'
);
$body
=
$response
->
getBody
()
->
getContents
();
$keyDetailAPIdata
=
json_decode
(
$body
,
true
);
$updateKey
=
Storage
::
disk
(
'public'
)
->
put
(
'key/apikey.dba'
,
$keyDetailAPIdata
[
'access_token'
]);
if
(
$updateKey
==
true
){
$api_key
=
Storage
::
get
(
'key/apikey.dba'
);
}
else
{
return
false
;
}
}
else
{
return
false
;
$file
=
Storage
::
disk
(
'public'
)
->
exists
(
'key/apikey.dba'
);
if
(
$file
==
true
){
$api_key
=
Storage
::
get
(
'key/apikey.dba'
);
}
else
{
return
false
;
}
}
}
return
$api_key
;
}
...
...
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