-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[gem cdnjs appveyor clojars] refactor clojars, establish BaseJsonServ…
…ice (#1702) * refactor clojars integration * DRY up services that request data from JSON endpoints
- Loading branch information
Showing
8 changed files
with
91 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
|
||
const { BaseJsonService } = require('../base'); | ||
const { NotFound } = require('../errors'); | ||
const { version: versionColor } = require('../../lib/color-formatters'); | ||
|
||
module.exports = class Clojars extends BaseJsonService { | ||
async handle({clojar}) { | ||
const apiUrl = 'https://clojars.org/' + clojar + '/latest-version.json'; | ||
const json = await this._requestJson(apiUrl); | ||
|
||
if (Object.keys(json).length === 0) { | ||
/* Note the 'not found' response from clojars is: | ||
status code = 200, body = {} */ | ||
throw new NotFound(); | ||
} | ||
|
||
return { | ||
message: "[" + clojar + " \"" + json.version + "\"]", | ||
color: versionColor(json.version) | ||
}; | ||
} | ||
|
||
// Metadata | ||
static get defaultBadgeData() { | ||
return { label: 'clojars' }; | ||
} | ||
|
||
static get category() { | ||
return 'version'; | ||
} | ||
|
||
static get url() { | ||
return { | ||
base: 'clojars/v', | ||
format: '(.+)', | ||
capture: ['clojar'] | ||
}; | ||
} | ||
|
||
static get examples() { | ||
return [ | ||
{ previewUrl: 'prismic' } | ||
]; | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters