Skip to content

Commit

Permalink
add additional comment param
Browse files Browse the repository at this point in the history
  • Loading branch information
fershad committed Jan 23, 2024
1 parent 7657e6a commit 1254eed
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/hosting-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { getApiRequestHeaders } from "./helpers";
* @param {string|array} domain - The domain to check, or an array of domains to be checked.
*/

function check(domain) {
function check(domain, comment) {
// is it a single domain or an array of them?
if (typeof domain === "string") {
return checkAgainstAPI(domain);
return checkAgainstAPI(domain, comment);
} else {
return checkDomainsAgainstAPI(domain);
return checkDomainsAgainstAPI(domain, comment);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/hosting-api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe("hostingAPI", () => {
url: "google.com",
green: true,
});
const res = await hosting.check("google.com", requestHeaderComment);
const res = await hosting.check("google.com", null, requestHeaderComment);
expect(res).toEqual(true);
});
it("sets the correct user agent header", async () => {
Expand All @@ -30,7 +30,7 @@ describe("hostingAPI", () => {
green: true,
};
});
const res = await hosting.check("google.com", requestHeaderComment);
const res = await hosting.check("google.com", null, requestHeaderComment);
expect(userAgent).toEqual("co2js/1.2.34 Test Runner");
});
});
Expand Down
7 changes: 4 additions & 3 deletions src/hosting-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,20 @@ async function getBody(url, comment) {
* Check if a domain is hosted by a green web host.
* @param {string|array} domain - The domain to check, or an array of domains to be checked.
* @param {object} db - Optional. A database object to use for lookups.
* @param {string} comment - Optional. The app, site, or organisation that is making the request.
* @returns {boolean|array} - A boolean if a string was provided, or an array of booleans if an array of domains was provided.
*/

function check(domain, db) {
function check(domain, db, comment) {
if (db) {
return hostingJSON.check(domain, db);
}

// is it a single domain or an array of them?
if (typeof domain === "string") {
return checkAgainstAPI(domain);
return checkAgainstAPI(domain, comment);
} else {
return checkDomainsAgainstAPI(domain);
return checkDomainsAgainstAPI(domain, comment);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/hosting.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import hostingAPI from "./hosting-api.js";
* @param {string|array} domain - The domain to check, or an array of domains to be checked.
* @returns {boolean|array} - A boolean if a string was provided, or an array of booleans if an array of domains was provided.
*/
function check(domain) {
return hostingAPI.check(domain);
function check(domain, comment) {
return hostingAPI.check(domain, comment);
}

export default {
Expand Down
2 changes: 1 addition & 1 deletion src/hosting.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe("hosting", () => {
expect(res).toEqual(true);
});
it("sets the correct user agent header", async () => {
await hosting.check("google.com", requestHeaderComment);
await hosting.check("google.com", null, requestHeaderComment);
expect(httpsGetSpy).toHaveBeenCalledTimes(1);
expect(httpsGetSpy).toHaveBeenLastCalledWith(
expect.any(String),
Expand Down

0 comments on commit 1254eed

Please sign in to comment.