Class: MultiVideoStreaming::Drivers::S3

Inherits:
Protocols::Platform show all
Defined in:
lib/multi_video_streaming/drivers/s3.rb

Constant Summary collapse

PARAMS_EQUIVALENT =
{
  "key" => :video_id,
  "title" => :title,
  "status" => :status,
  "files" => :files,
  "available_resolutions" => :available_resolutions,
  "direct_play" => :direct_play,
  "date_uploaded" => :date_uploaded
}
STATUS_EQUIVALENT =
{
  :true => "available",
  :false => "failed"
}

Instance Attribute Summary

Attributes inherited from Protocols::Platform

#dependency_params, #https_service_instance, #required_fields_validator_instance, #response_instance

Instance Method Summary collapse

Methods inherited from Protocols::Platform

#initialize

Methods included from Protocols::Interface

#method

Constructor Details

This class inherits a constructor from MultiVideoStreaming::Protocols::Platform

Instance Method Details

#delete_videoObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/multi_video_streaming/drivers/s3.rb', line 83

def delete_video()
  begin
    video_id, bucket = self.dependency_params.values_at(:video_id, :bucket)
    self.required_fields_validator_instance.validate(bucket: bucket)

    configure_credentials
  
    response = Aws::S3::Resource.new().bucket(bucket).object(video_id)
    response.data
    response.delete

    return self.response_instance.add_response(
      platform_name: "s3",
      status: "success",
      original_status_code: 200,
      data: {},
      message:  "Video deleted successfully."
    )

  rescue Aws::Errors::MissingCredentialsError => exception
    return self.response_instance.add_response(
      platform_name: "s3",
      status: "error",
      original_status_code: 401,
      data: {},
      message: exception.message
    )
  rescue Aws::S3::Errors::NotFound
    return self.response_instance.add_response(
      platform_name: "s3",
      status: "error",
      original_status_code: 404,
      data: {},
      message: "Video or bucket does not exist."
    )
  rescue => exception
    return self.response_instance.add_response(
      platform_name: "s3",
      status: "error",
      original_status_code: 500,
      data: {},
      message: exception.message || MultiVideoStreaming::Helpers::GetDefaultErrorMessage.by_method(method: :delete)
    )
  end
end

#get_videoObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/multi_video_streaming/drivers/s3.rb', line 21

def get_video()
  begin
    video_id, bucket = self.dependency_params.values_at(:video_id, :bucket)

    self.required_fields_validator_instance.validate(bucket: bucket)

    configure_credentials

    response = Aws::S3::Resource.new().bucket(bucket).object(video_id)
    video_url = response.public_url

    url_signed = MultiVideoStreaming::Utils::S3.generate_presign_url(method: :get, bucket: bucket, key: video_id, download: false, expires_in: 900)
    data = {
      "key": response.key,
      "title": response.key,
      "status":  STATUS_EQUIVALENT[:true],
      "files": [
        {
          file: url_signed
        }
      ],
      "available_resolutions": [],
      "direct_play": url_signed,
      "date_uploaded": response.data.last_modified
    }

    return self.response_instance.add_response(
      platform_name: "s3",
      status: "success",
      original_status_code: 200,
      data: data,
      params_equivalent: PARAMS_EQUIVALENT,
      message:  "Video found successfully."
    )

  rescue Aws::Errors::MissingCredentialsError => exception
    return self.response_instance.add_response(
      platform_name: "s3",
      status: "error",
      original_status_code: 401,
      data: {},
      message: exception.message
    )
  rescue Aws::S3::Errors::NotFound => e
    return self.response_instance.add_response(
      platform_name: "s3",
      status: "error",
      original_status_code: 404,
      data: {},
      message: "Video or bucket does not exist."
    )
  rescue => exception
    return self.response_instance.add_response(
      platform_name: "s3",
      status: "error",
      original_status_code: 500,
      data: {},
      message: exception.message || MultiVideoStreaming::Helpers::GetDefaultErrorMessage.by_method(method: :get)
    )
  end
end