callpixelsjs-rails 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 95e618811f3152b6fd4d4cbb1903501eb0673dd9
4
- data.tar.gz: cefabde8f534e5baa1c0d34776c60fb32999f4fa
3
+ metadata.gz: 8f5d9341bfd0c70bd2855e385760c55383e4b74e
4
+ data.tar.gz: c17584d2360476c52e847a881048e9d96d9a9538
5
5
  SHA512:
6
- metadata.gz: 325a99683c9a95409f5e738a6ecc44bd2673b502e1d1aa476df3522050ce71ab80cf8739627141c2db0726fa2b61bdf9e3e79c3e45c968a1b8a67f86d1b13fad
7
- data.tar.gz: 129910e20f10b42f9e68bfefb0ea1476bf8615f8bad8e1943868a1a0ed4b83e0287fc96b322347c227081c52162bd8f081217293e035e01b077f364260a34700
6
+ metadata.gz: ca41dda0224c22f3b9ee1e2c00908bb54e5732c9565a899e7994ac70b6d56b74eb8fdfbfa03b2c42207e2721456499b0d2d939ffde198ff0c05e8c6c492d2341
7
+ data.tar.gz: 0b4dee2e3b4009fac58e23f6fe2eacc08dc532fc939fe7a83ffd00bcf38159b7f5de538b423d0f566f5eab3773fa5fb4924980a75a16c18a1557447402a392c6
data/Gruntfile.js ADDED
@@ -0,0 +1,47 @@
1
+ module.exports = function(grunt) {
2
+
3
+ grunt.initConfig({
4
+ pkg: grunt.file.readJSON('package.json'),
5
+ concat: {
6
+ options: {
7
+ separator: ';'
8
+ },
9
+ dist: {
10
+ src: [
11
+ 'src/callpixels/base/helpers.js',
12
+ 'src/callpixels/base/cookies.js',
13
+ 'src/callpixels/base/base64.js',
14
+ 'src/callpixels/base/data.js',
15
+ 'src/callpixels/base/model.js',
16
+ 'src/callpixels/base/request.js',
17
+ 'src/callpixels/base/request_number.js',
18
+ 'src/callpixels/cache.js',
19
+ 'src/callpixels/number.js',
20
+ 'src/callpixels/campaign.js'
21
+ ],
22
+ dest: 'dist/<%= pkg.name %>.js'
23
+ }
24
+ },
25
+ uglify: {
26
+ options: {
27
+ banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
28
+ },
29
+ dist: {
30
+ files: {
31
+ 'dist/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>']
32
+ }
33
+ }
34
+ },
35
+ watch: {
36
+ files: ['<%= jshint.files %>'],
37
+ tasks: ['jshint']
38
+ }
39
+ });
40
+
41
+ grunt.loadNpmTasks('grunt-contrib-uglify');
42
+ grunt.loadNpmTasks('grunt-contrib-jshint');
43
+ grunt.loadNpmTasks('grunt-contrib-watch');
44
+ grunt.loadNpmTasks('grunt-contrib-concat');
45
+
46
+ grunt.registerTask('default', ['concat','uglify']);
47
+ };
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require "bundler/gem_tasks"
2
+ require 'fileutils'
3
+ require_relative 'lib/callpixelsjs/compile.rb'
4
+
5
+ namespace :callpixelsjs do
6
+ desc "compile callpixelsjs"
7
+ task :compile do
8
+ Callpixelsjs::Compile.perform
9
+ end
10
+ end
11
+
12
+ task :before_build do
13
+ Rake::Task["callpixelsjs:compile"].execute
14
+ end
15
+
16
+ task :build => :before_build
data/config/README ADDED
@@ -0,0 +1 @@
1
+ See our <a href="http://support.callpixels.com/callpixels-js/">knowledge base article</a> for more information.
@@ -0,0 +1,26 @@
1
+ {
2
+ "tags": {
3
+ "allowUnknownTags": true
4
+ },
5
+ "source": {
6
+ "include": [
7
+ "config/README",
8
+ "src/callpixels/number.js",
9
+ "src/callpixels/campaign.js"
10
+ ],
11
+ "exclude": [],
12
+ "includePattern": ".+\\.js(doc)?$",
13
+ "excludePattern": "(^|\\/|\\\\)_"
14
+ },
15
+ "opts": {
16
+ "destination": "./vendor/documentation/javascript/v1/"
17
+ },
18
+ "plugins": [],
19
+ "templates": {
20
+ "cleverLinks": false,
21
+ "monospaceLinks": false,
22
+ "default": {
23
+ "outputSourceFiles": true
24
+ }
25
+ }
26
+ }
@@ -1,5 +1,5 @@
1
1
  module Callpixelsjs
2
2
  module Rails
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
data/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "callpixels",
3
+ "description": "Callpixels Javascript API",
4
+ "version": "0.1.0",
5
+ "homepage": "https://github.com/callpixels/callpixelsjs",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/callpixels/callpixelsjs.git"
9
+ },
10
+ "bugs": {
11
+ "url": "https://github.com/callpixels/callpixelsjs/issues"
12
+ },
13
+ "author": {
14
+ "name": "Blake Hilscher",
15
+ "email": "blake@callpixels.com",
16
+ "url": "http://callpixels.com/"
17
+ },
18
+ "contributors": [
19
+ {
20
+ "name": "Blake Hilscher",
21
+ "email": "blake@hilscher.ca",
22
+ "url": "http://blake.hilscher.ca/"
23
+ }
24
+ ],
25
+ "licenses": [
26
+ {
27
+ "type": "GPLv3",
28
+ "url": "http://github.com/callpixels/callpixelsjs/blob/master/LICENSE"
29
+ }
30
+ ],
31
+ "main": "src/package.js",
32
+ "engines": {
33
+ "node": ">= 0.6.x"
34
+ },
35
+ "dependencies": {
36
+ },
37
+ "devDependencies": {
38
+ "grunt": "~0.4.5",
39
+ "jsdoc": "~3.3.0",
40
+ "grunt-contrib-jshint": "~0.10.0",
41
+ "grunt-contrib-nodeunit": "~0.4.1",
42
+ "grunt-contrib-uglify": "~0.5.0",
43
+ "grunt-contrib-watch": "~0.6.1",
44
+ "grunt-contrib-concat": "~0.4.0"
45
+ }
46
+ }
@@ -577,9 +577,7 @@
577
577
  request.send();
578
578
  }
579
579
 
580
- if (request.status === 200) {
581
- runCallbacks(request.responseText);
582
- }
580
+ runCallbacks(request.responseText);
583
581
  }
584
582
  };
585
583
 
@@ -1070,21 +1068,31 @@
1070
1068
  * @function request_number
1071
1069
  * @instance
