aliyun_open_search 0.3.0 → 0.3.1

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: a0c0771214d13524facc8c7d13c3ab9dd62717c6
4
- data.tar.gz: 6bd2f5956ff22f8beb516f37d631f6f4b3622098
3
+ metadata.gz: c5e99bfcdbe6afc31c2e970c7dcc681a49211bcf
4
+ data.tar.gz: 794c9d72dc9440532f1024f153e785841d74d1ad
5
5
  SHA512:
6
- metadata.gz: f9e0a17537e36e8924e3f11a958461ef660375a3013d7ad477914c60013492d9de43b0c81c17ae522088f1657c77e6a1fabc6eb8a15b21fcb075a1173b3e2a0f
7
- data.tar.gz: 89745ede0e5ec6bc1c5c4059bd0b52315f03ba2b74188cacf32c8e7ddffc77b1527e408b5bbf2e3255d1b256825a16c7977b70ec8cfda7ff7507efb17b8c37b9
6
+ metadata.gz: f4206fb509144123bcbdfd40fba83d0646e75009da0b457152192fe386e29bb4890377c9d3c7a3f94826b2b546d0899f55822f2caaa79ff216bbafbe03b9080d
7
+ data.tar.gz: 1cf54b4c7c1b94b8864e08d5d874d3461b5bc29275207b1e3e356a021ccba0611b83f30a1ff7aa64ae0a60bf9265679a2dddfdaae109998b64d0d485c7917b05
data/README.md CHANGED
@@ -7,7 +7,11 @@
7
7
  Add this line to your application's Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'aliyun_open_search', github: "LcpMarvel/aliyun_open_search", require: false
10
+ gem 'aliyun_open_search'
11
+
12
+ # or
13
+
14
+ gem 'aliyun_open_search', github: "LcpMarvel/aliyun_open_search"
11
15
 
12
16
  ```
13
17
 
@@ -35,7 +39,7 @@ OPEN_SEARCH_HOST: "http://opensearch-cn-hangzhou.aliyuncs.com"
35
39
 
36
40
  ### 数据处理API
37
41
 
38
- ```
42
+ ```ruby
39
43
  # app_name 是阿里云 应用名称
40
44
  # params 的内容按照阿里云文档中的约定组织
41
45
  require "aliyun_open_search"
@@ -89,6 +93,36 @@ AliyunOpenSearch::Search.new("test", "test2", "test3").execute(params)
89
93
 
90
94
  ```
91
95
 
96
+ ### 签名
97
+ ##### 你可以直接使用封装好的方法进行签名(文档读得好累)
98
+
99
+ ```ruby
100
+
101
+ AliyunOpenSearch.request_method = "POST" # 默认是 GET, 大写
102
+
103
+ # custom_params 的内容按照阿里云文档中的约定组织
104
+ custom_params = {
105
+ "action" => "push",
106
+ "table_name" => "cars",
107
+ "items" => [
108
+ {
109
+ "cmd": "update",
110
+ "timestamp": 1_420_070_400_010,
111
+ "fields": {
112
+ "id": "121139313135",
113
+ "styl_name": "aodi",
114
+ "acquirer_id": "1"
115
+ }
116
+ }
117
+ ].to_json
118
+ }
119
+
120
+ AliyunOpenSearch::Base.signature(
121
+ AliyunOpenSearch::Base.new.basic_params.merge!(custom_params)
122
+ )
123
+
124
+ ```
125
+
92
126
 
93
127
  ## Development
94
128
 
@@ -5,6 +5,10 @@ module AliyunOpenSearch
5
5
  class Base
6
6
  attr_reader :basic_params, :base_url
7
7
 
8
+ class << self
9
+ attr_accessor :request_method
10
+ end
11
+
8
12
  def initialize
9
13
  @basic_params = {
10
14
  "Version" => "v2",
@@ -25,7 +29,7 @@ module AliyunOpenSearch
25
29
  end
26
30
 
27
31
  def self.request_method
28
- "GET"
32
+ @request_method ||= "GET"
29
33
  end
30
34
 
31
35
  def self.signature(params)
@@ -4,17 +4,18 @@ module AliyunOpenSearch
4
4
 
5
5
  def initialize(*index_names)
6
6
  super()
7
+
7
8
  @index_names = index_names.join(";")
8
9
  @base_url = "#{ENV["OPEN_SEARCH_HOST"]}/search"
9
10
  end
10
11
 
11
12
  def execute(custom_params)
12
13
  params = basic_params.merge(
13
- self.class.format_params(custom_params.merge("index_name" => index_names))
14
+ Base.format_params(custom_params.merge("index_name" => index_names))
14
15
  )
15
16
 
16
17
  Net::HTTP.get(
17
- uri(params.merge("Signature" => self.class.signature(params)))
18
+ uri(params.merge("Signature" => Search.signature(params)))
18
19
  )
19
20
  end
20
21
  end
@@ -11,19 +11,10 @@ module AliyunOpenSearch
11
11
  end
12
12
 
13
13
  def execute(custom_params)
14
- formatted_custom_params = {}.tap do |hash|
15
- custom_params.map do |key, value|
16
- hash[key.to_s] = if value.is_a?(Array)
17
- JSON.generate(value)
18
- else
19
- value.to_s
20
- end
21
- end
22
- end
14
+ formatted_custom_params = Base.format_params(custom_params)
23
15
 
24
16
  params_with_signature = basic_params.merge(
25
- "Signature" => self.class
26
- .signature(basic_params.merge(formatted_custom_params))
17
+ "Signature" => Syncs.signature(basic_params.merge(formatted_custom_params))
27
18
  )
28
19
 
29
20
  Net::HTTP.post_form(uri(params_with_signature), formatted_custom_params)
@@ -1,3 +1,3 @@
1
1
  module AliyunOpenSearch
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aliyun_open_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - lcp