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

Commit

Permalink
initial untappd implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
infomofo committed Sep 2, 2019
1 parent ead0fc9 commit d1b6b5a
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/fixtures/untappd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint max-len: "off" */

const AUTHENTICATE_URL = `https://untappd.com/oauth/authenticate?
scope=&
redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fcallback&
response_type=code&
client_id=APPID123
`.replace(/\s+/g, '');

const DANCE_CALLBACK = `?
code=CODE123
`.replace(/\s+/g, '');

export default [AUTHENTICATE_URL, DANCE_CALLBACK];
42 changes: 42 additions & 0 deletions lib/providers/untappd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
curry,
has,
identity,
ifElse,
merge,
pipe,
pipeP,
prop,
} from 'ramda';
import {
authorizationUrl,
} from '../utils/oauth2';
import {
fromQueryString,
} from '../utils/uri';

const SCOPE = '';
const AUTH = 'https://untappd.com/oauth/authenticate';

const checkError = ifElse(
has('error'),
pipe(prop('error'), curry((e) => { throw new Error(e); })),
identity,
);

// eslint-disable-next-line import/prefer-default-export
export const authorize = (
{ dance },
{ appId, callback, scope = SCOPE }) =>
pipeP(
dance,
fromQueryString,
checkError,
merge({ appId, callback }),
)(authorizationUrl(AUTH, appId, callback, scope, 'code'));

export const identify = curry((request, { code }) => ({
credentials: {
code,
},
}));
21 changes: 21 additions & 0 deletions lib/providers/untappd.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import assert from 'assert';
import * as untappd from './untappd';
import DANCE from '../fixtures/untappd';
import * as test from '../platforms/test';
import login from '../login';

describe('Untappd', () => {
before(() => {
test.setup([], DANCE);
});

it('should authorize', () => {
const untappdTest = login(untappd, test);
return untappdTest({
appId: 'APPID123',
})
.then((response) => {
assert.equal(response.credentials.code, 'CODE123');
});
});
});

0 comments on commit d1b6b5a

Please sign in to comment.