Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Commit

Permalink
add material
Browse files Browse the repository at this point in the history
  • Loading branch information
dhvanipa committed Apr 29, 2020
0 parents commit 8a8378e
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# API Workshop Material
18 changes: 18 additions & 0 deletions app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
body {
background: white;
color: #323232;
font-weight: 300;
font-family: Helevtica neue, robot;
}

.button {
background-color: #4caf50; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: pointer;
}
57 changes: 57 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
fetch ('https://api.github.com/users/dhvani35729')
.then (response => response.json ())
.then (data => {
console.log (data);
var greetingNode = document.getElementById ('greeting');
greetingNode.innerHTML += ' ' + data.login + '!';
var bioNode = document.getElementById ('userBio');
bioNode.innerHTML = data.bio;
var userImageNode = document.getElementById ('userImg');
userImageNode.src = data.avatar_url;
userImageNode.width = 200;
});

function loadUsers () {
console.log ('Loading users..');
fetch ('https://reqres.in/api/users')
.then (res => res.json ())
.then (data => {
console.log (data);
var userTable = document.getElementById ('userTable');

data.data.forEach (user => {
console.log (user.email);
var newRow = userTable.insertRow ();
var colId = document.createElement ('th');
var colName = document.createElement ('th');
var colEmail = document.createElement ('th');
let textId = document.createTextNode (user.id);
let textName = document.createTextNode (user.first_name);
let textEmail = document.createTextNode (user.email);
colId.appendChild (textId);
colName.appendChild (textName);
colEmail.appendChild (textEmail);
newRow.appendChild (colId);
newRow.appendChild (colName);
newRow.appendChild (colEmail);
});
});
}

function sendSwit () {
console.log ('Sending message to Swit');
var inputText = document.getElementById ('message').value;
fetch ('https://hook.swit.io/chat/200326205355708CTEB/ntq1pBDDQqf3ne3NgZFL', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify ({
text: inputText,
}),
})
.then (res => res.json ())
.then (data => console.log (data));

return false;
}
18 changes: 18 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# importing the requests library
import requests
import json
from threading import Timer


def askData():
Timer(1.0, askData).start()

API_ENDPOINT = "https://hook.swit.io/chat/200328231505006C9sA/FihS4PXQOpHrBcc5lWm7"

data = {'text':"I want data"}

r = requests.post(url = API_ENDPOINT, json=data)

print(r)

askData()
45 changes: 45 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html>

<head>
<link rel="stylesheet" href="app.css">
</head>

<body>

<h2 id="greeting">
Hey there,
</h2>
<p id="userBio">
</p>
<img id="userImg">

<hr />
<buttton class="button" onclick="loadUsers()">Load Users</buttton>

<table id="userTable">
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>emal</th>
</tr>
</thead>
<tbody>

</tbody>
</table>

<hr />
<form onsubmit="return sendSwit()">
<label>Message:</label><br>
<input type="text" id="message" value=""><br>
<input type="submit" value="Submit">
</form>


</body>

<script src="app.js"></script>

</html>
15 changes: 15 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const express = require ('express');
const app = express ();

const port = 3000;

app.get ('/', (req, res) => {
// res.send ('Hello World!');
res.status (200).json ({
message: 'It works!',
});
});

app.listen (port, () =>
console.log ('Starting server on http://localhost:' + port)
);

0 comments on commit 8a8378e

Please sign in to comment.