myfit added

This commit is contained in:
dev-chiefworks
2023-02-18 18:03:38 -05:00
parent 8f7546b614
commit 5f6877e912
10 changed files with 337 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
<?php
$myfile = fopen("../../writable/myfit_session.txt", "r");
$session_token = fgets($myfile);
$member_id = fgets($myfile);
$guid = fgets($myfile);
fclose($myfile);
// Find a randomDate between $start_date and $end_date
function randomDate($start_date, $end_date)
{
// Convert to timetamps
$min = strtotime($start_date);
$max = strtotime($end_date);
// Generate random number using above bounds
$val = rand($min, $max);
// Convert back to desired date format
return date('Y-m-d H:i:s', $val);
}
function randomDateInRange(DateTime $start, DateTime $end) {
$randomTimestamp = mt_rand($start->getTimestamp(), $end->getTimestamp());
$randomDate = new DateTime();
$randomDate->setTimestamp($randomTimestamp);
return $randomDate;
}
+49
View File
@@ -0,0 +1,49 @@
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<title>myFit API Test POINT</title>
</head>
<body>
<h1>myFit Api Tests!</h1>
<?php
$dm ="http://".$_SERVER['HTTP_HOST']."/myfit/";
$tArr =[
['login','What are you for really *******'],
['tracking_weight','What are you for really *******'],
['tracking_blood_pressure','What are you for really *******'],
['tracking_history','This is a sample call for tracking history']
];
$i=0;
echo "<table class='table table-striped'>";
foreach($tArr as $rr){
$i++;
$urlS = $dm.$rr[0].".php";
echo "<tr><td style='width: 20px'>$i</td><td style='width: 120px'><a href='".$urlS ."' target='BLANK'>".$urlS ."</a></td><td>".$rr[1]."</td></tr>";
}
echo "</table>";
//foreach ($_SERVER as $parm => $value) echo "$parm = '$value'\n";
?>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<!-- Option 2: Separate Popper and Bootstrap JS -->
<!--
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
-->
</body>
</html>
+31
View File
@@ -0,0 +1,31 @@
<?php
include 'myfit_class.php';
$myfit_class = new myfit_class();
// $email = 'ameye@chiefsoft.com';
$email = 'ses66181+merms8455@gmail.com';
$email = 'ses66181+merms6214@gmail.com';
$data['username'] = $email;
$data['password'] = 'mermsemr';
$data['loc'] = "38.101.241.200";
$data['sessionid'] = rand(10000,99999)."A".rand(10000,99999); // dummy for a start
$out = array();
$ret = $myfit_class->myfit_api("login",$data,$out);
if ($out['session_token'] != ''){
echo 'Save the session for other use - you will need it';
$myfile = fopen("../../writable/myfit_session.txt", "w") or die("Unable to open file!");
fwrite($myfile, $out['session_token']);
fwrite($myfile, "\n");
fwrite($myfile, $out['member_id']);
fwrite($myfile, "\n");
fwrite($myfile, $out['guid']);
fclose($myfile);
}
?>
+147
View File
@@ -0,0 +1,147 @@
<?php
include_once('CONFIGURE.php');
class myfit_class{
public $REACT_APP_AUX_ENDPOINT = "https://devapi.mermsemr.com/en/desktop/api/v2/myfit";
public $REACT_APP_USERS_ENDPOINT = "https://devapi.mermsemr.com/en/desktop/api/v2/myfituser";
function __construct() {
}
public function myfit_api($urlPath,$in, &$out = array()) {
$ret = 0;
// $urlPath = $this->baseUrlPath($in);
$local_url = $this->REACT_APP_USERS_ENDPOINT;
// $local_url = $this->REACT_APP_AUX_ENDPOINT;
$url = $local_url ."/".$urlPath;
$data = $in;
$content = json_encode($data);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type" => "application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($status != 200) {
echo ("Error: call to URL $url failed with status $status, response $json_response, | curl_error " . curl_error($curl) . ", | curl_errno " . curl_errno($curl));
}
curl_close($curl);
$response = json_decode($json_response, true);
$this->showResult($url, $in, $response);
$out = $response;
return $response;
}
public function myfit_get_api($urlPath,$in, &$out = array()) {
$ret = 0;
// $urlPath = $this->baseUrlPath($in);
$local_url = $this->REACT_APP_USERS_ENDPOINT;
// $local_url = $this->REACT_APP_AUX_ENDPOINT;
$url = $local_url ."/".$urlPath;
$data = $in;
$content = json_encode($data);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type" => "application/json"));
//curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($status != 200) {
echo ("Error: call to URL $url failed with status $status, response $json_response, | curl_error " . curl_error($curl) . ", | curl_errno " . curl_errno($curl));
}
curl_close($curl);
$response = json_decode($json_response, true);
$this->showResult($url, $in, $response);
$out = $response;
return $response;
}
public function showResult($url, $in,$out){
$inHeaders = array_keys($in);
echo "<hr />API INPUT <table>
<tr><td colspan='3'>".$url."</td></tr>
</table>";
var_dump($inHeaders);
echo "<hr />";
//$response['result_list']
if ( isset($out['result_list']) && is_array($out['result_list']) && count($out['result_list']) > 0 ){
$arr = $out['result_list'];
$myHeaders = array_keys($arr[0]);
var_dump( $myHeaders);
$tableHead = '<tr>';
foreach ($myHeaders as $hd){
$tableHead .= "<th>".$hd."</th>";
}
$tableHead .= '</tr>';
$tableBody = '';
foreach ($arr as $item) {
$tableBody .= '<tr>';
$backColor ='white';
foreach ($myHeaders as $hd){
$backColor = ($backColor=='aliceblue')?'white': 'aliceblue';
$tableBody .= "<td style='background-color:$backColor'>".$item[$hd]."</td>";
}
$tableBody .= '</tr>';
}
echo "<table>".$tableHead.$tableBody."</table>";
}
}
public function showOutResult($out){
//$response['result_list']
if ( isset($out['tracking_data']) && is_array($out['tracking_data']) && count($out['tracking_data']) > 0 ){
$arr = $out['tracking_data'];
$myHeaders = array_keys($arr[0]);
var_dump( $myHeaders);
$tableHead = '<tr style=\"background-color:lightblue;\">';
foreach ($myHeaders as $hd){
$tableHead .= "<th>".$hd."</th>";
}
$tableHead .= '</tr>';
$tableBody = '';
foreach ($arr as $item) {
$tableBody .= '<tr>';
$backColor ='white';
foreach ($myHeaders as $hd){
$backColor = ($backColor=='aliceblue')?'white': 'aliceblue';
$tableBody .= "<td style='background-color:$backColor'>".$item[$hd]."</td>";
}
$tableBody .= '</tr>';
}
echo "<table>".$tableHead.$tableBody."</table>";
}
}
}
?>
+13
View File
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<title>myFit API Test POINT</title>
</head>
<body>
+25
View File
@@ -0,0 +1,25 @@
<?php
include_once 'CONFIGURE.php';
include 'myfit_class.php';
$myfit_class = new myfit_class();
$data['member_id'] = $member_id;
$data['session_token'] = $session_token;
$data['member_uuid'] = $guid;
$data['loc'] = "38.101.241.200";
$data['sessionid'] = $session_token;
$data['code'] = 'BLPR';
$data['unit'] = 'mmHg';
$data['val1'] = 115 + rand(0,12);
$data['val2'] = 60 + rand(0,12);
$data['val3'] = 80 + rand(0,12);
//$data['event_time'] = '2023-02-18 03:37';
//$data['event_time'] = randomDateInRange(strtotime('2023-02-01 00:29'), strtotime('2023-02-28 22:29'));
$data['event_time'] = randomDate('2023-02-01 00:29', '2023-02-28 22:29');
$out = array();
var_dump($data);
$ret = $myfit_class->myfit_api("tracking",$data,$out);
+20
View File
@@ -0,0 +1,20 @@
<?php
include 'phead.php';
include_once 'CONFIGURE.php';
include 'myfit_class.php';
$myfit_class = new myfit_class();
$data['member_id'] = $member_id;
$data['session_token'] = $session_token;
$data['member_uuid'] = $guid;
$data['loc'] = "38.101.241.200";
$data['sessionid'] = $session_token;
$data['code'] = 'WEIGT';
$out = array();
$ret = $myfit_class->myfit_get_api("trackinghx",$data,$out);
$myfit_class->showOutResult($out);
echo highlight_string(file_get_contents(__FILE__));
+21
View File
@@ -0,0 +1,21 @@
<?php
include_once 'CONFIGURE.php';
include 'myfit_class.php';
$myfit_class = new myfit_class();
$data['member_id'] = $member_id;
$data['session_token'] = $session_token;
$data['member_uuid'] = $guid;
$data['loc'] = "38.101.241.200";
$data['sessionid'] = $session_token;
$data['code'] = 'WEIGT';
$data['unit'] = 'KG';
$data['val1'] = 135 + rand(0,12);
//$data['event_time'] = '2023-02-18 03:37';
//$data['event_time'] = randomDateInRange(strtotime('2023-02-01 00:29'), strtotime('2023-02-28 22:29'));
$data['event_time'] = randomDate('2023-02-01 00:29', '2023-02-28 22:29');
$out = array();
$ret = $myfit_class->myfit_api("tracking",$data,$out);
+1
View File
@@ -0,0 +1 @@
<?php
+3
View File
@@ -0,0 +1,3 @@
58914299424016077730608274314642903631264178237880128136124353930296954921392288419326961050983
16
d274dcd9-7f5d-4919-b284-2a0cf137302e