Skip to content

Instantly share code, notes, and snippets.

@basith374
Created July 5, 2020 18:00
Show Gist options
  • Save basith374/97bfff0694d735b943fe3f8cef81ed22 to your computer and use it in GitHub Desktop.
Save basith374/97bfff0694d735b943fe3f8cef81ed22 to your computer and use it in GitHub Desktop.
ebay search
<?php
if(isset($_GET['productid'])) {
$ch = curl_init('http://ebay-api.thedcevents.com/api/findproduct/' . $_GET['productid']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
// $result = '{"title":"foo","url":"bar","img":"baz","thumbnails":["asd","qwe"]}';
$result = json_decode($output);
if($result->status == 'SUCCESS') {
$item = $result->data;
} else {
$error = true;
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Ebay Search</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<style>
.search {
padding: 2rem 0;
}
.search input {
width: 100%;
}
.container {
padding-top: 5rem;
}
</style>
</head>
<body>
<div class="container">
<div class="navbar navbar-default">
<div class="navbar-header">
<a class="navbar-brand" href="#">Ebay Product Search</a>
</div>
</div>
<div class="search">
<form>
<input type="text" placeholder="Search Ebay" name="productid" onkeydown="onkeydown()"/>
</form>
</div>
<div>
<?php if(isset($error)) { ?>
<div>Not found</div>
<?php } ?>
<?php if(isset($item)) { ?>
<div class="panel panel-default">
<div class="panel-body">
<div><?php echo $item->title ?></div>
<div><?php echo $item->url ?></div>
<div><?php echo $item->img ?></div>
<div>
<?php foreach($item->thumbnails as $thumb) { ?>
<img src="<?php echo $thumb; ?>" />
<?php } ?>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
<script>
function onkeydown(e) {
if(e.keyCode === 13) {
document.querySelector('form').submit()
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment