arei / node-untappd Goto Github PK
View Code? Open in Web Editor NEWNodeJS API for Untappd
License: MIT License
NodeJS API for Untappd
License: MIT License
There are some options that are not passed on, e.g. the user activity feed has a since_id
option that would generate less data over the wire when polling the feed. Only limit
and max_id
is supported.
It'd be nice if you could just pass the params in an object to the function instead. Like this:
untappd.userFeed(cb, user_name, {
since_id: last_id,
limit: 5
});
That way you won't need to maintain the params if new ones show up in the API and this lib can instead just stringify the params instead of what is currently done:
that.userFeed = function(callback, lookupUser, params) {
// snip-snip guard statements
return get("/v4/user/checkins/"+lookupUser, QS.stringify(params), callback);
}
Per the README:
Below is a list of sites where you can see node-untappd in production use.
- http://www.arei.net - arei's website which shows the last beer he drank in the upper right corner.
The linked site no longer has that information "in the upper right corner".
Looks like they've changed the friend feed (and possibly others) to require the ACCESS_TOKEN
parameter instead of a combination of CLIENT_ID
and CLIENT_SECRET
.
Request
{ host: 'api.untappd.com',
port: 443,
path: '/v4/checkin/recent?limit=10&client_id=<secret>&client_secret=<secret>',
method: 'GET' }
{ limit: 10,
client_id: '<secret>',
client_secret: '<secret>' }
null
node-untappd: data: 191
node-untappd: end: 0
[Thu Aug 10 2017 09:34:26 GMT-0500 (CDT)] ERROR { meta:
{ code: 500,
error_detail: 'This method requires authentication.',
error_type: 'invalid_auth',
developer_friendly: '',
response_time: { time: 0.01, measure: 'seconds' } },
response: [] }
500: This method requires authentication.
When working with the pendingFriends
method, I noticed that the data
argument is dropped. This is expected, as there is nothing additional that can be passed to this endpoint Edit: Turns out, you can pass a limit
and offset
. However, the method itself still expects it and will throw a ReferenceError
.
Lines 360 to 366 in 02ef1ea
I get an error when running the code in v0.5.0
:
[Thu Mar 25 2021 19:32:50 GMT-0500 (Central Daylight Time)] ERROR ReferenceError: data is not defined
at UntappdClient.that.pendingFriends (/Users/yeargism/Sites/hubot-untappd-friends/node_modules/node-untappd/UntappdClient.js:362:3)
at approveRequests (/Users/yeargism/Sites/hubot-untappd-friends/src/untappd-friends.coffee:286:13)
at TextListener.callback (/Users/yeargism/Sites/hubot-untappd-friends/src/untappd-friends.coffee:66:27)
at executeListener (/Users/yeargism/Sites/hubot-untappd-friends/node_modules/hubot/src/listener.js:79:16)
at allDone (/Users/yeargism/Sites/hubot-untappd-friends/node_modules/hubot/src/middleware.js:56:7)
at /Users/yeargism/Sites/hubot-untappd-friends/node_modules/async/lib/async.js:274:13
at Object.async.eachSeries (/Users/yeargism/Sites/hubot-untappd-friends/node_modules/async/lib/async.js:142:20)
at async.reduce (/Users/yeargism/Sites/hubot-untappd-friends/node_modules/async/lib/async.js:268:15)
at processTicksAndRejections (internal/process/task_queues.js:75:11)
Looks like a merge might have gone sideways. Looking into it.
$ npm t
> [email protected] test
> ./node_modules/.bin/jest
FAIL __tests__/Request.js
● Test suite failed to run
/Users/stephen/Sites/node-untappd/UntappdClient.js: Unexpected token, expected , (134:2)
132 | request.end();
133 | return request;
> 134 | };
| ^
135 |
136 | var hasToken = function() {
137 | return !!token;
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.677s
Ran all test suites.
When running debug mode on both my laptop and remote server, I get this:
node-untappd: get : /v4/beer/info/44533?client_id=MY_CLIENT_ID&client_secret=MY_CLIENT_SECRET
{ client_id: 'MY_CLIENT_ID',
client_secret: 'MY_CLIENT_ID' }
null
node-untappd: error: { '0': { [Error: socket hang up] code: 'ECONNRESET' } }
If I change the port in the module from 443 to 80 (not what you intended here) it works:
node-untappd: get : /v4/beer/info/44533?client_id=MY_CLIENT_ID&client_secret=MY_CLIENT_SECRET
{ client_id: 'MY_CLIENT_ID',
client_secret: 'MY_CLIENT_SECRET' }
null
node-untappd: data: 14064
node-untappd: data: 1448
node-untappd: data: 18824
node-untappd: data: 1448
node-untappd: data: 17376
node-untappd: data: 7240
node-untappd: data: 1448
node-untappd: data: 13832
node-untappd: end: 0
{ meta:
{ code: 200,
response_time: { time: 0.528, measure: 'seconds' },
init_time: { time: 0.007, measure: 'seconds' } },
notifications: [],
[...rest of the object...]
(Client ID and secret obscured for obvious reasons.)
My code is, essentially, just
console.log(JSON.parse(body));
When utilizing this package, or running tests, it's timing out.
Results from test script (with added --detectOpenHandles option):
➜ npm run test
> [email protected] test
> ./node_modules/.bin/jest --detectOpenHandles
PASS __tests__/Request.js
Requests
✓ Handles parse errors (40 ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 0.395 s, estimated 1 s
Ran all test suites.
Jest has detected the following 1 open handle potentially keeping Jest from exiting:
● TCPWRAP
99 | }
100 |
> 101 | var request = HTTPS.request(options, function(response) {
| ^
102 | response.setEncoding("utf8");
103 | var data = "";
104 |
at req (UntappdClient.js:101:23)
at get (UntappdClient.js:55:10)
at UntappdClient.beerInfo (UntappdClient.js:320:10)
at Object.<anonymous> (__tests__/Request.js:28:11)
at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)
at runJest (node_modules/@jest/core/build/runJest.js:404:19)
at _run10000 (node_modules/@jest/core/build/cli/index.js:320:7)
at runCLI (node_modules/@jest/core/build/cli/index.js:173:3)
node:events:504
throw er; // Unhandled 'error' event
^
Error: socket hang up
at connResetException (node:internal/errors:691:14)
at TLSSocket.socketOnEnd (node:_http_client:466:23)
at TLSSocket.emit (node:events:538:35)
at endReadableNT (node:internal/streams/readable:1345:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
Emitted 'error' event on ClientRequest instance at:
at TLSSocket.socketOnEnd (node:_http_client:466:9)
at TLSSocket.emit (node:events:538:35)
at endReadableNT (node:internal/streams/readable:1345:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'ECONNRESET'
}
Hey arei - when I try to run your example with my id/secret, I get the error below.
{ code: 500,
error_detail: 'Please pass via GET using the parameter 'client_secret' and 'client_id'',
error_type: 'invalid_param',
developer_friendly: '/v4/user/checkins/',
response_time: { time: 0.003, measure: 'seconds' } },
response: [] }
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.