Skip to content

Commit 0682ee2

Browse files
committed
Initial steps for integrations documentation
1 parent bf519d1 commit 0682ee2

File tree

4 files changed

+91
-65
lines changed

4 files changed

+91
-65
lines changed

dist/woof.js

+7-23
Original file line numberDiff line numberDiff line change
@@ -2164,29 +2164,13 @@ Woof.prototype.pow = function (a, b) {
21642164
return Math.pow(a, b);
21652165
};
21662166

2167-
//IN THE MIDDLE OF ADDING CURRENCY FUNCTIONS
2168-
// const getData = (url, callback) => {
2169-
// fetch(url,{mode:'cors',header:{'Access-Control-Allow-Origin':'*'}}).then(result => {
2170-
// result.json().then(data => {
2171-
// callback(data)
2172-
// })
2173-
// })
2174-
// }
2175-
2176-
// function func(data){
2177-
// return data.rates;
2178-
// }
2179-
2180-
// Woof.prototype.currencyConversionRate = function(from, to) {
2181-
// // httpGetAsync("http://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b1b15e88fa797225412429c1c50c122a1", "");
2182-
// var rate = undefined;
2183-
// var url = "http://api.fixer.io/latest?base=" + from;
2184-
// getData(url, data => {
2185-
// rate = data;
2186-
// console.log(rate);
2187-
// })
2188-
// return rate;
2189-
// };
2167+
var getData = function getData(url, callback) {
2168+
fetch(url, { mode: 'cors', header: { 'Access-Control-Allow-Origin': '*' } }).then(function (result) {
2169+
result.json().then(function (data) {
2170+
callback(data);
2171+
});
2172+
});
2173+
};
21902174

