Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pusher.me() returns rubbish #48

Open
davidnewcomb opened this issue Jul 31, 2023 · 3 comments
Open

pusher.me() returns rubbish #48

davidnewcomb opened this issue Jul 31, 2023 · 3 comments

Comments

@davidnewcomb
Copy link

Following your documentation. I am using version 3.0.0. What am I doing wrong? How can I get the useful information using your module?

import PushBullet from 'pushbullet'
import { API_KEY } from './config.js'

const pusher = new PushBullet(API_KEY)
const me = await pusher.me()
console.log('Me:', me)

Gives:

Me: Response {
  size: 0,
  [Symbol(Body internals)]: {
    body: PassThrough {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 3,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: true,
      [Symbol(kCapture)]: false,
      [Symbol(kCallback)]: null
    },
    stream: PassThrough {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 3,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: true,
      [Symbol(kCapture)]: false,
      [Symbol(kCallback)]: null
    },
    boundary: null,
    disturbed: false,
    error: null
  },
  [Symbol(Response internals)]: {
    type: 'default',
    url: 'https://api.pushbullet.com/v2/users/me',
    status: 200,
    statusText: '',
    headers: {
      'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000',
      connection: 'close',
      'content-length': '353',
      'content-type': 'application/json; charset=utf-8',
      date: 'Mon, 31 Jul 2023 21:08:44 GMT',
      via: '1.1 google',
      'x-ratelimit-limit': '16384',
      'x-ratelimit-remaining': '16369',
      'x-ratelimit-reset': '1690840927'
    },
    counter: 0,
    highWaterMark: 16384
  }
}

But when I use curl with the same access token I get:

curl --header 'Access-Token: <access_token>' "https://api.pushbullet.com/v2/users/me" 
{"active":true,"iden":"....}
@davidnewcomb
Copy link
Author

@davidnewcomb
Copy link
Author

davidnewcomb commented Jul 31, 2023

I've reopened this to ask why I'm supposed to await .json(). Surely that bit should live inside the library as it's part of the session layer. When I call me() I should just get back the me object and not your internal object where I have to do the last little bit - each time.

This is what I had to do to get version 3.0.0 working. Is this right? It's not at all what the docs say.

const pusher = new PushBullet(API_KEY)
const pbObjectPromise = await pusher.devices()
const pbObject = await pbObjectPromise.json()
const devices = pbObject.devices
const device = devices.find((d) => d.nickname === DEVICE_NICKNAME)

@alexwhitman
Copy link
Owner

The response that is returned is the response object from fetch() which is used internally. Earlier versions did return the JSON response but there were requests to return the full response as the PushBullet API returns rate limiting information in the response headers (https://docs.pushbullet.com/#ratelimiting) which can be useful to not exceed quota limits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants