Sha256: 153d0f2595b6720674825a3d899c35a52242b0a49ff36c2d58f6dd5da7c58369

Contents?: true

Size: 1020 Bytes

Versions: 1

Compression:

Stored size: 1020 Bytes

Contents

require "aws-sdk-s3"

module Alephant
  module Harness
    module Service
      module S3
        def self.create(id)
          client.create_bucket(bucket: id)
        end

        def self.delete(id)
          s3 = Aws::S3::Resource.new(client: client)
          s3.bucket(id).delete
        end

        def self.add_object(id, object_id, data)
          client.put_object(
            body: data,
            bucket: id,
            key: object_id
          )
        end

        def self.get_object(id, object_id)
          client.get_object(
            bucket: id,
            key: object_id
          )
        end

        def self.bucket_exists?(bucket_id)
          begin
            client.head_bucket(
              bucket: bucket_id
            )
            yield if block_given?
            true
          rescue => e
            false
          end
        end

        private

        def self.client
          @client ||= ::Aws::S3::Client.new(AWS.s3_config)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alephant-harness-1.0.0 lib/alephant/harness/service/s3.rb