tablestore-ruby-sdk 0.0.1 → 0.0.4

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
  SHA1:
3
- metadata.gz: c36ab88b0d68c1d3d9b195807ad3f20b8350e846
4
- data.tar.gz: '0928fd79588d6dbcca9d7af69ff4aa188f5ebbb0'
3
+ metadata.gz: 86177da99a4888d0a61d1b52b20f90b43fb3624d
4
+ data.tar.gz: 37ad84d31c752483becbd23dcebc212ce054607c
5
5
  SHA512:
6
- metadata.gz: 65470041a252ccfc3812746fa787904cfa351346bbdc0989f7712e9f1b2c8a76cce11b8a2378e5da86de69bd51d9252c8385a18fe6429ee13ce650583ef6cea2
7
- data.tar.gz: d805aa949b1a73d505db768b3076ca0f21d7adc75a1aa1a71a0177a9d0435662b29a28d55030301594c42dd0bd278c1a1ca47615d4951878818c5e1b0458562a
6
+ metadata.gz: ffcd6971f6c6b5e7311e5495bec618db4f2eef6797f7e8dd701e594252ee60f6ac05e3a3ab047e36f86862c348c6d463f777b2c1d60543a9ad6c1a49726810f1
7
+ data.tar.gz: 6aadd6fb901ddab23eab2dbe74bcd78e283f7cf7f16f1f3b05f3627c9a39c3a395ed7e261ef28ad51866c5ff862b15a55ddfe44ea8c3c6b3aa525c7c3c404051
@@ -11,8 +11,9 @@ class TableStore
11
11
  DEFAULT_MAX_CONNECTION = 50
12
12
  DEFAULT_LOGGER_NAME = 'tablestore-client'
13
13
 
14
+ attr_accessor :base_url, :access_key_id, :access_key_secret, :instance_name
14
15
 
15
- def initialize(end_point, access_key_id, access_key_secret, instance_name, **kwargs)
16
+ def initialize(base_url, access_key_id, access_key_secret, instance_name, **kwargs)
16
17
  # 初始化TableStoreClient实例。
17
18
  # end_point是TableStoreClient服务的地址(例如 'http://instance.cn-hangzhou.TableStoreClient.aliyun.com'),必须以'http://'或'https://'开头。
18
19
  # access_key_id是访问TableStoreClient服务的accessid,通过官方网站申请或通过管理员获取。
@@ -28,6 +29,11 @@ class TableStore
28
29
  #self.validate_parameter(end_point, access_key_id, access_key_secret, instance_name)
29
30
  #sts_token = kwargs.get('sts_token')
30
31
 
32
+ self.base_url = base_url
33
+ self.access_key_id = access_key_id
34
+ self.access_key_secret = access_key_secret
35
+ self.instance_name = instance_name
36
+
31
37
  #示例:创建一个TableStoreClient实例
32
38
  # from tablestore.client import TableStoreClient
33
39
  # client = TableStoreClient('your_instance_endpoint', 'your_user_id', 'your_user_key', 'your_instance_name')
@@ -56,6 +62,15 @@ class TableStore
56
62
  TableStoreClient.new.decode_get_row(response.body)
57
63
  end
58
64
 
65
+ def _update_row(table_name, row, condition)
66
+ api_name = 'UpdateRow'
67
+ body = TableStoreClient.new.encode_update_row(table_name, row, condition)
68
+ response = post_request(body, api_name)
69
+ if response.code == 200
70
+ 'update succeed!'
71
+ end
72
+ end
73
+
59
74
  def _batch_get_row(request)
60
75
  api_name = 'BatchGetRow'
61
76
  body = TableStoreClient.new.make_batch_get_row(request)
@@ -76,22 +91,26 @@ class TableStore
76
91
  def post_request(body, api_name)
77
92
  md5 = Base64.encode64(Digest::MD5.new.digest(body)).gsub(/\n/, '')
78
93
  headers = get_headers(md5, api_name)
79
- url = BaseUrl+ '/' + api_name
80
- RestClient.post(url, body, headers)
94
+ url = base_url + '/' + api_name
95
+ begin
96
+ RestClient.post(url, body, headers)
97
+ rescue => e
98
+ raise '请检查传入参数'
99
+ end
81
100
  end
82
101
 
83
102
  def get_headers(md5, api_name)
