algolia-indices 0.1.0 → 0.2.0

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
  SHA256:
3
- metadata.gz: b2a3c0af82c1678abce5e87b0ef7efb742da491bda0f2dfc07a2fd702a2b9e62
4
- data.tar.gz: 61dc872342172b72207b422144e554a6ca965684312408c94d8b38c70e7d7ffe
3
+ metadata.gz: 39560bd31744ca72081fc48087e1de62c6505012c36bc2ab4761166024a4d790
4
+ data.tar.gz: a473ea29089945454cf0d19f00b1a36dd1234be1dbd2ffe2f59fe67ce1d9bed0
5
5
  SHA512:
6
- metadata.gz: c3c8694387ecef634491de40a99b43e484028a78d0a45256f466b8e97786ff74849344dcd13948b5aef085d30d1fbbfe70c3ff97558e75e03208068c9408fa56
7
- data.tar.gz: af5d6129cda532ea78a038c2864a8d61520067f1547d21a16e15ad7c7a7ce80f9fd9f00cbd0ad11eef4858a1fa232cc4f2519995b8531c5c360e753f7b4cfce5
6
+ metadata.gz: 49c9f8b2e068f74a37147d6dd4951ae4f941f52ff7960b0dc024627514e83d4dc216d86c6de31b84181f381ed6df970bfd87d93edb6faa819ddc3a564ce03c54
7
+ data.tar.gz: e22e02b05bfd1e8c98252d50b9222e46fee0e30f729e8c31be6fe987efdc0485ee004c00250115b56547a5a48ccc7f36a720919234049aa57f31edf083ed92e1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- algolia-indices (0.1.0)
4
+ algolia-indices (0.2.0)
5
5
  faraday (~> 0.15.3)
6
6
  thor (~> 0.20.3)
7
7
 
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
- TODO
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
 
@@ -5,7 +5,7 @@ require 'algolia/indices/converter'
5
5
  module Algolia
6
6
  module Indices
7
7
  class CLI < Thor
8
- desc "import [API-KEY] [APPLICATION-ID] [INDEX-NAME] [FILE-PATH]", "import records to specified Algolia index"
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
@@ -1,5 +1,5 @@
1
1
  module Algolia
2
2
  module Indices
3
- VERSION = "0.1.0"
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: algolia-indices
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - m-nakamura145