Skip to content

Instantly share code, notes, and snippets.

@fastcodecoq
Created March 3, 2015 20:32
Show Gist options
  • Select an option

  • Save fastcodecoq/8dd1ab271dd4421e408b to your computer and use it in GitHub Desktop.

Select an option

Save fastcodecoq/8dd1ab271dd4421e408b to your computer and use it in GitHub Desktop.
function knackFactory($http){
this.uri = undefined;
this.obj_key = undefined;
this.field_key = undefined;
this.base_url = 'https://api.knackhq.com';
this.forms = function(){ this.uri = '/v1/objects/'; return this;}
this.form = function(_obj_key){ console.log(_obj_key); this.obj_key = _obj_key; this.uri = '/v1/objects/'+this.obj_key+'/'; return this;}
this.field = function(_field_key){ this.field_key = _field_key; this.uri = '/v1/objects/'+this.obj_key+'/fields/'; return this; }
this.fields = function(){ this.uri = '/v1/objects/'+this.obj_key+'/'; return this;}
this.field = function(_field_key){ this.field_key = _field_key; this.uri = '/v1/objects/'+this.obj_key+'/fields/'; return this; }
this.records = function(){ this.uri = '/v1/objects/'+this.obj_key+'/records/'; return this; }
this.record = function(_record_key){ this.record_key = _record_key; this.uri = '/v1/objects/'+this.obj_key+'/records/' + this.record_key; return this; }
this.reset = this.destroy = function(){ this.uri = ''; return this;}
//methods
this.get = function(){ return (this.uri) ? $http.get(this.base_url + this.uri) : false; }
this.create = function(data){ return (this.uri) ? $http.post(this.base_url + this.uri, data) : false; }
this.del = function(){ return (this.uri) ? $http.delete(this.base_url + this.uri) : false; }
this.update = function(data){ return (this.uri) ? $http.put(this.base_url + this.uri, data) : false; }
return this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment