algolia-indices 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +28 -2
- data/lib/algolia/indices/cli.rb +9 -1
- data/lib/algolia/indices/client.rb +9 -1
- data/lib/algolia/indices/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39560bd31744ca72081fc48087e1de62c6505012c36bc2ab4761166024a4d790
|
4
|
+
data.tar.gz: a473ea29089945454cf0d19f00b1a36dd1234be1dbd2ffe2f59fe67ce1d9bed0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49c9f8b2e068f74a37147d6dd4951ae4f941f52ff7960b0dc024627514e83d4dc216d86c6de31b84181f381ed6df970bfd87d93edb6faa819ddc3a564ce03c54
|
7
|
+
data.tar.gz: e22e02b05bfd1e8c98252d50b9222e46fee0e30f729e8c31be6fe987efdc0485ee004c00250115b56547a5a48ccc7f36a720919234049aa57f31edf083ed92e1
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# algolia-indices
|
2
2
|
|
3
|
-
A command line tool for [Algolia](https://www.algolia.com).
|
3
|
+
A command line tool for [Algolia](https://www.algolia.com). algolia-indices has the following features:
|
4
|
+
|
5
|
+
* **Import records**: You can import the record of the yaml file into the specified algolia index.
|
6
|
+
* **Clear an index's context**: You can clear records from specified algolia index.
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
@@ -20,7 +23,30 @@ Or install it yourself as:
|
|
20
23
|
|
21
24
|
## Usage
|
22
25
|
|
23
|
-
|
26
|
+
```sh
|
27
|
+
# Import the record of the yaml file into the specified algolia index
|
28
|
+
$ algolia-indices import [API-KEY] [APPLICATION-ID] [INDEX-NAME] [FILE-PATH]
|
29
|
+
|
30
|
+
# Clear records from specified algolia index
|
31
|
+
$ algolia-indices clear [API-KEY] [APPLICATION-ID] [INDEX-NAME]
|
32
|
+
```
|
33
|
+
|
34
|
+
### Algolia API-Key
|
35
|
+
|
36
|
+
You must generate an API key that gave the Add object and Delete Object permissions.
|
37
|
+
|
38
|
+
see [Algolia API Key document](https://www.algolia.com/doc/guides/security/api-keys/#api-key-restrictions).
|
39
|
+
|
40
|
+
### Import data format
|
41
|
+
|
42
|
+
Create data source in `yaml` format.
|
43
|
+
|
44
|
+
```yaml
|
45
|
+
records:
|
46
|
+
- name: sample_restaurant1
|
47
|
+
- name: sample_restaurant2
|
48
|
+
|
49
|
+
```
|
24
50
|
|
25
51
|
## Development
|
26
52
|
|
data/lib/algolia/indices/cli.rb
CHANGED
@@ -5,7 +5,7 @@ require 'algolia/indices/converter'
|
|
5
5
|
module Algolia
|
6
6
|
module Indices
|
7
7
|
class CLI < Thor
|
8
|
-
desc
|
8
|
+
desc 'import [API-KEY] [APPLICATION-ID] [INDEX-NAME] [FILE-PATH]', 'Import records to specified algolia index'
|
9
9
|
def import(api_key, application_id, index_name, path)
|
10
10
|
puts 'Import records to Algolia'
|
11
11
|
converter = Algolia::Indices::Converter.load(path)
|
@@ -13,6 +13,14 @@ module Algolia
|
|
13
13
|
client.batch_write_operations(converter.batch_write_operations_request_paramters)
|
14
14
|
puts 'Finished'
|
15
15
|
end
|
16
|
+
|
17
|
+
desc 'clear [API-KEY] [APPLICATION-ID] [INDEX-NAME]', 'Clear records from specified algolia index'
|
18
|
+
def clear(api_key, application_id, index_name)
|
19
|
+
puts "Clear an index: #{index_name} content"
|
20
|
+
client = Algolia::Indices::Client.new(api_key, application_id, index_name)
|
21
|
+
client.clear_index
|
22
|
+
puts 'Finished'
|
23
|
+
end
|
16
24
|
end
|
17
25
|
end
|
18
26
|
end
|
@@ -15,6 +15,10 @@ module Algolia
|
|
15
15
|
http_post(batch_write_operations_path, parameters)
|
16
16
|
end
|
17
17
|
|
18
|
+
def clear_index
|
19
|
+
http_post(clear_index_path)
|
20
|
+
end
|
21
|
+
|
18
22
|
private
|
19
23
|
|
20
24
|
def http_client
|
@@ -34,7 +38,7 @@ module Algolia
|
|
34
38
|
}
|
35
39
|
end
|
36
40
|
|
37
|
-
def http_post(path, parameters = {})
|
41
|
+
def http_post(path, parameters = {}.to_json)
|
38
42
|
http_client.post do |req|
|
39
43
|
req.url path
|
40
44
|
req.body = parameters
|
@@ -48,6 +52,10 @@ module Algolia
|
|
48
52
|
def batch_write_operations_path
|
49
53
|
"/1/indexes/#{@index_name}/batch"
|
50
54
|
end
|
55
|
+
|
56
|
+
def clear_index_path
|
57
|
+
"/1/indexes/#{@index_name}/clear"
|
58
|
+
end
|
51
59
|
end
|
52
60
|
end
|
53
61
|
end
|