algoliasearch-rails 1.3.3 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e29ac47364a507c6d864668517822cffce9c2d6
4
- data.tar.gz: 66acdcd30134e3b656e03eab50400c3424853e52
3
+ metadata.gz: cdbcc449354c8cdb2735703c5084715b838b85fc
4
+ data.tar.gz: c582acfeb65aaf4bd47f27be2368b5377bb901e5
5
5
  SHA512:
6
- metadata.gz: daa6bdbe2bd086b90c710942c87474684cad0a1af44406e2a2ffdc6033baf7ef4a4eac7d9a566bab4e6b4f4a34f0d3b4a1f4ac8ff1fe3527da14ec0178a5edf1
7
- data.tar.gz: fd0ab69277ac18436e0fa3a789fd0844621360a3310d81721732234530b240d561b5c821864c55151491818244ce0fb14b80e95574456f8fdf5d7e4595698e90
6
+ metadata.gz: 05405690f066188e732cf7de198a9ece32f4cae75e635b42d7d9cad7e5d8f1d1db465d323d69b57dddb8a92fd5d79733fe95511d428880f6e6729222c1de3cb8
7
+ data.tar.gz: eadeaaa3d98e49954973397ca30533b7f1a07a3537742dd618bb2a00947026c08b35429d912c84d8aabc7007ea9409db95126878832ddda1845786b97c2a2851
data/ChangeLog CHANGED
@@ -1,5 +1,10 @@
1
1
  CHANGELOG
2
2
 
3
+ 2013-11-07 1.3.4
4
+
5
+ * updated algoliasearch to 1.1.6 (clear_index! is now a real clear, not a delete/create) and algoliasearch-client-js to 2.3.0
6
+ * restore missing ensure_init call in the ```search``` method
7
+
3
8
  2013-11-07 1.3.3
4
9
 
5
10
  * new :per_environment options suffixing index's name by the Rails environment
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gem 'json', '>= 1.5.1'
4
- gem 'algoliasearch', '>= 1.1.4'
4
+ gem 'algoliasearch', '>= 1.1.6'
5
5
 
6
6
  group :test do
7
7
  gem 'rspec', '>= 2.5.0'
data/Gemfile.lock CHANGED
@@ -24,7 +24,7 @@ GEM
24
24
  thread_safe (~> 0.1)
25
25
  tzinfo (~> 0.3.37)
26
26
  addressable (2.3.5)
27
- algoliasearch (1.1.5)
27
+ algoliasearch (1.1.6)
28
28
  curb
29
29
  arel (4.0.1)
30
30
  atomic (1.1.14)
@@ -150,7 +150,7 @@ PLATFORMS
150
150
 
151
151
  DEPENDENCIES
152
152
  activerecord (>= 3.0.7)
153
- algoliasearch (>= 1.1.4)
153
+ algoliasearch (>= 1.1.6)
154
154
  autotest
155
155
  autotest-fsevent
156
156
  autotest-growl
data/README.md CHANGED
@@ -3,6 +3,8 @@ Algolia Search for Rails
3
3
 
4
4
  This gem let you easily integrate the Algolia Search API to your favorite ORM. It's based on the [algoliasearch-client-ruby](https://github.com/algolia/algoliasearch-client-ruby) gem.
5
5
 
6
+ You might be interested in the sample Ruby on Rails application providing a ```typeahead.js```-based auto-completion and ```Google```-like instant search: [algoliasearch-rails-example](https://github.com/algolia/algoliasearch-rails-example/).
7
+
6
8
  [![Build Status](https://travis-ci.org/algolia/algoliasearch-rails.png?branch=master)](https://travis-ci.org/algolia/algoliasearch-rails) [![Gem Version](https://badge.fury.io/rb/algoliasearch-rails.png)](http://badge.fury.io/rb/algoliasearch-rails) [![Code Climate](https://codeclimate.com/github/algolia/algoliasearch-rails.png)](https://codeclimate.com/github/algolia/algoliasearch-rails)
7
9
 
8
10
 
@@ -214,7 +216,7 @@ Turns any ```input[type="text"]``` element into a typeahead, for example:
214
216
  var client = new AlgoliaSearch('YourApplicationID', 'SearchOnlyApplicationKey');
215
217
  $('input#user_email').typeahead({
216
218
  name: 'emails',
217
- remote: client.initIndex('#{Contact.index_name}').getTypeaheadTransport(),
219
+ remote: client.initIndex('<%= Contact.index_name %>').getTypeaheadTransport(),
218
220
  engine: Hogan,
219
221
  template: '{{{_highlightResult.email.value}}} ({{{_highlightResult.first_name.value}}} {{{_highlightResult.last_name.value}}})',
220
222
  valueKey: 'email'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.3
1
+ 1.3.4
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "algoliasearch-rails"
8
- s.version = "1.3.3"
8
+ s.version = "1.3.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Algolia"]
@@ -54,14 +54,14 @@ Gem::Specification.new do |s|
54
54
 
55
55
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
56
56
  s.add_runtime_dependency(%q<json>, [">= 1.5.1"])
57
- s.add_runtime_dependency(%q<algoliasearch>, [">= 1.1.4"])
57
+ s.add_runtime_dependency(%q<algoliasearch>, [">= 1.1.6"])
58
58
  s.add_development_dependency(%q<jeweler>, [">= 0"])
59
59
  s.add_development_dependency(%q<will_paginate>, [">= 2.3.15"])
60
60
  s.add_development_dependency(%q<kaminari>, [">= 0"])
61
61
  s.add_development_dependency(%q<travis>, [">= 0"])
62
62
  else
63
63
  s.add_dependency(%q<json>, [">= 1.5.1"])
64
- s.add_dependency(%q<algoliasearch>, [">= 1.1.4"])
64
+ s.add_dependency(%q<algoliasearch>, [">= 1.1.6"])
65
65
  s.add_dependency(%q<jeweler>, [">= 0"])
66
66
  s.add_dependency(%q<will_paginate>, [">= 2.3.15"])
67
67
  s.add_dependency(%q<kaminari>, [">= 0"])
@@ -69,7 +69,7 @@ Gem::Specification.new do |s|
69
69
  end
70
70
  else
71
71
  s.add_dependency(%q<json>, [">= 1.5.1"])
72
- s.add_dependency(%q<algoliasearch>, [">= 1.1.4"])
72
+ s.add_dependency(%q<algoliasearch>, [">= 1.1.6"])
73
73
  s.add_dependency(%q<jeweler>, [">= 0"])
74
74
  s.add_dependency(%q<will_paginate>, [">= 2.3.15"])
75
75
  s.add_dependency(%q<kaminari>, [">= 0"])
@@ -131,13 +131,14 @@ module AlgoliaSearch
131
131
  end
132
132
  end
133
133
 
134
- def clear_index!
134
+ def clear_index!(synchronous = false)
135
135
  ensure_init
136
- @index.delete
136
+ synchronous ? @index.clear! : @index.clear
137
137
  @index = nil
138
138
  end
139
139
 
140
140
  def search(q, settings = {})
141
+ ensure_init
141
142
  json = @index.search(q, Hash[settings.map { |k,v| [k.to_s, v.to_s] }])
142
143
  results = json['hits'].map do |hit|
143
144
  o = Object.const_get(@options[:type]).find(hit['objectID'])
@@ -1,10 +1,10 @@
1
1
  /*!
2
- * algoliasearch 2.0.1
2
+ * algoliasearch 2.3.0
3
3
  * https://github.com/algolia/algoliasearch-client-js
4
4
  * Copyright 2013 Algolia SAS; Licensed MIT
5
5
  */
6
6
 
7
- var VERSION = "2.0.1";
7
+ var VERSION = "2.3.0";
8
8
 
9
9
  var AlgoliaSearch = function(applicationID, apiKey, method, resolveDNS, hostsArray) {
10
10
  this.applicationID = applicationID;
@@ -17,7 +17,9 @@ var AlgoliaSearch = function(applicationID, apiKey, method, resolveDNS, hostsArr
17
17
  if (Math.random() > .5) {
18
18
  this.hosts.reverse();
19
19
  }
20
- if (!this._isUndefined(method) && (method === "https" || method === "HTTPS")) {
20
+ if (this._isUndefined(method) || method == null) {
21
+ this.hosts.push(("https:" == document.location.protocol ? "https" : "http") + "://" + hostsArray[i]);
22
+ } else if (method === "https" || method === "HTTPS") {
21
23
  this.hosts.push("https://" + hostsArray[i]);
22
24
  } else {
23
25
  this.hosts.push("http://" + hostsArray[i]);
@@ -120,10 +122,13 @@ AlgoliaSearch.prototype = {
120
122
  callback: callback
121
123
  });
122
124
  },
123
- addUserKeyWithValidity: function(acls, validity, callback) {
125
+ addUserKeyWithValidity: function(acls, validity, maxQueriesPerIPPerHour, maxHitsPerQuery, callback) {
124
126
  var indexObj = this;
125
127
  var aclsObject = {};
126
128
  aclsObject.acl = acls;
129
+ aclsObject.validity = validity;
130
+ aclsObject.maxQueriesPerIPPerHour = maxQueriesPerIPPerHour;
131
+ aclsObject.maxHitsPerQuery = maxHitsPerQuery;
127
132
  this._jsonRequest({
128
133
  method: "POST",
129
134
  url: "/1/indexes/" + indexObj.indexName + "/keys",
@@ -171,6 +176,7 @@ AlgoliaSearch.prototype = {
171
176
  this.indexName = indexName;
172
177
  this.as = algoliasearch;
173
178
  this.typeAheadArgs = null;
179
+ this.typeAheadPropertyName = null;
174
180
  },
175
181
  _sendQueriesBatch: function(params, callback) {
176
182
  this._jsonRequest({
@@ -417,8 +423,11 @@ AlgoliaSearch.prototype.Index.prototype = {
417
423
  this._search(params, callback);
418
424
  }
419
425
  },
420
- getTypeaheadTransport: function(args) {
426
+ getTypeaheadTransport: function(args, propertyName) {
421
427
  this.typeAheadArgs = args;
428
+ if (typeof propertyName !== "undefined") {
429
+ this.typeAheadPropertyName = propertyName;
430
+ }
422
431
  return this;
423
432
  },
424
433
  get: function(query, processRemoteData, that, cb, suggestions) {
@@ -427,12 +436,16 @@ AlgoliaSearch.prototype.Index.prototype = {
427
436
  if (success) {
428
437
  for (var i = 0; i < content.hits.length; ++i) {
429
438
  var obj = content.hits[i];
430
- var found = false;
431
439
  if (typeof obj.value === "undefined") {
432
- for (var propertyName in obj) {
433
- if (!found && obj.hasOwnProperty(propertyName) && typeof obj[propertyName] === "string") {
434
- obj.value = obj[propertyName];
435
- found = true;
440
+ if (self.typeAheadPropertyName != null && typeof obj[self.typeAheadPropertyName] !== "undefined") {
441
+ obj.value = obj[self.typeAheadPropertyName];
442
+ } else {
443
+ var found = false;
444
+ for (var propertyName in obj) {
445
+ if (!found && obj.hasOwnProperty(propertyName) && typeof obj[propertyName] === "string") {
446
+ obj.value = obj[propertyName];
447
+ found = true;
448
+ }
436
449
  }
437
450
  }
438
451
  }
@@ -459,6 +472,14 @@ AlgoliaSearch.prototype.Index.prototype = {
459
472
  }
460
473
  });
461
474
  },
475
+ clearIndex: function(callback) {
476
+ var indexObj = this;
477
+ this.as._jsonRequest({
478
+ method: "POST",
479
+ url: "/1/indexes/" + encodeURIComponent(indexObj.indexName) + "/clear",
480
+ callback: callback
481
+ });
482
+ },
462
483
  getSettings: function(callback) {
463
484
  var indexObj = this;
464
485
  this.as._jsonRequest({
@@ -511,11 +532,13 @@ AlgoliaSearch.prototype.Index.prototype = {
511
532
  callback: callback
512
533
  });
513
534
  },
514
- addUserKeyWithValidity: function(acls, validity, callback) {
535
+ addUserKeyWithValidity: function(acls, validity, maxQueriesPerIPPerHour, maxHitsPerQuery, callback) {
515
536
  var indexObj = this;
516
537
  var aclsObject = {};
517
538
  aclsObject.acl = acls;
518
539
  aclsObject.validity = validity;
540
+ aclsObject.maxQueriesPerIPPerHour = maxQueriesPerIPPerHour;
541
+ aclsObject.maxHitsPerQuery = maxHitsPerQuery;
519
542
  this.as._jsonRequest({
520
543
  method: "POST",
521
544
  url: "/1/indexes/" + encodeURIComponent(indexObj.indexName) + "/keys",
@@ -540,5 +563,6 @@ AlgoliaSearch.prototype.Index.prototype = {
540
563
  indexName: null,
541
564
  cache: {},
542
565
  typeAheadArgs: null,
566
+ typeAheadPropertyName: null,
543
567
  emptyConstructor: function() {}
544
568
  };
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * algoliasearch 2.0.1
2
+ * algoliasearch 2.3.0
3
3
  * https://github.com/algolia/algoliasearch-client-js
4
4
  * Copyright 2013 Algolia SAS; Licensed MIT
5
5
  */
6
6
 
7
- var VERSION="2.0.1",AlgoliaSearch=function(a,b,c,d,e){this.applicationID=a,this.apiKey=b,this._isUndefined(e)&&(e=[a+"-1.algolia.io",a+"-2.algolia.io",a+"-3.algolia.io"]),this.hosts=[];for(var f=0;f<e.length;++f)Math.random()>.5&&this.hosts.reverse(),this._isUndefined(c)||"https"!==c&&"HTTPS"!==c?this.hosts.push("http://"+e[f]):this.hosts.push("https://"+e[f]);Math.random()>.5&&this.hosts.reverse(),(this._isUndefined(d)||d)&&this._jsonRequest({method:"GET",url:"/1/isalive"})};AlgoliaSearch.prototype={deleteIndex:function(a,b){this._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(a),callback:b})},moveIndex:function(a,b,c){var d={operation:"move",destination:b};this._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(indexName)+"/operation",body:d,callback:c})},copyIndex:function(a,b,c){var d={operation:"copy",destination:b};this._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(indexName)+"/operation",body:d,callback:c})},getLogs:function(a,b,c){this._isUndefined(b)&&(b=0),this._isUndefined(c)&&(c=10),this._jsonRequest({method:"GET",url:"/1/logs?offset="+b+"&length="+c,callback:a})},listIndexes:function(a){this._jsonRequest({method:"GET",url:"/1/indexes/",callback:a})},initIndex:function(a){return new this.Index(this,a)},listUserKeys:function(a){this._jsonRequest({method:"GET",url:"/1/keys",callback:a})},getUserKeyACL:function(a,b){this._jsonRequest({method:"GET",url:"/1/keys/"+a,callback:b})},deleteUserKey:function(a,b){this._jsonRequest({method:"DELETE",url:"/1/keys/"+a,callback:b})},addUserKey:function(a,b){var c={};c.acl=a,this._jsonRequest({method:"POST",url:"/1/keys",body:c,callback:b})},addUserKeyWithValidity:function(a,b,c){var d=this,e={};e.acl=a,this._jsonRequest({method:"POST",url:"/1/indexes/"+d.indexName+"/keys",body:e,callback:c})},startQueriesBatch:function(){this.batch=[]},addQueryInBatch:function(a,b,c){var d="query="+b;this._isUndefined(c)||null==c||(d=this._getSearchParams(c,d)),this.batch.push({indexName:a,params:d})},clearCache:function(){this.cache={}},sendQueriesBatch:function(a,b){for(var c=this,d={requests:[],apiKey:this.apiKey,appID:this.applicationID},e=0;e<c.batch.length;++e)d.requests.push(c.batch[e]);if(window.clearTimeout(c.onDelayTrigger),!this._isUndefined(b)&&null!=b&&b>0){var f=window.setTimeout(function(){c._sendQueriesBatch(d,a)},b);c.onDelayTrigger=f}else this._sendQueriesBatch(d,a)},Index:function(a,b){this.indexName=b,this.as=a,this.typeAheadArgs=null},_sendQueriesBatch:function(a,b){this._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/*/queries",body:a,callback:b})},_jsonRequest:function(a){var b=this,c=a.callback,d=null,e=a.url;if(this._isUndefined(a.body)||(e=a.url+"_body_"+JSON.stringify(a.body)),!this._isUndefined(a.cache)&&(d=a.cache,!this._isUndefined(d[e])))return this._isUndefined(c)||c(!0,d[e]),void 0;var f=function(g){var h=0;return b._isUndefined(g)||(h=g),b.hosts.length<=h?(b._isUndefined(c)||c(!1,{message:"Cannot contact server"}),void 0):(a.callback=function(g,i,j,k){i||b._isUndefined(k)||console.log("Error: "+k.message),i&&!b._isUndefined(a.cache)&&(d[e]=k),!i&&g&&h+1<b.hosts.length?f(h+1):b._isUndefined(c)||c(i,k)},a.hostname=b.hosts[h],b._jsonRequestByHost(a),void 0)};f()},_jsonRequestByHost:function(a){var b=null,c=this;this._isUndefined(a.body)||(b=JSON.stringify(a.body));var d=a.hostname+a.url,e=null;e=new XMLHttpRequest,"withCredentials"in e?(e.open(a.method,d,!0),e.setRequestHeader("X-Algolia-API-Key",this.apiKey),e.setRequestHeader("X-Algolia-Application-Id",this.applicationID),null!=b&&e.setRequestHeader("Content-type","application/json")):"undefined"!=typeof XDomainRequest?(e=new XDomainRequest,e.open(a.method,d)):console.log("your browser is too old to support CORS requests"),e.send(b),e.onload=function(b){if(c._isUndefined(b))a.callback(!1,!0,b,JSON.parse(e.responseText));else{var d=0===b.target.status||503===b.target.status,f=200===b.target.status||201===b.target.status;a.callback(d,f,b.target,null!=b.target.response?JSON.parse(b.target.response):null)}},e.onerror=function(){a.callback(!0,!1,null,{message:"Could not connect to Host"})}},_getSearchParams:function(a,b){if(this._isUndefined(a)||null==a)return b;for(var c in a)null!=c&&a.hasOwnProperty(c)&&(b+=0===b.length?"?":"&",b+=c+"="+encodeURIComponent(a[c]));return b},_isUndefined:function(a){return void 0===a},applicationID:null,apiKey:null,hosts:[],cache:{}},AlgoliaSearch.prototype.Index.prototype={clearCache:function(){this.cache={}},addObject:function(a,b,c){var d=this;this.as._isUndefined(c)?this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(d.indexName),body:a,callback:b}):this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/"+encodeURIComponent(c),body:a,callback:b})},addObjects:function(a,b){for(var c=this,d={requests:[]},e=0;e<a.length;++e){var f={action:"addObject",body:a[e]};d.requests.push(f)}this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/batch",body:d,callback:b})},getObject:function(a,b,c){var d=this,e="";if(!this.as._isUndefined(c)){e="?attributes=";for(var f=0;f<c.length;++f)0!==f&&(e+=","),e+=c[f]}this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/"+encodeURIComponent(a)+e,callback:b})},partialUpdateObject:function(a,b){var c=this;this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/"+encodeURIComponent(a.objectID)+"/partial",body:a,callback:b})},saveObject:function(a,b){var c=this;this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/"+encodeURIComponent(a.objectID),body:a,callback:b})},saveObjects:function(a,b){for(var c=this,d={requests:[]},e=0;e<a.length;++e){var f={action:"updateObject",objectID:encodeURIComponent(a[e].objectID),body:a[e]};d.requests.push(f)}this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/batch",body:d,callback:b})},deleteObject:function(a,b){if(null==a||0===a.length)return b(!1,{message:"empty objectID"}),void 0;var c=this;this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/"+encodeURIComponent(a),callback:b})},search:function(a,b,c,d){var e=this,f="query="+encodeURIComponent(a);if(this.as._isUndefined(c)||null==c||(f=this.as._getSearchParams(c,f)),window.clearTimeout(e.onDelayTrigger),!this.as._isUndefined(d)&&null!=d&&d>0){var g=window.setTimeout(function(){e._search(f,b)},d);e.onDelayTrigger=g}else this._search(f,b)},getTypeaheadTransport:function(a){return this.typeAheadArgs=a,this},get:function(a,b,c,d,e){return self=this,this.search(a,function(a,b){if(a){for(var f=0;f<b.hits.length;++f){var g=b.hits[f],h=!1;if("undefined"==typeof g.value)for(var i in g)!h&&g.hasOwnProperty(i)&&"string"==typeof g[i]&&(g.value=g[i],h=!0);e.push(c._transformDatum(g))}d&&d(e)}},self.typeAheadArgs),!0},waitTask:function(a,b){var c=this;this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/task/"+a,callback:function(d,e){if(d&&"published"===e.status)b(!0,e);else{if(d&&e.pendingTask)return c.waitTask(a,b);b(!1,e)}}})},getSettings:function(a){var b=this;this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/settings",callback:a})},setSettings:function(a,b){var c=this;this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/settings",body:a,callback:b})},listUserKeys:function(a){var b=this;this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/keys",callback:a})},getUserKeyACL:function(a,b){var c=this;this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys/"+a,callback:b})},deleteUserKey:function(a,b){var c=this;this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys/"+a,callback:b})},addUserKey:function(a,b){var c=this,d={};d.acl=a,this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys",body:d,callback:b})},addUserKeyWithValidity:function(a,b,c){var d=this,e={};e.acl=a,e.validity=b,this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/keys",body:e,callback:c})},_search:function(a,b){this.as._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/query",body:{params:a,apiKey:this.as.apiKey,appID:this.as.applicationID},callback:b})},as:null,indexName:null,cache:{},typeAheadArgs:null,emptyConstructor:function(){}};
7
+ var VERSION="2.3.0",AlgoliaSearch=function(a,b,c,d,e){this.applicationID=a,this.apiKey=b,this._isUndefined(e)&&(e=[a+"-1.algolia.io",a+"-2.algolia.io",a+"-3.algolia.io"]),this.hosts=[];for(var f=0;f<e.length;++f)Math.random()>.5&&this.hosts.reverse(),this._isUndefined(c)||null==c?this.hosts.push(("https:"==document.location.protocol?"https":"http")+"://"+e[f]):"https"===c||"HTTPS"===c?this.hosts.push("https://"+e[f]):this.hosts.push("http://"+e[f]);Math.random()>.5&&this.hosts.reverse(),(this._isUndefined(d)||d)&&this._jsonRequest({method:"GET",url:"/1/isalive"})};AlgoliaSearch.prototype={deleteIndex:function(a,b){this._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(a),callback:b})},moveIndex:function(a,b,c){var d={operation:"move",destination:b};this._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(indexName)+"/operation",body:d,callback:c})},copyIndex:function(a,b,c){var d={operation:"copy",destination:b};this._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(indexName)+"/operation",body:d,callback:c})},getLogs:function(a,b,c){this._isUndefined(b)&&(b=0),this._isUndefined(c)&&(c=10),this._jsonRequest({method:"GET",url:"/1/logs?offset="+b+"&length="+c,callback:a})},listIndexes:function(a){this._jsonRequest({method:"GET",url:"/1/indexes/",callback:a})},initIndex:function(a){return new this.Index(this,a)},listUserKeys:function(a){this._jsonRequest({method:"GET",url:"/1/keys",callback:a})},getUserKeyACL:function(a,b){this._jsonRequest({method:"GET",url:"/1/keys/"+a,callback:b})},deleteUserKey:function(a,b){this._jsonRequest({method:"DELETE",url:"/1/keys/"+a,callback:b})},addUserKey:function(a,b){var c={};c.acl=a,this._jsonRequest({method:"POST",url:"/1/keys",body:c,callback:b})},addUserKeyWithValidity:function(a,b,c,d,e){var f=this,g={};g.acl=a,g.validity=b,g.maxQueriesPerIPPerHour=c,g.maxHitsPerQuery=d,this._jsonRequest({method:"POST",url:"/1/indexes/"+f.indexName+"/keys",body:g,callback:e})},startQueriesBatch:function(){this.batch=[]},addQueryInBatch:function(a,b,c){var d="query="+b;this._isUndefined(c)||null==c||(d=this._getSearchParams(c,d)),this.batch.push({indexName:a,params:d})},clearCache:function(){this.cache={}},sendQueriesBatch:function(a,b){for(var c=this,d={requests:[],apiKey:this.apiKey,appID:this.applicationID},e=0;e<c.batch.length;++e)d.requests.push(c.batch[e]);if(window.clearTimeout(c.onDelayTrigger),!this._isUndefined(b)&&null!=b&&b>0){var f=window.setTimeout(function(){c._sendQueriesBatch(d,a)},b);c.onDelayTrigger=f}else this._sendQueriesBatch(d,a)},Index:function(a,b){this.indexName=b,this.as=a,this.typeAheadArgs=null,this.typeAheadPropertyName=null},_sendQueriesBatch:function(a,b){this._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/*/queries",body:a,callback:b})},_jsonRequest:function(a){var b=this,c=a.callback,d=null,e=a.url;if(this._isUndefined(a.body)||(e=a.url+"_body_"+JSON.stringify(a.body)),!this._isUndefined(a.cache)&&(d=a.cache,!this._isUndefined(d[e])))return this._isUndefined(c)||c(!0,d[e]),void 0;var f=function(g){var h=0;return b._isUndefined(g)||(h=g),b.hosts.length<=h?(b._isUndefined(c)||c(!1,{message:"Cannot contact server"}),void 0):(a.callback=function(g,i,j,k){i||b._isUndefined(k)||console.log("Error: "+k.message),i&&!b._isUndefined(a.cache)&&(d[e]=k),!i&&g&&h+1<b.hosts.length?f(h+1):b._isUndefined(c)||c(i,k)},a.hostname=b.hosts[h],b._jsonRequestByHost(a),void 0)};f()},_jsonRequestByHost:function(a){var b=null,c=this;this._isUndefined(a.body)||(b=JSON.stringify(a.body));var d=a.hostname+a.url,e=null;e=new XMLHttpRequest,"withCredentials"in e?(e.open(a.method,d,!0),e.setRequestHeader("X-Algolia-API-Key",this.apiKey),e.setRequestHeader("X-Algolia-Application-Id",this.applicationID),null!=b&&e.setRequestHeader("Content-type","application/json")):"undefined"!=typeof XDomainRequest?(e=new XDomainRequest,e.open(a.method,d)):console.log("your browser is too old to support CORS requests"),e.send(b),e.onload=function(b){if(c._isUndefined(b))a.callback(!1,!0,b,JSON.parse(e.responseText));else{var d=0===b.target.status||503===b.target.status,f=200===b.target.status||201===b.target.status;a.callback(d,f,b.target,null!=b.target.response?JSON.parse(b.target.response):null)}},e.onerror=function(){a.callback(!0,!1,null,{message:"Could not connect to Host"})}},_getSearchParams:function(a,b){if(this._isUndefined(a)||null==a)return b;for(var c in a)null!=c&&a.hasOwnProperty(c)&&(b+=0===b.length?"?":"&",b+=c+"="+encodeURIComponent(a[c]));return b},_isUndefined:function(a){return void 0===a},applicationID:null,apiKey:null,hosts:[],cache:{}},AlgoliaSearch.prototype.Index.prototype={clearCache:function(){this.cache={}},addObject:function(a,b,c){var d=this;this.as._isUndefined(c)?this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(d.indexName),body:a,callback:b}):this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/"+encodeURIComponent(c),body:a,callback:b})},addObjects:function(a,b){for(var c=this,d={requests:[]},e=0;e<a.length;++e){var f={action:"addObject",body:a[e]};d.requests.push(f)}this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/batch",body:d,callback:b})},getObject:function(a,b,c){var d=this,e="";if(!this.as._isUndefined(c)){e="?attributes=";for(var f=0;f<c.length;++f)0!==f&&(e+=","),e+=c[f]}this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/"+encodeURIComponent(a)+e,callback:b})},partialUpdateObject:function(a,b){var c=this;this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/"+encodeURIComponent(a.objectID)+"/partial",body:a,callback:b})},saveObject:function(a,b){var c=this;this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/"+encodeURIComponent(a.objectID),body:a,callback:b})},saveObjects:function(a,b){for(var c=this,d={requests:[]},e=0;e<a.length;++e){var f={action:"updateObject",objectID:encodeURIComponent(a[e].objectID),body:a[e]};d.requests.push(f)}this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/batch",body:d,callback:b})},deleteObject:function(a,b){if(null==a||0===a.length)return b(!1,{message:"empty objectID"}),void 0;var c=this;this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/"+encodeURIComponent(a),callback:b})},search:function(a,b,c,d){var e=this,f="query="+encodeURIComponent(a);if(this.as._isUndefined(c)||null==c||(f=this.as._getSearchParams(c,f)),window.clearTimeout(e.onDelayTrigger),!this.as._isUndefined(d)&&null!=d&&d>0){var g=window.setTimeout(function(){e._search(f,b)},d);e.onDelayTrigger=g}else this._search(f,b)},getTypeaheadTransport:function(a,b){return this.typeAheadArgs=a,"undefined"!=typeof b&&(this.typeAheadPropertyName=b),this},get:function(a,b,c,d,e){return self=this,this.search(a,function(a,b){if(a){for(var f=0;f<b.hits.length;++f){var g=b.hits[f];if("undefined"==typeof g.value)if(null!=self.typeAheadPropertyName&&"undefined"!=typeof g[self.typeAheadPropertyName])g.value=g[self.typeAheadPropertyName];else{var h=!1;for(var i in g)!h&&g.hasOwnProperty(i)&&"string"==typeof g[i]&&(g.value=g[i],h=!0)}e.push(c._transformDatum(g))}d&&d(e)}},self.typeAheadArgs),!0},waitTask:function(a,b){var c=this;this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/task/"+a,callback:function(d,e){if(d&&"published"===e.status)b(!0,e);else{if(d&&e.pendingTask)return c.waitTask(a,b);b(!1,e)}}})},clearIndex:function(a){var b=this;this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/clear",callback:a})},getSettings:function(a){var b=this;this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/settings",callback:a})},setSettings:function(a,b){var c=this;this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/settings",body:a,callback:b})},listUserKeys:function(a){var b=this;this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/keys",callback:a})},getUserKeyACL:function(a,b){var c=this;this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys/"+a,callback:b})},deleteUserKey:function(a,b){var c=this;this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys/"+a,callback:b})},addUserKey:function(a,b){var c=this,d={};d.acl=a,this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys",body:d,callback:b})},addUserKeyWithValidity:function(a,b,c,d,e){var f=this,g={};g.acl=a,g.validity=b,g.maxQueriesPerIPPerHour=c,g.maxHitsPerQuery=d,this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(f.indexName)+"/keys",body:g,callback:e})},_search:function(a,b){this.as._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/query",body:{params:a,apiKey:this.as.apiKey,appID:this.as.applicationID},callback:b})},as:null,indexName:null,cache:{},typeAheadArgs:null,typeAheadPropertyName:null,emptyConstructor:function(){}};
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: algoliasearch-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Algolia
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '>='
32
32
  - !ruby/object:Gem::Version
33
- version: 1.1.4
33
+ version: 1.1.6
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
- version: 1.1.4
40
+ version: 1.1.6
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: jeweler
43
43
  requirement: !ruby/object:Gem::Requirement