all files / src/ RequestConfig.js

56.41% Statements 44/78
100% Branches 2/2
29.17% Functions 7/24
56.41% Lines 44/78
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133                                                                                                                                                                 11×   11×                
var log = require('./Log.js').Logger('libZotero:RequestConfig');
var Validator = require('./Validator.js');
 
var RequestConfig = function(){
	this.config = {};
};
 
RequestConfig.prototype.Target = function(val){
	this.config['target'] = val;
	return this;
};
 
RequestConfig.prototype.TargetModifier = function(val){
	this.config['targetModifier'] = val;
	return this;
};
 
RequestConfig.prototype.LibraryType = function(val){
	this.config['libraryType'] = val;
	return this;
};
 
RequestConfig.prototype.LibraryID = function(val){
	this.config['libraryID'] = val;
	return this;
};
 
RequestConfig.prototype.ItemType = function(val){
	this.config['itemType'] = val;
	return this;
};
 
RequestConfig.prototype.ItemKey = function(val){
	this.config['itemKey'] = val;
	return this;
};
 
RequestConfig.prototype.CollectionKey = function(val){
	this.config['collectionKey'] = val;
	return this;
};
 
RequestConfig.prototype.Sort = function(val){
	this.config['sort'] = val;
	return this;
};
 
RequestConfig.prototype.Order = function(val){
	this.config['order'] = val;
	return this;
};
 
RequestConfig.prototype.Start = function(val){
	this.config['start'] = val;
	return this;
};
 
RequestConfig.prototype.Limit = function(val){
	this.config['limit'] = val;
	return this;
};
 
RequestConfig.prototype.Content = function(val){
	this.config['content'] = val;
	return this;
};
 
RequestConfig.prototype.Include = function(val){
	this.config['include'] = val;
	return this;
};
 
RequestConfig.prototype.Format = function(val){
	this.config['format'] = val;
	return this;
};
 
RequestConfig.prototype.Q = function(val){
	this.config['q'] = val;
	return this;
};
 
RequestConfig.prototype.Fq = function(val){
	this.config['fq'] = val;
	return this;
};
 
RequestConfig.prototype.Tag = function(val){
	this.config['tag'] = val;
	return this;
};
 
RequestConfig.prototype.TagType = function(val){
	this.config['tagType'] = val;
	return this;
};
 
RequestConfig.prototype.Key = function(val){
	this.config['key'] = val;
	return this;
};
 
RequestConfig.prototype.Style = function(val){
	this.config['style'] = val;
	return this;
};
 
RequestConfig.prototype.LinkWrap = function(val){
	this.config['linkwrap'] = val;
	return this;
};
 
RequestConfig.prototype.Validate = function(){
	let params = this.config;
	let valid = true;
 
	Object.keys(params).forEach(function(key){
		var val = params[key];
		//validate params based on patterns in Zotero.Validator
		if(Validator.validate(val, key) === false){
			//warn on invalid parameter and drop from params that will be used
			log.warn('API argument failed validation: ' + key + ' cannot be ' + val);
			delete params[key];
			valid = false;
		}
	});
 
	return valid;
};
 
 
module.exports = RequestConfig;