21912175
// find the woof.js script tag in the page
21922176
var currentScript = document.currentScript || Array.prototype.slice.call(document.getElementsByTagName('script')).find(function (s) {

docs/docs.css

+13-5
Original file line numberDiff line numberDiff line change
@@ -401,14 +401,22 @@ h4 {
401401
background-color: #0BCC9E;
402402
width:90% !important;
403403
}
404-
405-
/*CURRENCY FUNCTIONS STILL IN THE WORKS*/
406-
/*#Currency{
404+
#Sunrise{
405+
background-color: #FFE53F;
406+
width:90% !important;
407+
}
408+
#Get{
409+
background-color: #FF9D3F;
410+
width:90% !important;
411+
}
412+
#Currency{
407413
background-color: #00DA1F;
408414
width:90% !important;
409-
}*/
415+
}
410416

411-
/*#Currency,*/
417+
#Currency,
418+
#Get,
419+
#Sunrise,
412420
#Local,
413421
#Firebase {
414422
height: 8%;

docs/index.html

+64-14
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,70 @@
126126
tags:"local storage high score"
127127
}
128128
],
129-
//CURRENCY FUNCTIONS STILL IN THE WORKS
130-
// "Currency Conversion":[
131-
// {
132-
// integrationDescription:"Use the corrency conversion functions to convert with current conversion rates.",
133-
// html:"<a href='https://www.easymarkets.com/int/learn-centre/discover-trading/currency-acronyms-and-abbreviations/'>Click here for a list of currency abbreviations</a>",
134-
// integrationDescriptionClass:"alert-info"
135-
// },
136-
// {html:"<hr style=\"height:7px;border:none;color:#e0e0e0;background-color:#e0e0e0;\"/>"},
137-
// {
138-
// description:"Get the current conversion rate.",
139-
// code:'//From USD to EUR\ncurrencyConversionRate("USD","EUR")\n//From GBP to USD\ncurrencyConversionRate("GBP","USD")',
140-
// tags:"currency conversion"
141-
// }
142-
// ]
129+
"Get Requests": [
130+
{
131+
integrationDescription:"Use the getData() function to pull data from various APIs. You can see specific examples for several APIs in the Integrations section of the WoofJS documentation.",
132+
integrationDescriptionClass:"alert-info"
133+
},
134+
{html:"<hr style=\"height:7px;border:none;color:#e0e0e0;background-color:#e0e0e0;\"/>"},
135+
{
136+
description:"getData() works by taking an url and a function to do with the returned data. This is an example using the Sunrise-Sunset API.",
137+
code:'//First set up temporary text that will be replaced\nvar temp = new Text({\n text: "...", \n size: 60, \n color: "white", \nfontFamily: "arial",\n})\n//Then set your variables for the request\nvar lat = 40.7128\nvar lng = -74.0059 \n//Then set the url for your request\nvar url = "https://api.sunrise-sunset.org/json?lat=" + lat + "&lng=" + lng\n//Finaly call the getData() function\ngetData(url, data => {\n //Replace the temporary text\n temp.text = data.results.sunset\n}) ',
138+
tags:"get request json http"
139+
},
140+
{
141+
integrationDescription:"The data returned will in JSON format so it will need to be parsed to get the proper value you are looking for.",
142+
html:"<a target='_blank' href='https://joebeachjoebeach.github.io/json-path-finder/'>Use this JSON Path Finder to help you find the correct path for the data you are looking to retreive.</a>",
143+
integrationDescriptionClass:"alert-info"
144+
},
145+
],
146+
"Currency Conversion":[
147+
{
148+
integrationDescription:"Use the Currency Conversion API to get current conversion rates.",
149+
html:"<a target='_blank' href='http://fixer.io/'>Click here for the Currency Conversion API documentation</a>",
150+
integrationDescriptionClass:"alert-info"
151+
},
152+
{html:"<hr style=\"height:7px;border:none;color:#e0e0e0;background-color:#e0e0e0;\"/>"},
153+
{
154+
description:"Here is a walk through of a program shows how much $5 is currently worth in EUR.",
155+
code:'//First set up temporary text that will be replaced\nvar temp = new Text({\n text: "...", \n size: 60, \n color: "white", \n fontFamily: "arial",\n})\n//Then set your variables for the request\nvar base = "USD"\n//Then set the url for your request\nvar url = "http://api.fixer.io/latest?base=" + base\n//Finaly call the getData() function\ngetData(url, data => {\n //Replace the temporary text with the converted amoung\n temp.text = Math.round( 5*data.rates.EUR * 100) /100 + " EUR"\n}) ',
156+
tags:"currency conversion"
157+
},
158+
{
159+
description:"Here is a walk through of a program shows how much 10 GBP is currently worth in USD.",
160+
code:'//First set up temporary text that will be replaced\nvar temp = new Text({\n text: "...", \n size: 60, \n color: "white", \n fontFamily: "arial",\n})\n//Then set your variables for the request\nvar base = "GBP"\n//Then set the url for your request\nvar url = "http://api.fixer.io/latest?base=" + base\n//Finaly call the getData() function\ngetData(url, data => {\n //Replace the temporary text with the converted amoung\n temp.text = Math.round( 10*data.rates.USD * 100) /100 + " USD"\n}) ',
161+
tags:"currency conversion"
162+
},
163+
{html:"<hr style=\"height:7px;border:none;color:#e0e0e0;background-color:#e0e0e0;\"/>"},
164+
{
165+
integrationDescription:"For other currencies visit the API's documentation for help.",
166+
html:"<a target='_blank' href='http://fixer.io/'>Click here for the Currency Conversion API documentation</a>",
167+
integrationDescriptionClass:"alert-info"
168+
},
169+
],
170+
"Sunrise and Sunset Data":[
171+
{
172+
integrationDescription:"Use the Sunrise-Sunset API to get data about upcoming or past sunrises and sunsets.",
173+
html:"<a target='_blank' href='https://sunrise-sunset.org/api'>Click here for Sunrise-Sunset API documentation</a><br><a target='_blank' href='http://www.latlong.net/'>Click here to find latitude and longitude values</a>",
174+
integrationDescriptionClass:"alert-info"
175+
},
176+
{html:"<hr style=\"height:7px;border:none;color:#e0e0e0;background-color:#e0e0e0;\"/>"},
177+
{
178+
description:"Here is a walk through of how to display today's sunrise time in NYC:",
179+
code:'//First set up temporary text that will be replaced\nvar temp = new Text({\n text: "...", \n size: 60, \n color: "white", \nfontFamily: "arial",\n})\n//Then set your variables for the request\nvar lat = 40.7128\nvar lng = -74.0059 \n//Then set the url for your request\nvar url = "https://api.sunrise-sunset.org/json?lat=" + lat + "&lng=" + lng\n//Finaly call the getData() function\ngetData(url, data => {\n //Replace the temporary text\n temp.text = data.results.sunset\n}) ',
180+
tags:"sunrise sunrise url"
181+
},
182+
{
183+
description:"Here is a walk through of how to display today's sunset time in NYC:",
184+
code:'//First set up temporary text that will be replaced\nvar temp = new Text({\n text: "...", \n size: 60, \n color: "white", \nfontFamily: "arial",\n})\n//Then set your variables for the request\nvar lat = 40.7128\nvar lng = -74.0059 \n//Then set the url for your request\nvar url = "https://api.sunrise-sunset.org/json?lat=" + lat + "&lng=" + lng\n//Finaly call the getData() function\ngetData(url, data => {\n //Replace the temporary text\n temp.text = data.results.sunset\n}) ',
185+
tags:"sunrise sunset url"
186+
},
187+
{
188+
description:"There is even more you can do with the Sunrise-Sunset API:",
189+
code:'//Instead of data.results.sunrise or data.results.sunset, try:\ndata.results.solar_noon\ndata.results.day_length\ndata.results.civil_twilight_begin\ndata.results.civil_twilight_end\ndata.results.nautical_twilight_begin\ndata.results.nautical_twilight_end\nata.results.astronomical_twilight_begin\nata.results.astronomical_twilight_begin',
190+
tags:"sunrise sunset url"
191+
}
192+
]
143193

