Skip to content

Commit 8f23d27

Browse files
committed
change parameter name to userAgentIdentifier
1 parent 5a6fdfb commit 8f23d27

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

src/hosting-api.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,29 @@ import { getApiRequestHeaders } from "./helpers/index.js";
55
/**
66
* Check if a string or array of domains has been provided
77
* @param {string|array} domain - The domain to check, or an array of domains to be checked.
8-
* @param {string} comment - Optional. The app, site, or organisation that is making the request.
8+
* @param {string} userAgentIdentifier - Optional. The app, site, or organisation that is making the request.
99
*/
1010

11-
function check(domain, comment) {
11+
function check(domain, userAgentIdentifier) {
1212
// is it a single domain or an array of them?
1313
if (typeof domain === "string") {
14-
return checkAgainstAPI(domain, comment);
14+
return checkAgainstAPI(domain, userAgentIdentifier);
1515
} else {
16-
return checkDomainsAgainstAPI(domain, comment);
16+
return checkDomainsAgainstAPI(domain, userAgentIdentifier);
1717
}
1818
}
1919

2020
/**
2121
* Check if a domain is hosted by a green web host by querying the Green Web Foundation API.
2222
* @param {string} domain - The domain to check.
23-
* @param {string} comment - Optional. The app, site, or organisation that is making the request.
23+
* @param {string} userAgentIdentifier - Optional. The app, site, or organisation that is making the request.
2424
* @returns {boolean} - A boolean indicating whether the domain is hosted by a green web host.
2525
*/
26-
async function checkAgainstAPI(domain, comment) {
26+
async function checkAgainstAPI(domain, userAgentIdentifier) {
2727
const req = await fetch(
2828
`https://api.thegreenwebfoundation.org/greencheck/${domain}`,
2929
{
30-
headers: getApiRequestHeaders(comment),
30+
headers: getApiRequestHeaders(userAgentIdentifier),
3131
}
3232
);
3333
const res = await req.json();
@@ -37,17 +37,17 @@ async function checkAgainstAPI(domain, comment) {
3737
/**
3838
* Check if an array of domains is hosted by a green web host by querying the Green Web Foundation API.
3939
* @param {array} domains - An array of domains to check.
40-
* @param {string} comment - Optional. The app, site, or organisation that is making the request.
40+
* @param {string} userAgentIdentifier - Optional. The app, site, or organisation that is making the request.
4141
* @returns {array} - An array of domains that are hosted by a green web host.
4242
*/
4343

44-
async function checkDomainsAgainstAPI(domains, comment) {
44+
async function checkDomainsAgainstAPI(domains, userAgentIdentifier) {
4545
try {
4646
const apiPath = "https://api.thegreenwebfoundation.org/v2/greencheckmulti";
4747
const domainsString = JSON.stringify(domains);
4848

4949
const req = await fetch(`${apiPath}/${domainsString}`, {
50-
headers: getApiRequestHeaders(comment),
50+
headers: getApiRequestHeaders(userAgentIdentifier),
5151
});
5252

5353
const allGreenCheckResults = await req.json();

src/hosting-node.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ import { getApiRequestHeaders } from "./helpers/index.js";
1818
* for parsing as JSON.
1919
*
2020
* @param {string} url
21-
* @param {string} comment - Optional. The app, site, or organisation that is making the request.
21+
* @param {string} userAgentIdentifier - Optional. The app, site, or organisation that is making the request.
2222
* @return {string}
2323
*/
24-
async function getBody(url, comment) {
24+
async function getBody(url, userAgentIdentifier) {
2525
return new Promise(function (resolve, reject) {
2626
// Do async job
2727
const req = https.get(
2828
url,
29-
{ headers: getApiRequestHeaders(comment) },
29+
{ headers: getApiRequestHeaders(userAgentIdentifier) },
3030
function (res) {
3131
if (res.statusCode < 200 || res.statusCode >= 300) {
3232
return reject(
@@ -52,34 +52,34 @@ async function getBody(url, comment) {
5252
* Check if a domain is hosted by a green web host.
5353
* @param {string|array} domain - The domain to check, or an array of domains to be checked.
5454
* @param {object} db - Optional. A database object to use for lookups.
55-
* @param {string} comment - Optional. The app, site, or organisation that is making the request.
55+
* @param {string} userAgentIdentifier - Optional. The app, site, or organisation that is making the request.
5656
* @returns {boolean|array} - A boolean if a string was provided, or an array of booleans if an array of domains was provided.
5757
*/
5858

59-
function check(domain, db, comment) {
59+
function check(domain, db, userAgentIdentifier) {
6060
if (db) {
6161
return hostingJSON.check(domain, db);
6262
}
6363

6464
// is it a single domain or an array of them?
6565
if (typeof domain === "string") {
66-
return checkAgainstAPI(domain, comment);
66+
return checkAgainstAPI(domain, userAgentIdentifier);
6767
} else {
68-
return checkDomainsAgainstAPI(domain, comment);
68+
return checkDomainsAgainstAPI(domain, userAgentIdentifier);
6969
}
7070
}
7171

7272
/**
7373
* Check if a domain is hosted by a green web host by querying the Green Web Foundation API.
7474
* @param {string} domain - The domain to check.
75-
* @param {string} comment - Optional. The app, site, or organisation that is making the request.
75+
* @param {string} userAgentIdentifier - Optional. The app, site, or organisation that is making the request.
7676
* @returns {boolean} - A boolean indicating whether the domain is hosted by a green web host.
7777
*/
78-
async function checkAgainstAPI(domain, comment) {
78+
async function checkAgainstAPI(domain, userAgentIdentifier) {
7979
const res = JSON.parse(
8080
await getBody(
8181
`https://api.thegreenwebfoundation.org/greencheck/${domain}`,
82-
comment
82+
userAgentIdentifier
8383
)
8484
);
8585
return res.green;
@@ -88,17 +88,17 @@ async function checkAgainstAPI(domain, comment) {
8888
/**
8989
* Check if an array of domains is hosted by a green web host by querying the Green Web Foundation API.
9090
* @param {array} domains - An array of domains to check.
91-
* @param {string} comment - Optional. The app, site, or organisation that is making the request.
91+
* @param {string} userAgentIdentifier - Optional. The app, site, or organisation that is making the request.
9292
* @returns {array} - An array of domains that are hosted by a green web host.
9393
*/
94-
async function checkDomainsAgainstAPI(domains, comment) {
94+
async function checkDomainsAgainstAPI(domains, userAgentIdentifier) {
9595
try {
9696
const allGreenCheckResults = JSON.parse(
9797
await getBody(
9898
`https://api.thegreenwebfoundation.org/v2/greencheckmulti/${JSON.stringify(
9999
domains
100100
)}`,
101-
comment
101+
userAgentIdentifier
102102
)
103103
);
104104
return hostingJSON.greenDomainsFromResults(allGreenCheckResults);

src/hosting.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import hostingAPI from "./hosting-api.js";
55
/**
66
* Check if a domain is hosted by a green web host.
77
* @param {string|array} domain - The domain to check, or an array of domains to be checked.
8-
* @param {string} comment - Optional. The app, site, or organisation that is making the request.
8+
* @param {string} userAgentIdentifier - Optional. The app, site, or organisation that is making the request.
99
* @returns {boolean|array} - A boolean if a string was provided, or an array of booleans if an array of domains was provided.
1010
*/
11-
function check(domain, comment) {
12-
return hostingAPI.check(domain, comment);
11+
function check(domain, userAgentIdentifier) {
12+
return hostingAPI.check(domain, userAgentIdentifier);
1313
}
1414

1515
export default {

0 commit comments

Comments
 (0)