lib/s3cabinet.rb in s3cabinet-0.1.0 vs lib/s3cabinet.rb in s3cabinet-0.2.0

- old
+ new

@@ -12,17 +12,19 @@ @bucket = bucket @region = region @region_to_bucket_endpoint = { "us-east-1" => "https://s3.amazonaws.com", - "us-west-2" => "https://s3-us-west-2.amazonaws.com", "us-west-1" => "https://s3-us-west-1.amazonaws.com", + "us-west-2" => "https://s3-us-west-2.amazonaws.com", "eu-west-1" => "https://s3-eu-west-1.amazonaws.com", "eu-central-1" => "https://s3.eu-central-1.amazonaws.com", + "ap-south-1" => "https://s3.ap-south-1.amazonaws.com", + "ap-northeast-1" => "https://s3-ap-northeast-1.amazonaws.com", + "ap-northeast-2" => "https://s3-ap-northeast-2.amazonaws.com", "ap-southeast-1" => "https://s3-ap-southeast-1.amazonaws.com", "ap-southeast-2" => "https://s3-ap-southeast-2.amazonaws.com", - "ap-northeast-1" => "https://s3-ap-northeast-1.amazonaws.com", "sa-east-1" => "https://s3-sa-east-1.amazonaws.com", "cn-north-1" => "https://s3.cn-north-1.amazonaws.com.cn" } if access_id.is_a? Hash @@ -32,31 +34,41 @@ @bucket = hash[:bucket] @region = hash[:region] end end + def endpoint_url + @endpoint_url ||= begin + theurl = @region_to_bucket_endpoint[@region] + + if theurl.nil? + theurl = "https://s3.#{@region}.amazonaws.com" + end + + theurl + end + end + def s3 if @s3 == nil - endpoint = @region_to_bucket_endpoint[@region] + endpoint = endpoint_url if endpoint @s3 = Aws::S3::Client.new(access_key_id: @access_id, secret_access_key: @access_key, region: @region) else @s3 = Aws::S3::Client.new(access_key_id: @access_id, secret_access_key: @access_key, region: "us-east-1", endpoint: @region, force_path_style: true) end end @s3 end def url(key) + the_url = endpoint_url - the_url = @region_to_bucket_endpoint[@region] - if the_url "#{the_url}/#{@bucket}/#{key}" else "#{@region}/#{@bucket}/#{key}" end - end def set(key, value) val_str = { value: value, date: Time.now.to_i }.to_json set_raw(key, val_str)