Sha256: 1c433300a396fdac5b9bbbba71daf6e1a77230207087362503f5638ff056b8e1

Contents?: true

Size: 788 Bytes

Versions: 1

Compression:

Stored size: 788 Bytes

Contents

module Applicants
  class VideoUrlUtility

    def initialize(video_url)
      @video_url = video_url
    end

    def strip_params
      @video_url.split("?").first
    end

    def temporary(expires_in_seconds=3600)
      Aws::S3::Presigner.new(client: client)
        .presigned_url(
          :get_object,
          bucket:     bucket,
          key:        key,
          expires_in: expires_in_seconds
        )
    end

    def remove!
      Aws::S3::Object.new(bucket, key, client: client).delete
    end

  private

    def client
      @client ||= Aws::S3::Client.new(region: 'us-west-1')
    end

    def bucket
      uri.host.split('.').first
    end

    def key
      uri.path[1..uri.path.size]
    end

    def uri
      @_uri ||= URI.parse(strip_params)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
applicants-0.11.0 app/lib/applicants/video_url_utility.rb