This repository was archived by the owner on May 25, 2021. It is now read-only.
File tree 4 files changed +46
-2
lines changed
4 files changed +46
-2
lines changed Original file line number Diff line number Diff line change @@ -47,3 +47,25 @@ There are several additional functions available to simplify frequent calls:
47
47
'/Meetings?startDate=05-01-2015&endDate=05-03-2015';
48
48
49
49
api.call(options, callback);
50
+
51
+ ## Caching
52
+
53
+ Caching is turned on by default. Queries are cached for a period of 12 hours.
54
+ The cache can be turned off by invoking the following function:
55
+
56
+ api.useCache(false);
57
+
58
+ or individually, for each query by specifying an optional parameter in the
59
+ options object (defaults to the global useCache, which is set above, or true by
60
+ default):
61
+
62
+ options.useCache = false;
63
+
64
+ Additionally, we fall back on old cached data (even if it's older than 12 hours)
65
+ if the API is unavailable or returns an error for any reason. Otherwise, you
66
+ will get back from the server a response code 500, with an error object and
67
+ message like so:
68
+
69
+ {
70
+ "error": "Error getting access token: UNABLE_TO_VERIFY_LEAF_SIGNATURE"
71
+ }
Original file line number Diff line number Diff line change @@ -74,6 +74,22 @@ module.exports.call = function(options, callback) {
74
74
}
75
75
} ,
76
76
getCallback = function ( response ) {
77
+ // non-standard response
78
+ if ( response . statusCode !== 200 ) {
79
+ if ( options . useCache && cache . isCached ( options ) >= 0 ) {
80
+ // the object is cached, even if it's old,
81
+ // let's return that object.
82
+ cache . getCachedResponse ( options , callback ) ;
83
+ return ;
84
+ } else {
85
+ // the server is unavailable, and the object isn't
86
+ // cached at all, or the cache is off.
87
+ // we return an error:
88
+ callback ( { error : 'UM API returned non-200 status code' } ) ;
89
+ return ;
90
+ }
91
+ }
92
+
77
93
var responseData = '' ;
78
94
79
95
response . on ( 'data' , function ( chunk ) {
Original file line number Diff line number Diff line change @@ -19,8 +19,7 @@ module.exports.isCached = function(options) {
19
19
var timeDiff = Date . now ( ) - cache [ searchQuery ] . timestamp ;
20
20
21
21
// (now - time saved) < 12 hours
22
- if ( timeDiff < 15000 ) {
23
- // if(timeDiff < 43200000) {
22
+ if ( timeDiff < 43200000 ) {
24
23
return 1 ;
25
24
} else {
26
25
return 0 ;
Original file line number Diff line number Diff line change @@ -52,6 +52,13 @@ var getAccessToken = function(callback) {
52
52
}
53
53
} ,
54
54
postCallback = function ( response ) {
55
+ // non-standard response
56
+ if ( response . statusCode !== 200 ) {
57
+ callback ( { error : 'UM access token request returned non-200' +
58
+ 'status code' } ) ;
59
+ return ;
60
+ }
61
+
55
62
var tokenData = '' ;
56
63
response . on ( 'data' , function ( chunk ) {
57
64
tokenData += chunk ;
You can’t perform that action at this time.
0 commit comments