Class: OssServerClient
- Inherits:
-
Object
- Object
- OssServerClient
- Defined in:
- lib/client/oss_server_client.rb
Instance Attribute Summary collapse
-
#bucket ⇒ Object
Returns the value of attribute bucket.
-
#oss_client ⇒ Object
Returns the value of attribute oss_client.
Instance Method Summary collapse
- #get_bucket ⇒ Object
- #get_oss_client ⇒ Object
-
#initialize ⇒ OssServerClient
constructor
A new instance of OssServerClient.
- #send(oss_path, file_path) ⇒ Object
- #send_stream(oss_path, stream) ⇒ Object
Constructor Details
#initialize ⇒ OssServerClient
Returns a new instance of OssServerClient.
7 8 9 10 |
# File 'lib/client/oss_server_client.rb', line 7 def initialize get_oss_client get_bucket end |
Instance Attribute Details
#bucket ⇒ Object
Returns the value of attribute bucket.
5 6 7 |
# File 'lib/client/oss_server_client.rb', line 5 def bucket @bucket end |
#oss_client ⇒ Object
Returns the value of attribute oss_client.
4 5 6 |
# File 'lib/client/oss_server_client.rb', line 4 def oss_client @oss_client end |
Instance Method Details
#get_bucket ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/client/oss_server_client.rb', line 36 def get_bucket bucket = ENV["CRAWLAB_OSS_BUCKET"] if bucket == nil || bucket == "" return end @bucket = @oss_client.get_bucket(bucket) end |
#get_oss_client ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/client/oss_server_client.rb', line 12 def get_oss_client endpoint = ENV["CRAWLAB_OSS_ENDPOINT"] access_key_id = ENV["CRAWLAB_OSS_ACCESS_KEY"] access_key_secret = ENV["CRAWLAB_OSS_SECRET"] bucket = ENV["CRAWLAB_OSS_BUCKET"] if endpoint == nil || endpoint == "" return end if access_key_id == nil || access_key_id == "" return end if access_key_secret == nil || access_key_secret == "" return end if bucket == nil || bucket == "" return end @oss_client = Aliyun::OSS::Client.new( :endpoint => endpoint, :access_key_id => access_key_id, :access_key_secret => access_key_secret) end |
#send(oss_path, file_path) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/client/oss_server_client.rb', line 44 def send(oss_path,file_path) if @bucket == nil || @oss_client == nil return "bucket is nil" end @bucket.put_object(oss_path, :file => file_path) bucket_url = @bucket.object_url(oss_path) return bucket_url end |
#send_stream(oss_path, stream) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/client/oss_server_client.rb', line 54 def send_stream(oss_path,stream) if @bucket == nil || @oss_client == nil return "bucket is nil" end @bucket.put_object(oss_path){ |a| a << stream } bucket_url = @bucket.object_url(oss_path) return bucket_url end |