callpixelsjs-rails 0.0.8 → 0.0.9

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: 5f6287796f175818600067aa9594990e32aeae7e
4
- data.tar.gz: ab56843df5e9f583836c244b70535d56f1053eb5
3
+ metadata.gz: c6a41733ab787f91ab95a3855af0b2e5544acaf6
4
+ data.tar.gz: 21a4460eeab8a0f36c9a18665e1c4efdb468601b
5
5
  SHA512:
6
- metadata.gz: 58ae9e3ff3ea6fdab9f85240e307b2d5e327a52fdce62f6e080c65cf022ee0d898c7be6f499e018c98aa319762d6255e7d51f0177686197b2c9d277f480d8963
7
- data.tar.gz: 23d84cb95ad22db604a4bfa24864a2748cdd3265a7ca05f3ee7c13070db8afefcc8128530e0534f5dcb896f50645e21e26f5d961d26f5e2303c80602186f566f
6
+ metadata.gz: 53756d5317a7b60b72d0b235e81d2dbc6da46a0c668b7fbf6ffb48322b65600cf8726dbe61b2e32998518aef4e97b53864bf385e1668194bf1724853e5bb2da3
7
+ data.tar.gz: 32683275156731330c843f267b49342af2edb88c653feaf9f9dc47b2a7935b7868031310aeb770ed1f1e87208af1fb70afe1b632ee293d168a373bef1e10eff6
@@ -1,5 +1,5 @@
1
1
  module Callpixelsjs
2
2
  module Rails
3
- VERSION = "0.0.8"
3
+ VERSION = "0.0.9"
4
4
  end
5
5
  end
