mirror of
https://codeberg.org/keyoxide/doipjs.git
synced 2024-12-22 22:49:28 -07:00
Add Hackernews service provider
This commit is contained in:
parent
638eecee46
commit
fa5dee8505
3 changed files with 61 additions and 0 deletions
|
@ -17,10 +17,12 @@ exports.serviceprovidersList = [
|
||||||
'dns',
|
'dns',
|
||||||
'xmpp',
|
'xmpp',
|
||||||
'twitter',
|
'twitter',
|
||||||
|
'hackernews',
|
||||||
]
|
]
|
||||||
|
|
||||||
exports.serviceproviders = {
|
exports.serviceproviders = {
|
||||||
dns: require('./serviceproviders/dns'),
|
dns: require('./serviceproviders/dns'),
|
||||||
xmpp: require('./serviceproviders/xmpp'),
|
xmpp: require('./serviceproviders/xmpp'),
|
||||||
twitter: require('./serviceproviders/twitter'),
|
twitter: require('./serviceproviders/twitter'),
|
||||||
|
hackernews: require('./serviceproviders/hackernews'),
|
||||||
}
|
}
|
||||||
|
|
53
src/serviceproviders/hackernews.js
Normal file
53
src/serviceproviders/hackernews.js
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
Copyright 2020 Yarmo Mackenbach
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
const reURI = /^https:\/\/news.ycombinator.com\/user\?id=(.*)\/?/
|
||||||
|
|
||||||
|
const processURI = (uri, opts) => {
|
||||||
|
if (!opts) { opts = {} }
|
||||||
|
const match = uri.match(reURI)
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: "hackernews",
|
||||||
|
profile: {
|
||||||
|
display: match[1],
|
||||||
|
uri: uri
|
||||||
|
},
|
||||||
|
proof: {
|
||||||
|
uri: `https://hacker-news.firebaseio.com/v0/user/${match[1]}.json`,
|
||||||
|
fetch: null
|
||||||
|
},
|
||||||
|
qr: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const tests = [
|
||||||
|
{
|
||||||
|
uri: 'https://news.ycombinator.com/user?id=Alice',
|
||||||
|
shouldMatch: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
uri: 'https://news.ycombinator.com/user?id=Alice/',
|
||||||
|
shouldMatch: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
uri: 'https://domain.org/user?id=Alice',
|
||||||
|
shouldMatch: false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
exports.reURI = reURI
|
||||||
|
exports.processURI = processURI
|
||||||
|
exports.tests = tests
|
|
@ -45,4 +45,10 @@ describe('verify', () => {
|
||||||
expect(matches).to.be.length(1)
|
expect(matches).to.be.length(1)
|
||||||
expect(matches[0].type).to.be.equal('twitter')
|
expect(matches[0].type).to.be.equal('twitter')
|
||||||
})
|
})
|
||||||
|
it('should match "https://news.ycombinator.com/user?id=Alice" to the Hackernews service provider', () => {
|
||||||
|
const matches = doipjs.verify('https://news.ycombinator.com/user?id=Alice', null, {returnMatchesOnly: true})
|
||||||
|
expect(matches).to.be.a('array')
|
||||||
|
expect(matches).to.be.length(1)
|
||||||
|
expect(matches[0].type).to.be.equal('hackernews')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue