tencent_cos_sdk 0.1.2 → 0.2.0

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: 3d4d601a61de87459a00b854374dd00ef5ef6dd5
4
- data.tar.gz: cd25de1ae798210fecae01560d78e6a4f007e384
3
+ metadata.gz: 8c05cabab083444a58f54d2c23e20ad1a77a5889
4
+ data.tar.gz: cf903de3f333951eba8d7cc29737b5dd05544e33
5
5
  SHA512:
6
- metadata.gz: 51e2daf4b0b20657ff8658f41d535c49da264f422b2a1edf73a3e17b3871d56f11c1c05ea8760661ee4b88565e25281772bc3dd6ff60da06761bea920e715c2b
7
- data.tar.gz: f62f3b6d60375e8a12a88652cecd2b6f9bc0c62912900cb21c34813df266c2c11b24075bbffd1a2190c75d8829fb3549d375ca58f9217d903f470742c25fa2c9
6
+ metadata.gz: ab87e308ff8fc5907558384ad7c8eeb919a5e14098f78f81c707fcba53108d404e3970a6eafc6b2e07fa02416384e9f6ad0ec6f93d386d44ef9cf8e4c65d0ae0
7
+ data.tar.gz: df7cf33752d4cf4058fc517ed93ede94f63a2d6765b8a936bfd98297f44788d096e5f47baab8df34cde67ee946d9f07ce4d9f6c329e1d0e5ed7233a4363e7a18
@@ -4,12 +4,12 @@ require 'tencent_cos_sdk/utils'
4
4
 
5
5
  module TencentCosSdk
6
6
  class Request
7
- attr_accessor :http_method, :uri, :headers, :body, :file
7
+ attr_accessor :http_method, :path, :headers, :body, :file
8
8
  attr_accessor :response, :time_used
9
9
 
10
10
  def initialize options
11
11
  self.http_method = options[:http_method]
12
- self.uri = options[:uri]
12
+ self.path = options[:path]
13
13
  self.headers = options[:headers] || {}
14
14
  self.body = options[:body]
15
15
  self.file = options[:file]
@@ -26,7 +26,7 @@ module TencentCosSdk
26
26
 
27
27
  options = {
28
28
  method: http_method,
29
- url: "https://#{TencentCosSdk.conf.host}#{uri}",
29
+ url: TencentCosSdk.url(path),
30
30
  headers: headers,
31
31
  verify_ssl: false
32
32
  }
@@ -47,11 +47,10 @@ module TencentCosSdk
47
47
  puts response_description
48
48
  end
49
49
 
50
- file_path = uri["#{TencentCosSdk.conf.parent_path}/".length..-1]
51
-
52
- m = /attachment; filename\*="UTF-8''(.+)"/.match response.headers[:content_disposition]
53
- FileUtils.mkdir_p File.dirname(file_path)
54
- IO.binwrite(file_path, response) if m
50
+ if /attachment; filename\*="UTF-8''(.+)"/.match response.headers[:content_disposition]
51
+ FileUtils.mkdir_p File.dirname(path)
52
+ IO.binwrite(path, response)
53
+ end
55
54
 
56
55
  response
57
56
  end
@@ -60,7 +59,7 @@ module TencentCosSdk
60
59
 
61
60
  def description
62
61
  s = "\n\n"
63
- s << "#{http_method.upcase} #{uri} HTTP/1.1\n".light_magenta
62
+ s << "#{http_method.upcase} #{TencentCosSdk.uri(@path)} HTTP/1.1\n".light_magenta
64
63
 
65
64
  headers.each do |k, v|
66
65
  s << "#{k}: #{v}\n".red
@@ -2,6 +2,16 @@ require 'cgi'
2
2
  require 'openssl'
3
3
 
4
4
  module TencentCosSdk
5
+ class << self
6
+ def uri(path)
7
+ "#{TencentCosSdk.conf.parent_path.to_s}/#{path}"
8
+ end
9
+
10
+ def url(path)
11
+ "https://#{TencentCosSdk.conf.host}#{uri path}"
12
+ end
13
+ end
14
+
5
15
  class Request
6
16
  def get_authorization
7
17
  sign_time = "#{Time.now.to_i - 3600};#{Time.now.to_i + 3600}"
@@ -26,7 +36,7 @@ module TencentCosSdk
26
36
 
27
37
  def get_http_string
28
38
  http_string = http_method + "\n"
29
- http_string += uri + "\n"
39
+ http_string += TencentCosSdk.uri(@path) + "\n"
30
40
  http_string += get_params + "\n"
31
41
  http_string += get_headers + "\n"
32
42
  end
@@ -1,3 +1,3 @@
1
1
  module TencentCosSdk
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -9,27 +9,21 @@ module TencentCosSdk
9
9
  # TencentCosSdk.put '1/abc.txt', file: './xyz.txt'
10
10
  #
11
11
  def put path, options = {}
12
- Request.new(options.merge http_method: 'put', uri: uri(path), sign: true).execute
12
+ Request.new(options.merge http_method: 'put', path: path, sign: true).execute
13
13
  end
14
14
 
15
15
  #
16
16
  # TencentCosSdk.get '1/abc.txt'
17
17
  #
18
18
  def get path, options = {}
19
- Request.new(options.merge http_method: 'get', uri: uri(path)).execute
19
+ Request.new(options.merge http_method: 'get', path: path).execute
20
20
  end
21
21
 
22
22
  #
23
23
  # TencentCosSdk.delete '1/abc.txt'
24
24
  #
25
25
  def delete path, options = {}
26
- Request.new(options.merge http_method: 'delete', uri: uri(path), sign: true).execute
27
- end
28
-
29
- private
30
-
31
- def uri path
32
- File.join TencentCosSdk.conf.parent_path, path
26
+ Request.new(options.merge http_method: 'delete', path: path, sign: true).execute
33
27
  end
34
28
  end
35
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tencent_cos_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - xia xiongjun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-24 00:00:00.000000000 Z
11
+ date: 2018-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: openssl