@@ -0,0 +1,126 @@
1
+ // http://www.webtoolkit.info/javascript-base64.html#.U-qwzYBdUwQ
2
+ (function () {
3
+ var Base64 = {
4
+ _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
5
+ };
6
+ // public method for encoding
7
+ Base64.encode = function (input) {
8
+ var output = "";
9
+ var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
10
+ var i = 0;
11
+
12
+ input = Base64._utf8_encode(input);
13
+
14
+ while (i < input.length) {
15
+
16
+ chr1 = input.charCodeAt(i++);
17
+ chr2 = input.charCodeAt(i++);
18
+ chr3 = input.charCodeAt(i++);
19
+
20
+ enc1 = chr1 >> 2;
21
+ enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
22
+ enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
23
+ enc4 = chr3 & 63;
24
+
25
+ if (isNaN(chr2)) {
26
+ enc3 = enc4 = 64;
27
+ } else if (isNaN(chr3)) {
28
+ enc4 = 64;
29
+ }
30
+ output = output +
31
+ Base64._keyStr.charAt(enc1) + Base64._keyStr.charAt(enc2) +
32
+ Base64._keyStr.charAt(enc3) + Base64._keyStr.charAt(enc4);
33
+
34
+ }
35
+ return output;
36
+ };
37
+ Base64.decode = function (input) {
38
+ var output = "";
39
+ var chr1, chr2, chr3;
40
+ var enc1, enc2, enc3, enc4;
41
+ var i = 0;
42
+
43
+ input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
44
+
45
+ while (i < input.length) {
46
+
47
+ enc1 = Base64._keyStr.indexOf(input.charAt(i++));
48
+ enc2 = Base64._keyStr.indexOf(input.charAt(i++));
49
+ enc3 = Base64._keyStr.indexOf(input.charAt(i++));
50
+ enc4 = Base64._keyStr.indexOf(input.charAt(i++));
51
+
52
+ chr1 = (enc1 << 2) | (enc2 >> 4);
53
+ chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
54
+ chr3 = ((enc3 & 3) << 6) | enc4;
55
+
56
+ output = output + String.fromCharCode(chr1);
57
+
58
+ if (enc3 != 64) {
59
+ output = output + String.fromCharCode(chr2);
60
+ }
61
+ if (enc4 != 64) {
62
+ output = output + String.fromCharCode(chr3);
63
+ }
64
+
65
+ }
66
+
67
+ output = Base64._utf8_decode(output);
68
+
69
+ return output;
70
+ };
71
+ Base64._utf8_encode = function (string) {
72
+ //REGEX_2: /\r\n/g NEWLINE: "\n"
73
+ string = string.replace(eval("/\\r\\n/g"),eval("String('\\n')"));
74
+ var utftext = "";
75
+
76
+ for (var n = 0; n < string.length; n++) {
77
+
78
+ var c = string.charCodeAt(n);
79
+
80
+ if (c < 128) {
81
+ utftext += String.fromCharCode(c);
82
+ }
83
+ else if ((c > 127) && (c < 2048)) {
84
+ utftext += String.fromCharCode((c >> 6) | 192);
85
+ utftext += String.fromCharCode((c & 63) | 128);
86
+ }
87
+ else {
88
+ utftext += String.fromCharCode((c >> 12) | 224);
89
+ utftext += String.fromCharCode(((c >> 6) & 63) | 128);
90
+ utftext += String.fromCharCode((c & 63) | 128);
91
+ }
92
+
93
+ }
94
+
95
+ return utftext;
96
+ };
97
+ Base64._utf8_decode = function (utftext) {
98
+ var string = "";
99
+ var i = 0;
100
+ var c = c1 = c2 = 0;
101
+
102
+ while (i < utftext.length) {
103
+
104
+ c = utftext.charCodeAt(i);
105
+
106
+ if (c < 128) {
107
+ string += String.fromCharCode(c);
108
+ i++;
109
+ }
110
+ else if ((c > 191) && (c < 224)) {
111
+ c2 = utftext.charCodeAt(i + 1);
112
+ string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
113
+ i += 2;
114
+ }
115
+ else {
116
+ c2 = utftext.charCodeAt(i + 1);
117
+ c3 = utftext.charCodeAt(i + 2);
118
+ string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
119
+ i += 3;
120
+ }
121
+
122
+ }
123
+ return string;
124
+ };
125
+ Callpixels.Base.Base64 = Base64;
126
+ })();
@@ -0,0 +1,59 @@
1
+ // https://github.com/evertton/cookiejs
2
+ (function (f) {
3
+ var a = function (b, c, d) {
4
+ return 1 === arguments.length ? a.get(b) : a.set(b, c, d)
5
+ };
6
+ a._document = document;
7
+ a._navigator = navigator;
8
+ a.defaults = {path: "/"};
9
+ a.get = function (b) {
10
+ a._cachedDocumentCookie !== a._document.cookie && a._renewCache();
11
+ return a._cache[b]
12
+ };
13
+ a.set = function (b, c, d) {
14
+ d = a._getExtendedOptions(d);
15
+ a._document.cookie = a._generateCookieString(b, c, d);
16
+ return a
17
+ };
18
+ a._getExtendedOptions = function (b) {
19
+ return{path: b && b.path || a.defaults.path, domain: b && b.domain || a.defaults.domain, secure: b && b.secure !== f ? b.secure :
20
+ a.defaults.secure}
21
+ };
22
+ a._isValidDate = function (a) {
23
+ return"[object Date]" === Object.prototype.toString.call(a) && !isNaN(a.getTime())
24
+ };
25
+ a._generateCookieString = function (a, c, d) {
26
+ a = encodeURIComponent(a);
27
+ c = (c + "").replace(/[^!#$&-+\--:<-\[\]-~]/g, encodeURIComponent);
28
+ d = d || {};
29
+ a = a + "=" + c + (d.path ? ";path=" + d.path : "");
30
+ a += d.domain ? ";domain=" + d.domain : "";
31
+ return a += d.secure ? ";secure" : ""
32
+ };
33
+ a._getCookieObjectFromString = function (b) {
34
+ var c = {};
35
+ b = b ? b.split("; ") : [];
36
+ for (var d = 0; d < b.length; d++) {
37
+ var e = a._getKeyValuePairFromCookieString(b[d]);
38
+ c[e.key] === f && (c[e.key] = e.value)
39
+ }
40
+ return c
41
+ };
42
+ a._getKeyValuePairFromCookieString = function (a) {
43
+ var c = a.indexOf("="), c = 0 > c ? a.length : c;
44
+ return{key: decodeURIComponent(a.substr(0, c)), value: decodeURIComponent(a.substr(c + 1))}
45
+ };
46
+ a._renewCache = function () {
47
+ a._cache = a._getCookieObjectFromString(a._document.cookie);
48
+ a._cachedDocumentCookie = a._document.cookie
49
+ };
50
+ a._areEnabled = function () {
51
+ return a._navigator.cookieEnabled || "1" === a.set("cookies.js", 1).get("cookies.js")
52
+ };
53
+ a.enabled = a._areEnabled();
54
+ "function" === typeof define &&
55
+ define.amd ? define(function () {
56
+ return a
57
+ }) : "undefined" !== typeof exports ? ("undefined" !== typeof module && module.exports && (exports = module.exports = a), exports.Cookies = a) : a;
58
+ Callpixels.Base.Cookies = a;
59
+ })();
@@ -0,0 +1,81 @@
1
+ (function () {
2
+ // Dependencies
3
+ var Base = Callpixels.Base;
4
+ /**
5
+ * @constructor
6
+ * @memberof Callpixels.Base
7
+ * @param {Object} config - Configuration hash
8
+ * @param {String} config.type - The data type
9
+ * @param {Numeric} config.primary_key - The primary_key
10
+ */
11
+ var Data = function (config) {
12
+
13
+ function initialize() {
14
+ Base.assert_required_keys(config, 'type', 'primary_key');
15
+ if (typeof Callpixels.Base.Data._store[config.type] === 'undefined') {
16
+ Callpixels.Base.Data._store[config.type] = {};
17
+ }
18
+ if (typeof Callpixels.Base.Data._store[config.type][config.primary_key] === 'undefined') {
19
+ Callpixels.Base.Data._store[config.type][config.primary_key] = {};
20
+ }
21
+ }
22
+
23
+ var self = this;
24
+
25
+ /**
26
+ * Request data from the host
27
+ * @memberOf Callpixels.Base.Data
28
+ * @function get
29
+ * @instance
30
+ * @param {String} key - The key to retrieve
31
+ * @returns {*}
32
+ */
33
+ self.get = function () {
34
+ var output = {};
35
+ if (typeof arguments[0] === 'undefined') {
36
+ output = Callpixels.Base.Data._store[config.type][config.primary_key];
37
+ } else if (arguments.length === 1) {
38
+ output = Callpixels.Base.Data._store[config.type][config.primary_key][arguments[0]];
39
+ } else {
40
+ for (var i = 0; i < arguments.length; i++) {
41
+ var key = arguments[i];
42
+ output[key] = Callpixels.Base.Data._store[config.type][config.primary_key][key];
43
+ }
44
+ }
45
+ return output;
46
+ };
47
+
48
+ /**
49
+ * Request data from the host
50
+ * @memberOf Callpixels.Base.Data
51
+ * @function set
52
+ * @instance
53
+ * @param {String} key - The key to retrieve
54
+ * @param {String} value - The value to assign
55
+ * @returns {*}
56
+ */
57
+ self.set = function (key, value) {
58
+ Callpixels.Base.Data._store[config.type][config.primary_key][key] = value;
59
+ return value;
60
+ };
61
+
62
+ /**
63
+ * Merge data
64
+ * @memberOf Callpixels.Base.Data
65
+ * @function set
66
+ * @instance
67
+ * @param {String} object - The object to merge
68
+ * @returns {*}
69
+ */
70
+ self.merge = function (object) {
71
+ for (var key in object) {
72
+ Callpixels.Base.Data._store[config.type][config.primary_key][key] = object[key];
73
+ }
74
+ return object;
75
+ };
76
+
77
+ initialize();
78
+ };
79
+ Data._store = {};
80
+ Callpixels.Base.Data = Data;
81
+ })();
@@ -0,0 +1,55 @@
1
+ (function () {
2
+ // ensure namespace is present
3
+ if (typeof window.Callpixels === 'undefined') window.Callpixels = {};
4
+ var Base = {};
5
+ // define helpers
6
+ Base.assert_required_keys = function () {
7
+ var args = Array.prototype.slice.call(arguments);
8
+ var object = args.shift();
9
+ for (var i = 0; i < args.length; i++) {
10
+ var key = args[i];
11
+ if (typeof object === 'undefined' || typeof object[key] === 'undefined') {
12
+ throw "ArgumentError: Required keys are not defined: " + args.join(', ');
13
+ }
14
+ }
15
+ return object;
16
+ };
17
+ Base.merge = function (obj1, obj2) {
18
+ for (var p in obj2) {
19
+ try {
20
+ if (obj2[p].constructor == Object) {
21
+ obj1[p] = Base.merge(obj1[p], obj2[p]);
22
+ } else {
23
+ obj1[p] = obj2[p];
24
+ }
25
+ } catch (e) {
26
+ obj1[p] = obj2[p];
27
+ }
28
+ }
29
+ return obj1;
30
+ };
31
+ Base.isArray = function (arg) {
32
+ return Object.prototype.toString.call(arg) === '[object Array]';
33
+ };
34
+ Base.ieVersion = function () {
35
+ if (Base._ieVersion == null) {
36
+ Base._ieVersion = (function () {
37
+ var v = 3,
38
+ div = document.createElement('div'),
39
+ all = div.getElementsByTagName('i');
40
+
41
+ while (
42
+ div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
43
+ all[0]
44
+ ) {
45
+ }
46
+ return v > 4 ? v : false;
47
+ }());
48
+ }
49
+ if (Base._ieVersion == 6 || Base._ieVersion == 7) {
50
+ if (Callpixels['easyxdm_loaded'] == null) Callpixels['easyxdm_loaded'] = false;
51
+ }
52
+ return Base._ieVersion;
53
+ };
54
+ Callpixels.Base = Base;
55
+ })();
@@ -0,0 +1,113 @@
1
+ (function () {
2
+ // Dependencies
3
+ var Base = Callpixels.Base;
4
+ var Data = Callpixels.Base.Data;
5
+
6
+ /**
7
+ * @constructor
8
+ * @memberof Callpixels.Base
9
+ */
10
+ var Model = function () {
11
+
12
+ this.api_host_uri = '/api/v1/';
13
+ this.type = 'model';
14
+
15
+ this.primary_key = function (primary_key) {
16
+ return Model.primary_key(this.type, primary_key);
17
+ };
18
+
19
+ this.store = function (data) {
20
+ // do we have data to store?
21
+ if (typeof(data) !== 'undefined') {
22
+ // does the data contain the required primary_key?
23
+ var key = this.primary_key();
24
+ if (typeof(data[key]) === 'undefined') {
25
+ throw("ArgumentError: Expected to receive primary_key " + key);
26
+ }
27
+ // has a store been initialized?
28
+ else if (typeof(this._store) === 'undefined') {
29
+ this._store = new Callpixels.Base.Data({type: this.type, primary_key: data[key] });
30
+ }
31
+ // merge the data
32
+ this._store.merge(data);
33
+ // update visitor is token present
34
+ Model.update_visitor_id(data);
35
+ }
36
+ return this._store;
37
+ };
38
+
39
+ this.get_data = function (path, callback) {
40
+ return this.connection().getJSON(this.api_host_uri + path, null, [Model.update, callback], this);
41
+ };
42
+
43
+ this.post_data = function (path, data, callback) {
44
+ return this.connection().postJSON(this.api_host_uri + path, data, [Model.update, callback], this);
45
+ };
46
+
47
+ this.set = function () {
48
+ if (typeof(this["set_" + arguments[0]]) === 'function') {
49
+ arguments[1] = this["set_" + arguments[0]].apply(this, [arguments[1]]);
50
+ }
51
+ return this._store.set.apply(this, arguments);
52
+ };
53
+ this.get = function () {
54
+ return this._store.get.apply(this, arguments);
55
+ };
56
+ this.connection = function () {
57
+ return Callpixels.Base.Request.connection();
58
+ };
59
+ };
60
+ Model.inflections = {
61
+ 'number': 'numbers',
62
+ 'campaign': 'campaigns'
63
+ };
64
+ Model.update = function (data) {
65
+ for (var key in data) {
66
+ var type = key;
67
+ var value = data[key];
68
+ if (typeof Model.inflections[key] !== 'undefined') {
69
+ type = Model.inflections[key];
70
+ }
71
+ if (typeof Data._store[type] !== 'undefined') {
72
+ if (Base.isArray(value)) {
73
+ for (var i = 0; i < value.length; i++) {
74
+ Model.update_record(type, value[i]);
75
+ }
76
+ } else {
77
+ Model.update_record(type, value[i]);
78
+ }
79
+ }
80
+ }
81
+ return data;
82
+ };
83
+ Model.update_record = function (type, record) {
84
+ // update visitor is token present
85
+ Model.update_visitor_id(record);
86
+ // update data store
87
+ if (typeof record.id !== 'undefined') {
88
+ var primary_key = Model.primary_key(type);
89
+ for (var key in record) {
90
+ Callpixels.Base.Data._store[type][record[primary_key]][key] = record[key];
91
+ }
92
+ return true
93
+ } else {
94
+ return false
95
+ }
96
+ return record;
97
+ };
98
+ Model.update_visitor_id = function (record) {
99
+ if (typeof(record) !== 'undefined' && typeof(record.visitor_id) !== 'undefined') {
100
+ Callpixels.Base.Cookies.set('CallPixels-vid', record.visitor_id);
101
+ }
102
+ };
103
+ Model.primary_key = function (type, primary_key) {
104
+ if (typeof(Model.primary_keys) === 'undefined') Model.primary_keys = {};
105
+ // default key
106
+ if (typeof(Model.primary_keys[type]) === 'undefined') Model.primary_keys[type] = 'id';
107
+ // assign key if passed
108
+ if (typeof(primary_key) !== 'undefined') Model.primary_keys[type] = primary_key;
109
+ // return value
110
+ return Model.primary_keys[type];
111
+ }
112
+ Callpixels.Base.Model = Model;
113
+ })();