Class: MultiVideoStreaming::Drivers::Vimeo

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

Constant Summary collapse

PARAMS_EQUIVALENT =
{
  "vimeo_id" => :video_id,
  "name" => :title,
  "status" => :status,
  "files" => :files,
  "available_resolutions" => :available_resolutions,
  "player_embed_url" => :direct_play,
  "created_time" => :date_uploaded
}
STATUS_EQUIVALENT =
{
  "available" => "available",
  "quota_exceeded" => "failed",
  "total_cap_exceeded" => "failed",
  "transcode_starting" => "transcoding",
  "transcoding" => "transcoding",
  "transcoding_error" => "failed",
  "unavailable" => "failed",
  "uploading" => "processing",
  "uploading_error" => "failed"
}
VIMEO_URL =
"https://api.vimeo.com"

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



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/multi_video_streaming/drivers/vimeo.rb', line 143

def delete_video()
  begin
    video_id, token = self.dependency_params.values_at(:video_id, :token)
    self.required_fields_validator_instance.validate(video_id: video_id, token: token)
    @original_status_code = nil

    response = self.https_service_instance.delete(uri: "#{VIMEO_URL}/videos/#{video_id}", headers: { :Authorization => "Bearer #{token}" })

    @original_status_code = response["status_code"]

    if response["status_code"] != 204
      if response["status_code"] == 404
        raise MultiVideoStreaming::Helpers::GetDefaultErrorMessage.not_found(video_id: video_id)
      end

      raise response["developer_message"] || response["error"] || MultiVideoStreaming::Helpers::GetDefaultErrorMessage.by_method(method: :delete)
    end

    return self.response_instance.add_response(
      platform_name: "vimeo",
      status: "success",
      original_status_code: @original_status_code,
      data: {},
      message:  "Video deleted successfully."
    )
  rescue => exception
    return self.response_instance.add_response(
      platform_name: "vimeo",
      status: "error",
      original_status_code: @original_status_code,
      data: {},
      message: exception.message
    )
  end
end

#get_videoObject



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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/multi_video_streaming/drivers/vimeo.rb', line 86

def get_video()
  begin
    video_id, token = self.dependency_params.values_at(:video_id, :token)
    @original_status_code = nil

    self.required_fields_validator_instance.validate(token: token, video_id: video_id)

    response = self.https_service_instance.get(uri: "#{VIMEO_URL}/videos/#{video_id}", headers: { :Authorization => "Bearer #{token}" })

    @original_status_code = response["status_code"]
    if response["status_code"] != 200
      if response["status_code"] == 404
        raise MultiVideoStreaming::Helpers::GetDefaultErrorMessage.not_found(video_id: video_id)
      end

      raise response["developer_message"] || response["error"] || MultiVideoStreaming::Helpers::GetDefaultErrorMessage.by_method(method: :get)
    end

    response["vimeo_id"] = response["uri"].split("/videos/")[1]

    available_resolutions = []
    files = []
    response["files"]&.each do |file|
      if file["rendition"] != "adaptive"
        available_resolutions << file["rendition"]
        files << { file: file["link"], label: file["rendition"] }
      end
    end

    MultiVideoStreaming::Helpers::SortFilesArrayByLabel.sort(array: files)
    response["files"] = files
    response["available_resolutions"] = available_resolutions
    response["status"] = STATUS_EQUIVALENT[response["status"]]

    if response["status"] != "available"
      raise MultiVideoStreaming::Helpers::GetDefaultErrorMessage.not_available
    end

    return self.response_instance.add_response(
      platform_name: "vimeo",
      status: "success",
      original_status_code: @original_status_code,
      data: response,
      params_equivalent: PARAMS_EQUIVALENT,
      message:  "Video found successfully."
    )
  rescue => exception
    return self.response_instance.add_response(
      platform_name: "vimeo",
      status: "error",
      original_status_code: @original_status_code,
      data: {},
      message: exception.message
    )
  end
end

#upload_video(url:) ⇒ Object



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
82
83
84
# File 'lib/multi_video_streaming/drivers/vimeo.rb', line 30

def upload_video(url:)
  begin
    token = self.dependency_params[:token]
    title = MultiVideoStreaming::Helpers::TitleFromUrl.get(url: url)
    @original_status_code = nil

    self.required_fields_validator_instance.validate(token: token)
    response = self.https_service_instance.post(
      uri: "#{VIMEO_URL}/me/videos",
      headers: { :Authorization => "Bearer #{token}", :Accept => "application/vnd.vimeo.*+json;version=3.4" },
      body: {
        :name => title,
        :upload => {
          :approach => "pull",
          :link => url
        },
        :privacy => {
          :download => false,
          :embed => "private",
          :view => "nobody"
        }
      }
    )

    @original_status_code = response["status_code"]

    if response["status_code"] != 201
      raise response["developer_message"] || response["error"] || MultiVideoStreaming::Helpers::GetDefaultErrorMessage.by_method(method: :upload)
    end

    response["vimeo_id"] = response["uri"].split("/videos/")[1]
    response["files"] = []
    response["available_resolutions"] = []
    response["status"] = STATUS_EQUIVALENT[response["status"]]

    return self.response_instance.add_response(
      platform_name: "vimeo",
      status: "success",
      original_status_code: @original_status_code,
      data: response,
      params_equivalent: PARAMS_EQUIVALENT,
      message:  "Video uploaded successfully."
    )

  rescue => exception
    return self.response_instance.add_response(
      platform_name: "vimeo",
      status: "error",
      original_status_code: @original_status_code,
      data: {},
      message: exception.message
    )
  end

end