Skip to content
This repository was archived by the owner on Dec 7, 2021. It is now read-only.

Commit d1b6b5a

Browse files
committed
initial untappd implementation
1 parent ead0fc9 commit d1b6b5a

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

lib/fixtures/untappd.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* eslint max-len: "off" */
2+
3+
const AUTHENTICATE_URL = `https://untappd.com/oauth/authenticate?
4+
scope=&
5+
redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fcallback&
6+
response_type=code&
7+
client_id=APPID123
8+
`.replace(/\s+/g, '');
9+
10+
const DANCE_CALLBACK = `?
11+
code=CODE123
12+
`.replace(/\s+/g, '');
13+
14+
export default [AUTHENTICATE_URL, DANCE_CALLBACK];

lib/providers/untappd.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {
2+
curry,
3+
has,
4+
identity,
5+
ifElse,
6+
merge,
7+
pipe,
8+
pipeP,
9+
prop,
10+
} from 'ramda';
11+
import {
12+
authorizationUrl,
13+
} from '../utils/oauth2';
14+
import {
15+
fromQueryString,
16+
} from '../utils/uri';
17+
18+
const SCOPE = '';
19+
const AUTH = 'https://untappd.com/oauth/authenticate';
20+
21+
const checkError = ifElse(
22+
has('error'),
23+
pipe(prop('error'), curry((e) => { throw new Error(e); })),
24+
identity,
25+
);
26+
27+
// eslint-disable-next-line import/prefer-default-export
28+
export const authorize = (
29+
{ dance },
30+
{ appId, callback, scope = SCOPE }) =>
31+
pipeP(
32+
dance,
33+
fromQueryString,
34+
checkError,
35+
merge({ appId, callback }),
36+
)(authorizationUrl(AUTH, appId, callback, scope, 'code'));
37+
38+
export const identify = curry((request, { code }) => ({
39+
credentials: {
40+
code,
41+
},
42+
}));

lib/providers/untappd.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import assert from 'assert';
2+
import * as untappd from './untappd';
3+
import DANCE from '../fixtures/untappd';
4+
import * as test from '../platforms/test';
5+
import login from '../login';
6+
7+
describe('Untappd', () => {
8+
before(() => {
9+
test.setup([], DANCE);
10+
});
11+
12+
it('should authorize', () => {
13+
const untappdTest = login(untappd, test);
14+
return untappdTest({
15+
appId: 'APPID123',
16+
})
17+
.then((response) => {
18+
assert.equal(response.credentials.code, 'CODE123');
19+
});
20+
});
21+
});

0 commit comments

Comments
 (0)