mirror of
				https://github.com/KevinMidboe/moviedb.git
				synced 2025-10-29 17:50:25 +00:00 
			
		
		
		
	Add etag and if-modified-since support. (http request)
The execMethod() returns a third parameter which is the http response. (In order to get the date and the etag header values)
This commit is contained in:
		| @@ -40,8 +40,8 @@ MovieDB.prototype.requestToken = function(fn){ | |||||||
|     if(err) { |     if(err) { | ||||||
|       fn(err); |       fn(err); | ||||||
|     } else { |     } else { | ||||||
|        self.token = res.body; |     self.token = res.body; | ||||||
|        fn(); |     fn(); | ||||||
|     } |     } | ||||||
|   }); |   }); | ||||||
|  |  | ||||||
| @@ -85,6 +85,17 @@ var execMethod = function(type, params, endpoint, fn){ | |||||||
|   var req = request(type, endpoints.base_url + endpoint) |   var req = request(type, endpoints.base_url + endpoint) | ||||||
|             .query({api_key : this.api_key}) |             .query({api_key : this.api_key}) | ||||||
|             .set('Accept', 'application/json'); |             .set('Accept', 'application/json'); | ||||||
|  |    | ||||||
|  |   if (params.ifNoneMatch) { | ||||||
|  |     req=req.set('If-None-Match', params.ifNoneMatch); | ||||||
|  |      | ||||||
|  |   } else if (params.ifModifiedSince) { | ||||||
|  |     var t=params.ifModifiedSince; | ||||||
|  |     if (t.toUTCString) { | ||||||
|  |       t=t.toUTCString(); | ||||||
|  |     } | ||||||
|  |     req=req.set('If-Modified-Since', t); | ||||||
|  |   } | ||||||
|  |  | ||||||
|   if(type === 'GET') |   if(type === 'GET') | ||||||
|     req.query(params); |     req.query(params); | ||||||
| @@ -93,9 +104,9 @@ var execMethod = function(type, params, endpoint, fn){ | |||||||
|  |  | ||||||
|   req.end(function(err, res){ |   req.end(function(err, res){ | ||||||
|     if(err){ |     if(err){ | ||||||
|       fn(err); |       fn(err, null, res); | ||||||
|     } else { |     } else { | ||||||
|       fn(null, res.body); |       fn(null, res.body, res); | ||||||
|     } |     } | ||||||
|   }); |   }); | ||||||
| }; | }; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user