Skip to content

Instantly share code, notes, and snippets.

@sharpred
Created January 26, 2017 12:47

Revisions

  1. sharpred revised this gist Jan 26, 2017. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions lookup.js
    Original file line number Diff line number Diff line change
    @@ -24,12 +24,12 @@ const response = {
    }
    }, debug: {
    body: {
    accessDeviceToken: "NmUwMzY1MGY0ZGU1M2I3NDYyYmE1MDg4YWU4NmMxMTU7MEJGQTA4N0RFNTU5NDZDQUIzNkEzQTU5Mzc3QkNGQjQ="
    accessDeviceToken: "NmUwMzY1MGY0ZGU1M2I3NDYyYmE0RFNTU5NDZDQUIzNkEzQTU5Mzc3QkNGQjQ="
    },
    headers: {
    Accept: "application/json; charset=utf8",
    "auth-apiKey": "e2e381adc9f53e3873fbac6804f12b14",
    "auth-signature": "f2f226aed2f61c501f2352890816cc87a33bcd5a8a771d1228dddd05fda8b9275c985f50194ced64d59de17b90cebcd1a804e1b4cde36e273a3816606528518b", "auth-timestamp": 1485425224791, "auth-token": "6fd7c4e2a684285841f67391a5362ba5", "Content-Type": "application/json; charset=utf8"
    "auth-apiKey": "YOURAPIKEY",
    "auth-signature": "SOMEMADEUPVALUE", "auth-timestamp": 1485425224791, "auth-token": "ANOTHERMADEUPVALUE", "Content-Type": "application/json; charset=utf8"
    },
    preHashedSignature: "yada"
    }
  2. sharpred created this gist Jan 26, 2017.
    40 changes: 40 additions & 0 deletions lookup.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    /*
    * use of ramda fantasy Maybe for deep inspection of an object property
    * see https://github.com/ramda/ramda-fantasy/blob/master/docs/Maybe.md
    * for more info
    */
    const R = require("ramda");
    const M = require("ramda-fantasy").Maybe;
    const Just = M.Just;
    const Nothing = M.Nothing;
    const response = {
    "ota-api":
    {
    serverError:
    {
    error: 1902,
    message: "ERROR_ACCESS_DEVICE_ALREADY_AUTHENTICATE",
    exception: false,
    authenticated: true
    }, serverInformation: {
    beginTime: "2017-01-26T10:07:04.936Z",
    endTime: "2017-01-26T10:07:04.941Z",
    serverTime: 1485425224941,
    duration: 5
    }
    }, debug: {
    body: {
    accessDeviceToken: "NmUwMzY1MGY0ZGU1M2I3NDYyYmE1MDg4YWU4NmMxMTU7MEJGQTA4N0RFNTU5NDZDQUIzNkEzQTU5Mzc3QkNGQjQ="
    },
    headers: {
    Accept: "application/json; charset=utf8",
    "auth-apiKey": "e2e381adc9f53e3873fbac6804f12b14",
    "auth-signature": "f2f226aed2f61c501f2352890816cc87a33bcd5a8a771d1228dddd05fda8b9275c985f50194ced64d59de17b90cebcd1a804e1b4cde36e273a3816606528518b", "auth-timestamp": 1485425224791, "auth-token": "6fd7c4e2a684285841f67391a5362ba5", "Content-Type": "application/json; charset=utf8"
    },
    preHashedSignature: "yada"
    }
    };

    const lookup = R.curry((k, obj) => k in obj ? Just(obj[k]) : Nothing());

    console.log(lookup("ota-api", response).chain(lookup('serverError')).chain(lookup("authenticated")).getOrElse(false));