athombv / node-homey-oauth2app

This module does the heavy lifting for a Homey App that talks to any OAuth2 Web API.
https://athombv.github.io/node-homey-oauth2app/
5 stars 5 forks source link

Allow oauth2 requests to retrieve images #62

Closed jghaanstra closed 10 months ago

jghaanstra commented 2 years ago

The current implementation only allows to retrieve JSON data. Some devices might require the retrieval of images like motion snapshots. There currently isnt a (easy) way to do this using this module.

jghaanstra commented 2 years ago

For now I'm overwriting onHandleResponse() and changed the block from line https://github.com/athombv/node-homey-oauth2app/blob/3afb45d51c5b7f23873cb735cd22147bca73be20/lib/OAuth2Client.js#L847

if (typeof contentType === 'string') {
      if (contentType.startsWith('application/json')) {
        body = await response.json();
      } else if (contentType.startsWith('image')) {
        body = response;
      } else {
        body = await response.text();
      }
    } else {
      body = await response.text();
    }
WeeJeWel commented 10 months ago

I believe this is such a rare occurrence, that it's fine to overload the methods (that's what they're for!), and not implement this in the module itself.

WeeJeWel commented 10 months ago

Okay, I implemented it after all :-)

Thank you!

https://github.com/athombv/node-homey-oauth2app/commit/3d7a200f02816cf1e5af4b6071e0239de5947ad7

jghaanstra commented 10 months ago

Thanx!