1072
1070
  * @param {Object} tags - A collection of tags as key-value pairs. The number returned will match these tags.
1073
- * @param {getNumberCallback} callback - Callback fired after the request completes.
1071
+ * @param {getNumberCallback} callback - Callback fired if the request completes successfully.
1072
+ * @param {Function} error_callback - Callback fired if the request raises an error.
1074
1073
  * @example
1075
1074
  * campaign.request_number({calling_about: 'support'}, function (number) {
1076
1075
  * alert(number.get('number'))
1077
- * });
1076
+ * }, function(response){
1077
+ * alert('something went wrong: ' + response);
1078
+ * };
1078
1079
  */
1079
- self.request_number = function (tags, callback) {
1080
+ self.request_number = function (tags, callback, error_callback) {
1080
1081
  // assign the tags (this is important since it runs it through set_number_matching_tags)
1081
1082
  self.set('number_matching_tags', tags);
1082
1083
  // request the number
1083
1084
  new RequestNumber(self.get('campaign_key', 'number_matching_tags')).perform(function (data) {
1084
- // initialize number
1085
- var number = new Callpixels.Number(data.number);
1086
- // call callback
1087
- callback.apply(self, [number]);
1085
+ // did callpixels return a valid number?
1086
+ if (typeof(data) !== 'undefined' && typeof(data.number) !== 'undefined' && data.number !== '') {
1087
+ // initialize number
1088
+ var number = new Callpixels.Number(data.number);
1089
+ // call callback
1090
+ callback.apply(self, [number]);
1091
+ }
1092
+ // otherwise fire the error callback
1093
+ else if (typeof(error_callback) === 'function') {
1094
+ error_callback.apply(self, [data]);
1095
+ }
1088
1096
  });
1089
1097
  };
1090
1098
  /**
@@ -1,2 +1,2 @@
1
- /*! callpixels 13-08-2014 */
2
- !function(){"undefined"==typeof window.Callpixels&&(window.Callpixels={});var a={};a.assert_required_keys=function(){for(var a=Array.prototype.slice.call(arguments),b=a.shift(),c=0;c<a.length;c++){var d=a[c];if("undefined"==typeof b||"undefined"==typeof b[d])throw"ArgumentError: Required keys are not defined: "+a.join(", ")}return b},a.merge=function(b,c){for(var d in c)try{b[d]=c[d].constructor==Object?a.merge(b[d],c[d]):c[d]}catch(e){b[d]=c[d]}return b},a.isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)},a.ieVersion=function(){return null==a._ieVersion&&(a._ieVersion=function(){for(var a=3,b=document.createElement("div"),c=b.getElementsByTagName("i");b.innerHTML="<!--[if gt IE "+ ++a+"]><i></i><![endif]-->",c[0];);return a>4?a:!1}()),(6==a._ieVersion||7==a._ieVersion)&&null==Callpixels.easyxdm_loaded&&(Callpixels.easyxdm_loaded=!1),a._ieVersion},Callpixels.Base=a}(),function(a){var b=function(a,c,d){return 1===arguments.length?b.get(a):b.set(a,c,d)};b._document=document,b._navigator=navigator,b.defaults={path:"/"},b.get=function(a){return b._cachedDocumentCookie!==b._document.cookie&&b._renewCache(),b._cache[a]},b.set=function(a,c,d){return d=b._getExtendedOptions(d),b._document.cookie=b._generateCookieString(a,c,d),b},b._getExtendedOptions=function(c){return{path:c&&c.path||b.defaults.path,domain:c&&c.domain||b.defaults.domain,secure:c&&c.secure!==a?c.secure:b.defaults.secure}},b._isValidDate=function(a){return"[object Date]"===Object.prototype.toString.call(a)&&!isNaN(a.getTime())},b._generateCookieString=function(a,b,c){return a=encodeURIComponent(a),b=(b+"").replace(/[^!#$&-+\--:<-\[\]-~]/g,encodeURIComponent),c=c||{},a=a+"="+b+(c.path?";path="+c.path:""),a+=c.domain?";domain="+c.domain:"",a+=c.secure?";secure":""},b._getCookieObjectFromString=function(c){var d={};c=c?c.split("; "):[];for(var e=0;e<c.length;e++){var f=b._getKeyValuePairFromCookieString(c[e]);d[f.key]===a&&(d[f.key]=f.value)}return d},b._getKeyValuePairFromCookieString=function(a){var b=a.indexOf("="),b=0>b?a.length:b;return{key:decodeURIComponent(a.substr(0,b)),value:decodeURIComponent(a.substr(b+1))}},b._renewCache=function(){b._cache=b._getCookieObjectFromString(b._document.cookie),b._cachedDocumentCookie=b._document.cookie},b._areEnabled=function(){return b._navigator.cookieEnabled||"1"===b.set("cookies.js",1).get("cookies.js")},b.enabled=b._areEnabled(),"function"==typeof define&&define.amd?define(function(){return b}):"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=b),exports.Cookies=b):b,Callpixels.Base.Cookies=b}(),function(){var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="};Base64.encode=function(a){var b,c,d,e,f,g,h,i="",j=0;for(a=Base64._utf8_encode(a);j<a.length;)b=a.charCodeAt(j++),c=a.charCodeAt(j++),d=a.charCodeAt(j++),e=b>>2,f=(3&b)<<4|c>>4,g=(15&c)<<2|d>>6,h=63&d,isNaN(c)?g=h=64:isNaN(d)&&(h=64),i=i+Base64._keyStr.charAt(e)+Base64._keyStr.charAt(f)+Base64._keyStr.charAt(g)+Base64._keyStr.charAt(h);return i},Base64.decode=function(a){var b,c,d,e,f,g,h,i="",j=0;for(a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");j<a.length;)e=Base64._keyStr.indexOf(a.charAt(j++)),f=Base64._keyStr.indexOf(a.charAt(j++)),g=Base64._keyStr.indexOf(a.charAt(j++)),h=Base64._keyStr.indexOf(a.charAt(j++)),b=e<<2|f>>4,c=(15&f)<<4|g>>2,d=(3&g)<<6|h,i+=String.fromCharCode(b),64!=g&&(i+=String.fromCharCode(c)),64!=h&&(i+=String.fromCharCode(d));return i=Base64._utf8_decode(i)},Base64._utf8_encode=function(string){string=string.replace(eval("/\\r\\n/g"),eval("String('\\n')"));for(var utftext="",n=0;n<string.length;n++){var c=string.charCodeAt(n);128>c?utftext+=String.fromCharCode(c):c>127&&2048>c?(utftext+=String.fromCharCode(c>>6|192),utftext+=String.fromCharCode(63&c|128)):(utftext+=String.fromCharCode(c>>12|224),utftext+=String.fromCharCode(c>>6&63|128),utftext+=String.fromCharCode(63&c|128))}return utftext},Base64._utf8_decode=function(a){for(var b="",c=0,d=c1=c2=0;c<a.length;)d=a.charCodeAt(c),128>d?(b+=String.fromCharCode(d),c++):d>191&&224>d?(c2=a.charCodeAt(c+1),b+=String.fromCharCode((31&d)<<6|63&c2),c+=2):(c2=a.charCodeAt(c+1),c3=a.charCodeAt(c+2),b+=String.fromCharCode((15&d)<<12|(63&c2)<<6|63&c3),c+=3);return b},Callpixels.Base.Base64=Base64}(),function(){var a=Callpixels.Base,b=function(b){function c(){a.assert_required_keys(b,"type","primary_key"),"undefined"==typeof Callpixels.Base.Data._store[b.type]&&(Callpixels.Base.Data._store[b.type]={}),"undefined"==typeof Callpixels.Base.Data._store[b.type][b.primary_key]&&(Callpixels.Base.Data._store[b.type][b.primary_key]={})}var d=this;d.get=function(){var a={};if("undefined"==typeof arguments[0])a=Callpixels.Base.Data._store[b.type][b.primary_key];else if(1===arguments.length)a=Callpixels.Base.Data._store[b.type][b.primary_key][arguments[0]];else for(var c=0;c<arguments.length;c++){var d=arguments[c];a[d]=Callpixels.Base.Data._store[b.type][b.primary_key][d]}return a},d.set=function(a,c){return Callpixels.Base.Data._store[b.type][b.primary_key][a]=c,c},d.merge=function(a){for(var c in a)Callpixels.Base.Data._store[b.type][b.primary_key][c]=a[c];return a},c()};b._store={},Callpixels.Base.Data=b}(),function(){var a=Callpixels.Base,b=Callpixels.Base.Data,c=function(){this.api_host_uri="/api/v1/",this.type="model",this.primary_key=function(a){return c.primary_key(this.type,a)},this.store=function(a){if("undefined"!=typeof a){var b=this.primary_key();if("undefined"==typeof a[b])throw"ArgumentError: Expected to receive primary_key "+b;"undefined"==typeof this._store&&(this._store=new Callpixels.Base.Data({type:this.type,primary_key:a[b]})),this._store.merge(a),c.update_visitor_id(a)}return this._store},this.get_data=function(a,b){return this.connection().getJSON(this.api_host_uri+a,null,[c.update,b],this)},this.post_data=function(a,b,d){return this.connection().postJSON(this.api_host_uri+a,b,[c.update,d],this)},this.set=function(){return"function"==typeof this["set_"+arguments[0]]&&(arguments[1]=this["set_"+arguments[0]].apply(this,[arguments[1]])),this._store.set.apply(this,arguments)},this.get=function(){return this._store.get.apply(this,arguments)},this.connection=function(){return Callpixels.Base.Request.connection()}};c.inflections={number:"numbers",campaign:"campaigns"},c.update=function(d){for(var e in d){var f=e,g=d[e];if("undefined"!=typeof c.inflections[e]&&(f=c.inflections[e]),"undefined"!=typeof b._store[f])if(a.isArray(g))for(var h=0;h<g.length;h++)c.update_record(f,g[h]);else c.update_record(f,g[h])}return d},c.update_record=function(a,b){if(c.update_visitor_id(b),"undefined"!=typeof b.id){var d=c.primary_key(a);for(var e in b)Callpixels.Base.Data._store[a][b[d]][e]=b[e];return!0}return!1},c.update_visitor_id=function(a){"undefined"!=typeof a&&"undefined"!=typeof a.visitor_id&&Callpixels.Base.Cookies.set("CallPixels-vid",a.visitor_id)},c.primary_key=function(a,b){return"undefined"==typeof c.primary_keys&&(c.primary_keys={}),"undefined"==typeof c.primary_keys[a]&&(c.primary_keys[a]="id"),"undefined"!=typeof b&&(c.primary_keys[a]=b),c.primary_keys[a]},Callpixels.Base.Model=c}(),function(){var Base=window.Callpixels.Base,Cookies=window.Callpixels.Base.Cookies,Request=function(options){function initialize(a){config=Base.assert_required_keys(a,"http_prefix","addr","urlregex")}function with_ie_scripts(a){Callpixels.easyxdm_loaded?a():self.loadScript(http_prefix+"://cdn.jsdelivr.net/easyxdm/2.4.17.1/easyXDM.min.js",function(){self.loadScript(http_prefix+"://cdn.jsdelivr.net/easyxdm/2.4.17.1/json2.js",function(){Callpixels.easyxdm_loaded=!0,a()})})}var self=this,config={};self.getJSON=function(a,b,c,d){"function"==typeof c&&(c=[c]),"undefined"==typeof d&&(d=self);var e=function(){self.apiRequest(a,function(a){response=JSON.parse(a);for(var b in c)"function"==typeof c[b]&&c[b].apply(d,[response])},b)};6==Base.ieVersion()||7==Base.ieVersion()?with_ie_scripts(e):e()},self.postJSON=function(){return self.getJSON.apply(this,arguments)},self.apiRequest=function(request_uri,callbackFunctions,payload){function ignored(){}function runCallbacks(a){for(var b in callbackFunctions)"function"==typeof callbackFunctions[b]&&callbackFunctions[b](a)}function forwardResponse(){runCallbacks(xdr.responseText)}function sendXdm(){var remote=http_prefix+"://"+addr+"/ie_provider",swf=http_prefix+"://"+addr+"/easyxdm.swf",rpc=eval('new window.easyXDM.Rpc({ remote: "'+remote+'", swf: "'+swf+'"},{remote: {request: {}}});');rpc.request({url:"/"+request_url.match(urlregex)[1],method:"POST",data:payload},function(a){runCallbacks(a.data)})}var http_prefix=config.http_prefix,addr=config.addr,urlregex=eval(config.urlregex),request_url=http_prefix+"://"+addr+request_uri;if(payload&&"undefined"!=typeof Cookies.get("CallPixels-vid")&&"null"!==Cookies.get("CallPixels-vid")&&(payload.visitor_id=Cookies.get("CallPixels-vid")),"function"==typeof callbackFunctions&&(callbackFunctions=[callbackFunctions]),window.XDomainRequest){var xdr=new XDomainRequest;xdr.onload=forwardResponse,xdr.onprogress=ignored,xdr.onerror=ignored,xdr.ontimeout=ignored,xdr.timeout=3e4,payload?(xdr.open("post",request_url),xdr.send(self.buildPost(payload))):(xdr.open("get",request_url),xdr.send())}else if(6==Base.ieVersion()||7==Base.ieVersion())with_ie_scripts(sendXdm);else{var request=new XMLHttpRequest;payload?(request.open("POST",request_url,!1),request.setRequestHeader("Content-Type","application/json"),request.send(JSON.stringify(payload))):(request.open("GET",request_url,!1),request.send()),200===request.status&&runCallbacks(request.responseText)}},self.buildPost=function(a){var b="";for(var c in a)b+=c+"="+a[c]+"&";return b},self.loadScript=function(a,b){var c=document.getElementsByTagName("script")[0],d=document.createElement("script");d.type="text/javascript",d.async=!1,d.src=a;var e=function(a,b){"loaded"==a.readyState||"complete"==a.readyState?b():setTimeout(function(){e(a,b)},100)};"function"==typeof b&&("undefined"!=typeof d.addEventListener?d.addEventListener("load",b,!1):d.onreadystatechange=function(){d.onreadystatechange=null,e(d,b)}),c.parentNode.insertBefore(d,c)},initialize(options),self.config=config};Request.connection=function(){return"undefined"==typeof window.Callpixels._connection&&(window.Callpixels._connection=new Callpixels.Base.Request({addr:"callpixels.com",http_prefix:"http",urlregex:"/\\/\\/[^\\/]*\\/(.*)/"})),window.Callpixels._connection},Callpixels.Base.Request=Request}(),function(){function tags_to_script_tags(a){var b="";for(var c in a){var d=a[c];b=b+"&"+c+"="+d}return b}var Base=Callpixels.Base,Cookies=Callpixels.Base.Cookies,Base64=Callpixels.Base.Base64,Request=Callpixels.Base.Request,RequestNumber=function(options){function initialize(a){config=Base.assert_required_keys(a,"campaign_key")}function getParts(a){for(var b={},c=0;c<a.length;c++){var d=getUrlParts(a[c]);for(var e in d)b[e]=d[e]}return b}function getUrlParts(url){var objURL=new Object;try{url=url.match(eval("/\\?(.*)/"))[0]}catch(e){return objURL}return url.replace(new RegExp("([^?=&]+)(=([^&]*))?","g"),function(a,b,c,d){objURL[b.toLowerCase()]=d}),objURL}function getGACookies(){var a=["__utma","__utmb","__utmc","__utmz","__utmv"],b=new Object;for(var c in a){var d=extractCookie(a[c]);if(!(d||c>0))break;d&&(b[a[c]]=d)}return b}function extractCookie(a){var b=new RegExp(a+"=([^;]*)","g");try{return b.exec(document.cookie)[1]}catch(c){return!1}}function findOne(a,b){for(var c in b)for(var d in a)if(d==b[c])return a[d];return!1}var self=this,config={},resource_url="/api/v1/numbers?";self.perform=function(callback){function sendGARequest(a,b){body.ga=Base64.encode(a),body.c=Base64.encode(JSON.stringify(b)),Request.connection().getJSON(request_url,body,callback)}if("function"!=typeof callback)throw"ArgumentError: Expected to receive a callback function";var request_url=resource_url+"&campaign_key="+config.campaign_key;config.default_number_replacement&&(request_url=request_url+"&default_number="+config.default_number_replacement),config.message_replacement&&(request_url=request_url+"&message="+config.message_replacement);var body=new Object,uri=document.location.href;body.u=Base64.encode(uri),body.st=Base64.encode(tags_to_script_tags(config.number_matching_tags));var ou=Cookies.get("CallPixels-ou");getParts([document.location.href]).cpreset||!ou?Cookies.set("CallPixels-ou",body.u):body.ou=ou;var ga_acct="FAILED";try{_gaq.push(function(){ga_acct=eval("_gat._getTrackerByName()._getAccount()"),sendGARequest(ga_acct,getGACookies())})}catch(e){try{ga(function(tracker){var clientId=tracker.get("clientId"),allTrackers=eval("ga.getAll()");ga_acct=allTrackers[0].get("trackingId");var ga_cookies={};ga_cookies.__utma=clientId,ga_cookies.mp="yes",sendGARequest(ga_acct,ga_cookies)})}catch(f){Request.connection().getJSON(request_url,body,callback)}}},initialize(options)};Callpixels.Base.RequestNumber=RequestNumber}(),window.Callpixels.Cache={},function(){function a(b){if("undefined"!=typeof Callpixels.Base.Data._store){var c=Callpixels.Base.Data._store.numbers;if("undefined"!=typeof c){var d={};for(var e in c){var f=c[e];"true"===f.is_active&&("undefined"==typeof d[f.campaign_key]&&(d[f.campaign_key]=[],d[f.campaign_key].ids=[],d[f.campaign_key].hashes=[]),d[f.campaign_key].ids.push(f.id),d[f.campaign_key].hashes.push(f.id_checksum))}for(var g in d){var h={ids:d[g].ids,hashes:d[g].hashes};Callpixels.Base.Request.connection().postJSON("/api/v1/numbers/ping",h,[Callpixels.Base.Model.update,b],this)}}}setTimeout(a,15e3)}var b=Callpixels.Base;Callpixels.Number=function(a){function c(a){g.store(a),g.set("is_active","true")}function d(a){return"string"==typeof a&&(a=Callpixels.Number.extract_tags_from_string(a)),{tag_values:a,ids:[e("id")],campaign_key:e("campaign_key")}}function e(a){return g.get(a)}function f(){if(g.get("is_per_visitor")===!1)throw"Error: Tried to add tags to non per-visitor number."}var g=this;g.type="numbers",g.add_tags=function(a,b){f(),g.post_data("numbers/tag",d(a),b)},g.remove_tags=function(a,b){f(),g.post_data("numbers/untag",d(a),b)},g.remove_tags_by_keys=function(a,b){f(),"string"==typeof a&&(a=a.split(","));var c={tag_keys:a,ids:[e("id")],campaign_key:e("campaign_key")};g.post_data("numbers/untag/keys",c,b)},g.clear_tags=function(a){f();var b={ids:[e("id")],campaign_key:e("campaign_key"),all:"true"};g.post_data("numbers/untag",b,a)},g.release=function(){g.set("is_active","false")},g.initiate_call=function(a,c,d){"undefined"==typeof c&&(c={}),c.dial=a,c=b.merge(g.get("id","campaign_key"),c),g.post_data("numbers/initiate_call",c,d)},c(a)},Callpixels.Number.extract_tags_from_string=function(a){for(var b={},a=a.split(","),c=0;c<a.length;c++){var d=a[c].split(":");b[d[0]]=d[1]}return b},Callpixels.Number.prototype=new Callpixels.Base.Model,a()}(),function(){var a=Callpixels.Base.RequestNumber,b=function(b){function c(a){d.store(a)}var d=this;d.type="campaigns",d.primary_key("campaign_key"),d.numbers=[],d.request_number=function(b,c){d.set("number_matching_tags",b),new a(d.get("campaign_key","number_matching_tags")).perform(function(a){var b=new Callpixels.Number(a.number);c.apply(d,[b])})},d.numbers=function(){var a=[];if("undefined"!=typeof Callpixels.Base.Data._store){var b=Callpixels.Base.Data._store.numbers;if("undefined"!=typeof b)for(var c in b){var e=b[c];d.get("campaign_key")==e.campaign_key&&a.push(new Callpixels.Number(e))}}return a},d.set_number_matching_tags=function(a){if("string"==typeof a&&(a=Callpixels.Number.extract_tags_from_string(a)),!a||"object"!=typeof a||a instanceof Array)throw"ArgumentError: Expected number_matching_tags to be an object. eg: {tag: 'value'}";return a},c(b)};b.prototype=new Callpixels.Base.Model,Callpixels.Campaign=b}();
1
+ /*! callpixels 29-01-2015 */
2
+ !function(){"undefined"==typeof window.Callpixels&&(window.Callpixels={});var a={};a.assert_required_keys=function(){for(var a=Array.prototype.slice.call(arguments),b=a.shift(),c=0;c<a.length;c++){var d=a[c];if("undefined"==typeof b||"undefined"==typeof b[d])throw"ArgumentError: Required keys are not defined: "+a.join(", ")}return b},a.merge=function(b,c){for(var d in c)try{b[d]=c[d].constructor==Object?a.merge(b[d],c[d]):c[d]}catch(e){b[d]=c[d]}return b},a.isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)},a.ieVersion=function(){return null==a._ieVersion&&(a._ieVersion=function(){for(var a=3,b=document.createElement("div"),c=b.getElementsByTagName("i");b.innerHTML="<!--[if gt IE "+ ++a+"]><i></i><![endif]-->",c[0];);return a>4?a:!1}()),(6==a._ieVersion||7==a._ieVersion)&&null==Callpixels.easyxdm_loaded&&(Callpixels.easyxdm_loaded=!1),a._ieVersion},Callpixels.Base=a}(),function(a){var b=function(a,c,d){return 1===arguments.length?b.get(a):b.set(a,c,d)};b._document=document,b._navigator=navigator,b.defaults={path:"/"},b.get=function(a){return b._cachedDocumentCookie!==b._document.cookie&&b._renewCache(),b._cache[a]},b.set=function(a,c,d){return d=b._getExtendedOptions(d),b._document.cookie=b._generateCookieString(a,c,d),b},b._getExtendedOptions=function(c){return{path:c&&c.path||b.defaults.path,domain:c&&c.domain||b.defaults.domain,secure:c&&c.secure!==a?c.secure:b.defaults.secure}},b._isValidDate=function(a){return"[object Date]"===Object.prototype.toString.call(a)&&!isNaN(a.getTime())},b._generateCookieString=function(a,b,c){return a=encodeURIComponent(a),b=(b+"").replace(/[^!#$&-+\--:<-\[\]-~]/g,encodeURIComponent),c=c||{},a=a+"="+b+(c.path?";path="+c.path:""),a+=c.domain?";domain="+c.domain:"",a+=c.secure?";secure":""},b._getCookieObjectFromString=function(c){var d={};c=c?c.split("; "):[];for(var e=0;e<c.length;e++){var f=b._getKeyValuePairFromCookieString(c[e]);d[f.key]===a&&(d[f.key]=f.value)}return d},b._getKeyValuePairFromCookieString=function(a){var b=a.indexOf("="),b=0>b?a.length:b;return{key:decodeURIComponent(a.substr(0,b)),value:decodeURIComponent(a.substr(b+1))}},b._renewCache=function(){b._cache=b._getCookieObjectFromString(b._document.cookie),b._cachedDocumentCookie=b._document.cookie},b._areEnabled=function(){return b._navigator.cookieEnabled||"1"===b.set("cookies.js",1).get("cookies.js")},b.enabled=b._areEnabled(),"function"==typeof define&&define.amd?define(function(){return b}):"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=b),exports.Cookies=b):b,Callpixels.Base.Cookies=b}(),function(){var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="};Base64.encode=function(a){var b,c,d,e,f,g,h,i="",j=0;for(a=Base64._utf8_encode(a);j<a.length;)b=a.charCodeAt(j++),c=a.charCodeAt(j++),d=a.charCodeAt(j++),e=b>>2,f=(3&b)<<4|c>>4,g=(15&c)<<2|d>>6,h=63&d,isNaN(c)?g=h=64:isNaN(d)&&(h=64),i=i+Base64._keyStr.charAt(e)+Base64._keyStr.charAt(f)+Base64._keyStr.charAt(g)+Base64._keyStr.charAt(h);return i},Base64.decode=function(a){var b,c,d,e,f,g,h,i="",j=0;for(a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");j<a.length;)e=Base64._keyStr.indexOf(a.charAt(j++)),f=Base64._keyStr.indexOf(a.charAt(j++)),g=Base64._keyStr.indexOf(a.charAt(j++)),h=Base64._keyStr.indexOf(a.charAt(j++)),b=e<<2|f>>4,c=(15&f)<<4|g>>2,d=(3&g)<<6|h,i+=String.fromCharCode(b),64!=g&&(i+=String.fromCharCode(c)),64!=h&&(i+=String.fromCharCode(d));return i=Base64._utf8_decode(i)},Base64._utf8_encode=function(string){string=string.replace(eval("/\\r\\n/g"),eval("String('\\n')"));for(var utftext="",n=0;n<string.length;n++){var c=string.charCodeAt(n);128>c?utftext+=String.fromCharCode(c):c>127&&2048>c?(utftext+=String.fromCharCode(c>>6|192),utftext+=String.fromCharCode(63&c|128)):(utftext+=String.fromCharCode(c>>12|224),utftext+=String.fromCharCode(c>>6&63|128),utftext+=String.fromCharCode(63&c|128))}return utftext},Base64._utf8_decode=function(a){for(var b="",c=0,d=c1=c2=0;c<a.length;)d=a.charCodeAt(c),128>d?(b+=String.fromCharCode(d),c++):d>191&&224>d?(c2=a.charCodeAt(c+1),b+=String.fromCharCode((31&d)<<6|63&c2),c+=2):(c2=a.charCodeAt(c+1),c3=a.charCodeAt(c+2),b+=String.fromCharCode((15&d)<<12|(63&c2)<<6|63&c3),c+=3);return b},Callpixels.Base.Base64=Base64}(),function(){var a=Callpixels.Base,b=function(b){function c(){a.assert_required_keys(b,"type","primary_key"),"undefined"==typeof Callpixels.Base.Data._store[b.type]&&(Callpixels.Base.Data._store[b.type]={}),"undefined"==typeof Callpixels.Base.Data._store[b.type][b.primary_key]&&(Callpixels.Base.Data._store[b.type][b.primary_key]={})}var d=this;d.get=function(){var a={};if("undefined"==typeof arguments[0])a=Callpixels.Base.Data._store[b.type][b.primary_key];else if(1===arguments.length)a=Callpixels.Base.Data._store[b.type][b.primary_key][arguments[0]];else for(var c=0;c<arguments.length;c++){var d=arguments[c];a[d]=Callpixels.Base.Data._store[b.type][b.primary_key][d]}return a},d.set=function(a,c){return Callpixels.Base.Data._store[b.type][b.primary_key][a]=c,c},d.merge=function(a){for(var c in a)Callpixels.Base.Data._store[b.type][b.primary_key][c]=a[c];return a},c()};b._store={},Callpixels.Base.Data=b}(),function(){var a=Callpixels.Base,b=Callpixels.Base.Data,c=function(){this.api_host_uri="/api/v1/",this.type="model",this.primary_key=function(a){return c.primary_key(this.type,a)},this.store=function(a){if("undefined"!=typeof a){var b=this.primary_key();if("undefined"==typeof a[b])throw"ArgumentError: Expected to receive primary_key "+b;"undefined"==typeof this._store&&(this._store=new Callpixels.Base.Data({type:this.type,primary_key:a[b]})),this._store.merge(a),c.update_visitor_id(a)}return this._store},this.get_data=function(a,b){return this.connection().getJSON(this.api_host_uri+a,null,[c.update,b],this)},this.post_data=function(a,b,d){return this.connection().postJSON(this.api_host_uri+a,b,[c.update,d],this)},this.set=function(){return"function"==typeof this["set_"+arguments[0]]&&(arguments[1]=this["set_"+arguments[0]].apply(this,[arguments[1]])),this._store.set.apply(this,arguments)},this.get=function(){return this._store.get.apply(this,arguments)},this.connection=function(){return Callpixels.Base.Request.connection()}};c.inflections={number:"numbers",campaign:"campaigns"},c.update=function(d){for(var e in d){var f=e,g=d[e];if("undefined"!=typeof c.inflections[e]&&(f=c.inflections[e]),"undefined"!=typeof b._store[f])if(a.isArray(g))for(var h=0;h<g.length;h++)c.update_record(f,g[h]);else c.update_record(f,g[h])}return d},c.update_record=function(a,b){if(c.update_visitor_id(b),"undefined"!=typeof b.id){var d=c.primary_key(a);for(var e in b)Callpixels.Base.Data._store[a][b[d]][e]=b[e];return!0}return!1},c.update_visitor_id=function(a){"undefined"!=typeof a&&"undefined"!=typeof a.visitor_id&&Callpixels.Base.Cookies.set("CallPixels-vid",a.visitor_id)},c.primary_key=function(a,b){return"undefined"==typeof c.primary_keys&&(c.primary_keys={}),"undefined"==typeof c.primary_keys[a]&&(c.primary_keys[a]="id"),"undefined"!=typeof b&&(c.primary_keys[a]=b),c.primary_keys[a]},Callpixels.Base.Model=c}(),function(){var Base=window.Callpixels.Base,Cookies=window.Callpixels.Base.Cookies,Request=function(options){function initialize(a){config=Base.assert_required_keys(a,"http_prefix","addr","urlregex")}function with_ie_scripts(a){Callpixels.easyxdm_loaded?a():self.loadScript(http_prefix+"://cdn.jsdelivr.net/easyxdm/2.4.17.1/easyXDM.min.js",function(){self.loadScript(http_prefix+"://cdn.jsdelivr.net/easyxdm/2.4.17.1/json2.js",function(){Callpixels.easyxdm_loaded=!0,a()})})}var self=this,config={};self.getJSON=function(a,b,c,d){"function"==typeof c&&(c=[c]),"undefined"==typeof d&&(d=self);var e=function(){self.apiRequest(a,function(a){response=JSON.parse(a);for(var b in c)"function"==typeof c[b]&&c[b].apply(d,[response])},b)};6==Base.ieVersion()||7==Base.ieVersion()?with_ie_scripts(e):e()},self.postJSON=function(){return self.getJSON.apply(this,arguments)},self.apiRequest=function(request_uri,callbackFunctions,payload){function ignored(){}function runCallbacks(a){for(var b in callbackFunctions)"function"==typeof callbackFunctions[b]&&callbackFunctions[b](a)}function forwardResponse(){runCallbacks(xdr.responseText)}function sendXdm(){var remote=http_prefix+"://"+addr+"/ie_provider",swf=http_prefix+"://"+addr+"/easyxdm.swf",rpc=eval('new window.easyXDM.Rpc({ remote: "'+remote+'", swf: "'+swf+'"},{remote: {request: {}}});');rpc.request({url:"/"+request_url.match(urlregex)[1],method:"POST",data:payload},function(a){runCallbacks(a.data)})}var http_prefix=config.http_prefix,addr=config.addr,urlregex=eval(config.urlregex),request_url=http_prefix+"://"+addr+request_uri;if(payload&&"undefined"!=typeof Cookies.get("CallPixels-vid")&&"null"!==Cookies.get("CallPixels-vid")&&(payload.visitor_id=Cookies.get("CallPixels-vid")),"function"==typeof callbackFunctions&&(callbackFunctions=[callbackFunctions]),window.XDomainRequest){var xdr=new XDomainRequest;xdr.onload=forwardResponse,xdr.onprogress=ignored,xdr.onerror=ignored,xdr.ontimeout=ignored,xdr.timeout=3e4,payload?(xdr.open("post",request_url),xdr.send(self.buildPost(payload))):(xdr.open("get",request_url),xdr.send())}else if(6==Base.ieVersion()||7==Base.ieVersion())with_ie_scripts(sendXdm);else{var request=new XMLHttpRequest;payload?(request.open("POST",request_url,!1),request.setRequestHeader("Content-Type","application/json"),request.send(JSON.stringify(payload))):(request.open("GET",request_url,!1),request.send()),runCallbacks(request.responseText)}},self.buildPost=function(a){var b="";for(var c in a)b+=c+"="+a[c]+"&";return b},self.loadScript=function(a,b){var c=document.getElementsByTagName("script")[0],d=document.createElement("script");d.type="text/javascript",d.async=!1,d.src=a;var e=function(a,b){"loaded"==a.readyState||"complete"==a.readyState?b():setTimeout(function(){e(a,b)},100)};"function"==typeof b&&("undefined"!=typeof d.addEventListener?d.addEventListener("load",b,!1):d.onreadystatechange=function(){d.onreadystatechange=null,e(d,b)}),c.parentNode.insertBefore(d,c)},initialize(options),self.config=config};Request.connection=function(){return"undefined"==typeof window.Callpixels._connection&&(window.Callpixels._connection=new Callpixels.Base.Request({addr:"callpixels.com",http_prefix:"http",urlregex:"/\\/\\/[^\\/]*\\/(.*)/"})),window.Callpixels._connection},Callpixels.Base.Request=Request}(),function(){function tags_to_script_tags(a){var b="";for(var c in a){var d=a[c];b=b+"&"+c+"="+d}return b}var Base=Callpixels.Base,Cookies=Callpixels.Base.Cookies,Base64=Callpixels.Base.Base64,Request=Callpixels.Base.Request,RequestNumber=function(options){function initialize(a){config=Base.assert_required_keys(a,"campaign_key")}function getParts(a){for(var b={},c=0;c<a.length;c++){var d=getUrlParts(a[c]);for(var e in d)b[e]=d[e]}return b}function getUrlParts(url){var objURL=new Object;try{url=url.match(eval("/\\?(.*)/"))[0]}catch(e){return objURL}return url.replace(new RegExp("([^?=&]+)(=([^&]*))?","g"),function(a,b,c,d){objURL[b.toLowerCase()]=d}),objURL}function getGACookies(){var a=["__utma","__utmb","__utmc","__utmz","__utmv"],b=new Object;for(var c in a){var d=extractCookie(a[c]);if(!(d||c>0))break;d&&(b[a[c]]=d)}return b}function extractCookie(a){var b=new RegExp(a+"=([^;]*)","g");try{return b.exec(document.cookie)[1]}catch(c){return!1}}function findOne(a,b){for(var c in b)for(var d in a)if(d==b[c])return a[d];return!1}var self=this,config={},resource_url="/api/v1/numbers?";self.perform=function(callback){function sendGARequest(a,b){body.ga=Base64.encode(a),body.c=Base64.encode(JSON.stringify(b)),Request.connection().getJSON(request_url,body,callback)}if("function"!=typeof callback)throw"ArgumentError: Expected to receive a callback function";var request_url=resource_url+"&campaign_key="+config.campaign_key;config.default_number_replacement&&(request_url=request_url+"&default_number="+config.default_number_replacement),config.message_replacement&&(request_url=request_url+"&message="+config.message_replacement);var body=new Object,uri=document.location.href;body.u=Base64.encode(uri),body.st=Base64.encode(tags_to_script_tags(config.number_matching_tags));var ou=Cookies.get("CallPixels-ou");getParts([document.location.href]).cpreset||!ou?Cookies.set("CallPixels-ou",body.u):body.ou=ou;var ga_acct="FAILED";try{_gaq.push(function(){ga_acct=eval("_gat._getTrackerByName()._getAccount()"),sendGARequest(ga_acct,getGACookies())})}catch(e){try{ga(function(tracker){var clientId=tracker.get("clientId"),allTrackers=eval("ga.getAll()");ga_acct=allTrackers[0].get("trackingId");var ga_cookies={};ga_cookies.__utma=clientId,ga_cookies.mp="yes",sendGARequest(ga_acct,ga_cookies)})}catch(f){Request.connection().getJSON(request_url,body,callback)}}},initialize(options)};Callpixels.Base.RequestNumber=RequestNumber}(),window.Callpixels.Cache={},function(){function a(b){if("undefined"!=typeof Callpixels.Base.Data._store){var c=Callpixels.Base.Data._store.numbers;if("undefined"!=typeof c){var d={};for(var e in c){var f=c[e];"true"===f.is_active&&("undefined"==typeof d[f.campaign_key]&&(d[f.campaign_key]=[],d[f.campaign_key].ids=[],d[f.campaign_key].hashes=[]),d[f.campaign_key].ids.push(f.id),d[f.campaign_key].hashes.push(f.id_checksum))}for(var g in d){var h={ids:d[g].ids,hashes:d[g].hashes};Callpixels.Base.Request.connection().postJSON("/api/v1/numbers/ping",h,[Callpixels.Base.Model.update,b],this)}}}setTimeout(a,15e3)}var b=Callpixels.Base;Callpixels.Number=function(a){function c(a){g.store(a),g.set("is_active","true")}function d(a){return"string"==typeof a&&(a=Callpixels.Number.extract_tags_from_string(a)),{tag_values:a,ids:[e("id")],campaign_key:e("campaign_key")}}function e(a){return g.get(a)}function f(){if(g.get("is_per_visitor")===!1)throw"Error: Tried to add tags to non per-visitor number."}var g=this;g.type="numbers",g.add_tags=function(a,b){f(),g.post_data("numbers/tag",d(a),b)},g.remove_tags=function(a,b){f(),g.post_data("numbers/untag",d(a),b)},g.remove_tags_by_keys=function(a,b){f(),"string"==typeof a&&(a=a.split(","));var c={tag_keys:a,ids:[e("id")],campaign_key:e("campaign_key")};g.post_data("numbers/untag/keys",c,b)},g.clear_tags=function(a){f();var b={ids:[e("id")],campaign_key:e("campaign_key"),all:"true"};g.post_data("numbers/untag",b,a)},g.release=function(){g.set("is_active","false")},g.initiate_call=function(a,c,d){"undefined"==typeof c&&(c={}),c.dial=a,c=b.merge(g.get("id","campaign_key"),c),g.post_data("numbers/initiate_call",c,d)},c(a)},Callpixels.Number.extract_tags_from_string=function(a){for(var b={},a=a.split(","),c=0;c<a.length;c++){var d=a[c].split(":");b[d[0]]=d[1]}return b},Callpixels.Number.prototype=new Callpixels.Base.Model,a()}(),function(){var a=Callpixels.Base.RequestNumber,b=function(b){function c(a){d.store(a)}var d=this;d.type="campaigns",d.primary_key("campaign_key"),d.numbers=[],d.request_number=function(b,c,e){d.set("number_matching_tags",b),new a(d.get("campaign_key","number_matching_tags")).perform(function(a){if("undefined"!=typeof a&&"undefined"!=typeof a.number&&""!==a.number){var b=new Callpixels.Number(a.number);c.apply(d,[b])}else"function"==typeof e&&e.apply(d,[a])})},d.numbers=function(){var a=[];if("undefined"!=typeof Callpixels.Base.Data._store){var b=Callpixels.Base.Data._store.numbers;if("undefined"!=typeof b)for(var c in b){var e=b[c];d.get("campaign_key")==e.campaign_key&&a.push(new Callpixels.Number(e))}}return a},d.set_number_matching_tags=function(a){if("string"==typeof a&&(a=Callpixels.Number.extract_tags_from_string(a)),!a||"object"!=typeof a||a instanceof Array)throw"ArgumentError: Expected number_matching_tags to be an object. eg: {tag: 'value'}";return a},c(b)};b.prototype=new Callpixels.Base.Model,Callpixels.Campaign=b}();
@@ -227,7 +227,7 @@
227
227
  <dl>
228
228
 
229
229
  <dt>
230
- <h4 class="name" id="request_number"><span class="type-signature"></span>request_number<span class="signature">(tags, callback)</span><span class="type-signature"></span></h4>
230
+ <h4 class="name" id="request_number"><span class="type-signature"></span>request_number<span class="signature">(tags, callback, error_callback)</span><span class="type-signature"></span></h4>
231
231
 
232
232
 
233
233
  </dt>
@@ -308,7 +308,30 @@
308
308
 
309
309
 
310
310
 
311
- <td class="description last">Callback fired after the request completes.</td>
311
+ <td class="description last">Callback fired if the request completes successfully.</td>
312
+ </tr>
313
+
314
+
315
+
316
+ <tr>
317
+
318
+ <td class="name"><code>error_callback</code></td>
319
+
320
+
321
+ <td class="type">
322
+
323
+
324
+ <span class="param-type">function</span>
325
+
326
+
327
+
328
+ </td>
329
+
330
+
331
+
332
+
333
+
334
+ <td class="description last">Callback fired if the request raises an error.</td>
312
335
  </tr>
313
336
 
314
337
 
@@ -368,7 +391,9 @@
368
391
 
369
392
  <pre class="prettyprint"><code>campaign.request_number({calling_about: 'support'}, function (number) {
370
393
  alert(number.get('number'))
371
- });</code></pre>
394
+ }, function(response){
395
+ alert('something went wrong: ' + response);
396
+ };</code></pre>
372
397
 
373
398
 
374
399
  </dd>
@@ -395,7 +420,7 @@
395
420
  <br clear="both">
396
421
 
397
422
  <footer>
398
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Wed Aug 13 2014 21:32:34 GMT-0400 (EDT)
423
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Thu Jan 29 2015 13:09:13 GMT-0500 (EST)
399
424
  </footer>
400
425
 
401
426
  <script> prettyPrint(); </script>
@@ -1420,7 +1420,7 @@ with per-visitor numbers enabled.
1420
1420
  <br clear="both">
1421
1421
 
1422
1422
  <footer>
1423
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Wed Aug 13 2014 21:32:34 GMT-0400 (EDT)
1423
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Thu Jan 29 2015 13:09:13 GMT-0500 (EST)
1424
1424
  </footer>
1425
1425
 
1426
1426
  <script> prettyPrint(); </script>
@@ -54,21 +54,31 @@
54
54
  * @function request_number
55
55
  * @instance
56
56
  * @param {Object} tags - A collection of tags as key-value pairs. The number returned will match these tags.
57
- * @param {getNumberCallback} callback - Callback fired after the request completes.
57
+ * @param {getNumberCallback} callback - Callback fired if the request completes successfully.
58
+ * @param {Function} error_callback - Callback fired if the request raises an error.
58
59
  * @example
59
60
  * campaign.request_number({calling_about: 'support'}, function (number) {
60
61
  * alert(number.get('number'))
61
- * });
62
+ * }, function(response){
63
+ * alert('something went wrong: ' + response);
64
+ * };
62
65
  */
63
- self.request_number = function (tags, callback) {
66
+ self.request_number = function (tags, callback, error_callback) {
64
67
  // assign the tags (this is important since it runs it through set_number_matching_tags)
65
68
  self.set('number_matching_tags', tags);
66
69
  // request the number
67
70
  new RequestNumber(self.get('campaign_key', 'number_matching_tags')).perform(function (data) {
68
- // initialize number
69
- var number = new Callpixels.Number(data.number);
70
- // call callback
71
- callback.apply(self, [number]);
71
+ // did callpixels return a valid number?
72
+ if (typeof(data) !== 'undefined' &amp;&amp; typeof(data.number) !== 'undefined' &amp;&amp; data.number !== '') {
73
+ // initialize number
74
+ var number = new Callpixels.Number(data.number);
75
+ // call callback
76
+ callback.apply(self, [number]);
77
+ }
78
+ // otherwise fire the error callback
79
+ else if (typeof(error_callback) === 'function') {
80
+ error_callback.apply(self, [data]);
81
+ }
72
82
  });
73
83
  };
74
84
  /**
@@ -128,7 +138,7 @@
128
138
  <br clear="both">
129
139
 
130
140
  <footer>
131
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Wed Aug 13 2014 21:32:34 GMT-0400 (EDT)
141
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Thu Jan 29 2015 13:09:13 GMT-0500 (EST)
132
142
  </footer>
133
143
 
134
144
  <script> prettyPrint(); </script>
@@ -180,7 +180,7 @@
180
180
 
181
181
  <dt class="tag-source">Source:</dt>
182
182
  <dd class="tag-source"><ul class="dummy"><li>
183
- <a href="campaign.js.html">campaign.js</a>, <a href="campaign.js.html#line47">line 47</a>
183
+ <a href="campaign.js.html">campaign.js</a>, <a href="campaign.js.html#line57">line 57</a>
184
184
  </li></ul></dd>
185
185
 
186
186
 
@@ -227,7 +227,7 @@
227
227
  <br clear="both">
228
228
 
229
229
  <footer>
230
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Wed Aug 13 2014 21:32:34 GMT-0400 (EDT)
230
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Thu Jan 29 2015 13:09:13 GMT-0500 (EST)
231
231
  </footer>
232
232
 
233
233
  <script> prettyPrint(); </script>
@@ -58,7 +58,7 @@
58
58
  <br clear="both">
59
59
 
60
60
  <footer>
61
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Wed Aug 13 2014 21:32:34 GMT-0400 (EDT)
61
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Thu Jan 29 2015 13:09:13 GMT-0500 (EST)
62
62
  </footer>
63
63
 
64
64
  <script> prettyPrint(); </script>
@@ -246,7 +246,7 @@
246
246
  <br clear="both">
247
247
 
248
248
  <footer>
249
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Wed Aug 13 2014 21:32:34 GMT-0400 (EDT)
249
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Thu Jan 29 2015 13:09:13 GMT-0500 (EST)
250
250
  </footer>
251
251
 
252
252
  <script> prettyPrint(); </script>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: callpixelsjs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Hilscher
@@ -73,11 +73,16 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - Gruntfile.js
76
77
  - LICENSE
77
78
  - README.md
79
+ - Rakefile
80
+ - config/README
81
+ - config/jsdocs.json
78
82
  - lib/callpixelsjs/compile.rb
79
83
  - lib/callpixelsjs/rails.rb
80
84
  - lib/callpixelsjs/rails/version.rb
85
+ - package.json
81
86
  - vendor/assets/javascripts/callpixels.js
82
87
  - vendor/assets/javascripts/callpixels.min.js
83
88
  - vendor/documentation/javascript/v1/Callpixels.Campaign.html