144194
},
145195
"Sprites & Backgrounds": {

src/woof.es6.js

+7-23
Original file line numberDiff line numberDiff line change
@@ -1627,29 +1627,13 @@ Woof.prototype.pow = function(a,b) {
16271627
return Math.pow(a,b);
16281628
};
16291629

1630-
//IN THE MIDDLE OF ADDING CURRENCY FUNCTIONS
1631-
// const getData = (url, callback) => {
1632-
// fetch(url,{mode:'cors',header:{'Access-Control-Allow-Origin':'*'}}).then(result => {
1633-
// result.json().then(data => {
1634-
// callback(data)
1635-
// })
1636-
// })
1637-
// }
1638-
1639-
// function func(data){
1640-
// return data.rates;
1641-
// }
1642-
1643-
// Woof.prototype.currencyConversionRate = function(from, to) {
1644-
// // httpGetAsync("http://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b1b15e88fa797225412429c1c50c122a1", "");
1645-
// var rate = undefined;
1646-
// var url = "http://api.fixer.io/latest?base=" + from;
1647-
// getData(url, data => {
1648-
// rate = data;
1649-
// console.log(rate);
1650-
// })
1651-
// return rate;
1652-
// };
1630+
const getData = (url, callback) => {
1631+
fetch(url,{mode:'cors',header:{'Access-Control-Allow-Origin':'*'}}).then(result => {
1632+
result.json().then(data => {
1633+
callback(data)
1634+
})
1635+
})
1636+
}
16531637

16541638
// find the woof.js script tag in the page
16551639
var currentScript = document.currentScript || Array.prototype.slice.call(document.getElementsByTagName('script')).find(s => s.src.includes('woof.js'))

0 commit comments

Comments
 (0)