84
103
  headers = {
85
- "x-ots-date": '2018-01-09T14:48:12.000Z',#Time.now.getutc.strftime('%Y-%m-%dT%H:%M:%S.000Z'),
104
+ "x-ots-date": Time.now.getutc.strftime('%Y-%m-%dT%H:%M:%S.000Z'),
86
105
  "x-ots-apiversion": '2015-12-31',
87
- "x-ots-accesskeyid": UserID,
106
+ "x-ots-accesskeyid": access_key_id,
88
107
  "x-ots-contentmd5": md5,
89
- "x-ots-instancename": InstanceName,
108
+ "x-ots-instancename": instance_name,
90
109
  }
91
110
  signature_string = "/#{api_name}\nPOST\n\n"
92
111
  headers_string = headers.map{|k,v| "#{k.downcase}:#{v.strip}"}.sort.join("\n")
93
112
  signature_string += headers_string + "\n"
94
- salt1 = OpenSSL::HMAC.digest('sha1', UserSecret, signature_string)
113
+ salt1 = OpenSSL::HMAC.digest('sha1', access_key_secret, signature_string)
95
114
  signature = Base64.encode64(salt1).gsub(/\n/, '')
96
115
  headers.merge!({'User-Agent': 'aliyun-tablestore-sdk-ruby', 'x-ots-signature': signature})
97
116
  headers
@@ -209,7 +209,7 @@ class PlainBufferCodedInputStream
209
209
  row_list = []
210
210
  while !@input_stream.is_at_end?
211
211
  pk, attr = read_row_without_header
212
- row_list << {pk:pk, attr: attr}
212
+ row_list << {"primary_key"=>pk, "attribute_columns"=> attr}
213
213
  end
214
214
  row_list
215
215
  end
@@ -47,7 +47,7 @@ class TableStoreClient
47
47
  def encode_put_row(table_name, row, condition)
48
48
  proto = PutRowRequest.new
49
49
  proto.table_name = table_name
50
- condition = Condition(RowExistenceExpectation::IGNORE, nil) if condition.nil?
50
+ condition = Condition.new(RowExistenceExpectation::IGNORE) if condition.nil?
51
51
  contion_proto = Condition.new
52
52
  proto.condition = make_condition(contion_proto, condition)
53
53
  proto.row = serialize_for_put_row(row.primary_key, row.attribute_columns)
@@ -66,6 +66,18 @@ class TableStoreClient
66
66
  proto.serialize_to_string
67
67
  end
68
68
 
69
+ def encode_update_row(teble_name, row, condition)
70
+ proto = UpdateRowRequest.new
71
+ proto.table_name = table_name
72
+ condition = Condition.new(RowExistenceExpectation::IGNORE) if condition.nil?
73
+ proto.condition = condition
74
+ if return_type == ReturnType::RT_PK
75
+ proto.return_content.return_type = RT_PK
76
+ end
77
+ proto.row_change = serialize_for_update_row(row.primary_key, row.attribute_columns)
78
+ proto
79
+ end
80
+
69
81
  def decode_get_row(body)
70
82
  proto = GetRowResponse.new
71
83
  proto.parse_from_string(body)
@@ -359,9 +371,9 @@ class TableStoreClient
359
371
  raise TableStoreClientError.new("the columns value of update-row must be hash, but is #{attribute_columns[key].class}")
360
372
  end
361
373
  attribute_columns[key].each do |cell|
362
- # if cell.is_a?(Array)
363
- # raise TableStoreClientError.new("the cell of update-row must be array, but is #{cell.class}")
364
- # end
374
+ if cell.is_a?(Array)
375
+ raise TableStoreClientError.new("the cell of update-row must be array, but is #{cell.class}")
376
+ end
365
377
  end
366
378
  end
367
379
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tablestore-ruby-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - seveninches
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-10 00:00:00.000000000 Z
11
+ date: 2018-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -17,7 +17,7 @@ dependencies:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.0'
20
- type: :development
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
@@ -25,19 +25,25 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: protobuf
28
+ name: ruby_protobuf
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.8'
34
- type: :development
33
+ version: '0.4'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 0.4.11
37
+ type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
41
  - - "~>"
39
42
  - !ruby/object:Gem::Version
40
- version: '3.8'
43
+ version: '0.4'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.4.11
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: digest-crc
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -45,7 +51,7 @@ dependencies:
45
51
  - - "~>"
46
52
  - !ruby/object:Gem::Version
47
53
  version: '0.4'
48
- type: :development
54
+ type: :runtime
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
@@ -59,7 +65,7 @@ dependencies:
59
65
  - - "~>"
60
66
  - !ruby/object:Gem::Version
61
67
  version: '1.0'
62
- type: :development
68
+ type: :runtime
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements: