Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.

Commit e412d33

Browse files
committed
refactoring(Apisearch): added new parameter on the entry point for the index name
1 parent af4f449 commit e412d33

File tree

9 files changed

+71
-32
lines changed

9 files changed

+71
-32
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ build a query, and search! Super easy right?
6464
```javascript
6565
const api = apisearch({
6666
appId: 'music',
67-
apiKey: '1cc7a3e0-bda5-11e7-abc4-cec278b6b50a'
67+
index: 'default',
68+
token: '1cc7a3e0-bda5-11e7-abc4-cec278b6b50a'
6869
});
6970

7071
const query = api.query.create('Your search query');

dist/apisearch.js

Lines changed: 20 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/apisearch.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/apisearch.node.js

Lines changed: 20 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/apisearch.node.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/search_input.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@
3838
// 1. Create the client
3939
var api = apisearch({
4040
appId: 'music',
41-
apiKey: '5fadd8c4-c966-11e7-abc4-cec278b6b50a'
41+
index: 'default',
42+
token: '5fadd8c4-c966-11e7-abc4-cec278b6b50a',
43+
options: {
44+
endpoint: 'b2298209.ngrok.io'
45+
}
4246
});
4347
var query;
4448

src/Apisearch.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ class Apisearch {
1212
*/
1313
constructor({
1414
appId,
15-
apiKey,
15+
index,
16+
token,
1617
options: {
1718
endpoint,
1819
apiVersion,
@@ -26,7 +27,8 @@ class Apisearch {
2627
* Api
2728
*/
2829
this.appId = appId;
29-
this.apiKey = apiKey;
30+
this.index = index;
31+
this.token = token;
3032
this.apiVersion = apiVersion;
3133
this.endpoint = endpoint;
3234
this.protocol = protocol;
@@ -59,7 +61,7 @@ class Apisearch {
5961
JSON.stringify(query)
6062
);
6163
let composedQuery = {
62-
url: `${this.protocol}://${this.endpoint}/${this.apiVersion}?app_id=${this.appId}&key=${this.apiKey}&query=${encodedQuery}`,
64+
url: `${this.protocol}://${this.endpoint}/${this.apiVersion}?app_id=${this.appId}&index=${this.index}&token=${this.token}&query=${encodedQuery}`,
6365
options: {
6466
timeout: this.timeout
6567
}

src/index.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ import Apisearch from "./Apisearch";
1212

1313
module.exports = function({
1414
appId,
15-
apiKey,
15+
index,
16+
token,
1617
options = {}
1718
}) {
1819
checkAppId(appId);
19-
checkApiKey(apiKey);
20+
checkIndex(index);
21+
checkApiKey(token);
2022

2123
options = {
2224
endpoint: 'api.apisear.ch',
@@ -30,7 +32,8 @@ module.exports = function({
3032

3133
return new Apisearch({
3234
appId,
33-
apiKey,
35+
index,
36+
token,
3437
options
3538
});
3639
};
@@ -41,8 +44,14 @@ function checkAppId(appId) {
4144
}
4245
}
4346

44-
function checkApiKey(apiKey) {
45-
if (typeof apiKey === 'undefined') {
46-
throw new TypeError(`apiKey parameter must be defined.`)
47+
function checkIndex(index) {
48+
if (typeof index === 'undefined') {
49+
throw new TypeError(`index parameter must be defined.`)
50+
}
51+
}
52+
53+
function checkApiKey(token) {
54+
if (typeof token === 'undefined') {
55+
throw new TypeError(`token parameter must be defined.`)
4756
}
4857
}

test/apisearch.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const apisearch = require('../src/index');
77
describe('apisearch()', () => {
88
let client = apisearch({
99
appId: 'some_app_id',
10-
apiKey: 'some_api_key'
10+
index: 'some_index',
11+
token: 'some_api_key'
1112
});
1213

1314
describe('-> When creating a query', () => {

0 commit comments

Comments
 (0)