class BrightcoveCmsApi::Video
Public Class Methods
new(account_id:, client_id:, client_secret:)
click to toggle source
# File lib/brightcove_cms_api/video.rb, line 10 def initialize(account_id:, client_id:, client_secret:) @account_id = account_id @client_id = client_id @client_secret = client_secret set_authtoken end
Public Instance Methods
count()
click to toggle source
Get Video
count
# File lib/brightcove_cms_api/video.rb, line 32 def count check_token_expires @response = HTTP.auth("Bearer #{@token}").get("#{API_URL}/#{@account_id}/counts/videos") send_response end
create(params = {})
click to toggle source
Create Videos
# File lib/brightcove_cms_api/video.rb, line 25 def create(params = {}) check_token_expires @response = HTTP.auth("Bearer #{@token}").post("#{API_URL}/#{@account_id}/videos", { json: params }) send_response end
custom_fields()
click to toggle source
Get custom fields
# File lib/brightcove_cms_api/video.rb, line 81 def custom_fields check_token_expires @response = HTTP.auth("Bearer #{@token}").get("#{API_URL}/#{@account_id}/video_fields") send_response end
delete(video_id)
click to toggle source
delete video
# File lib/brightcove_cms_api/video.rb, line 46 def delete(video_id) check_token_expires @response = HTTP.auth("Bearer #{@token}").delete("#{API_URL}/#{@account_id}/videos/#{video_id}") send_response end
find_all()
click to toggle source
Get Videos
# File lib/brightcove_cms_api/video.rb, line 18 def find_all check_token_expires @response = HTTP.auth("Bearer #{@token}").get("#{API_URL}/#{@account_id}/videos") send_response end
get_by_reference_id(video_id)
click to toggle source
Get Video
by id and reference_id
# File lib/brightcove_cms_api/video.rb, line 39 def get_by_reference_id(video_id) check_token_expires @response = HTTP.auth("Bearer #{@token}").get("#{API_URL}/#{@account_id}/videos/#{video_id}") send_response end
images(video_id)
click to toggle source
Get video images
# File lib/brightcove_cms_api/video.rb, line 60 def images(video_id) check_token_expires @response = HTTP.auth("Bearer #{@token}").get("#{API_URL}/#{@account_id}/videos/#{video_id}/images") send_response end
playlists(video_id)
click to toggle source
get playlists for video
# File lib/brightcove_cms_api/video.rb, line 67 def playlists(video_id) check_token_expires @response = HTTP.auth("Bearer #{@token}").get("#{API_URL}/#{@account_id}/videos/#{video_id}/references") send_response end
remove_from_playlists(video_id)
click to toggle source
remove video from all playlists
# File lib/brightcove_cms_api/video.rb, line 74 def remove_from_playlists(video_id) check_token_expires @response = HTTP.auth("Bearer #{@token}").delete("#{API_URL}/#{@account_id}/videos/#{video_id}/references") send_response end
update(video_id, params = {})
click to toggle source
update video
# File lib/brightcove_cms_api/video.rb, line 53 def update(video_id, params = {}) check_token_expires @response = HTTP.auth("Bearer #{@token}").patch("#{API_URL}/#{@account_id}/videos/#{video_id}", { json: params }) send_response end
Private Instance Methods
check_token_expires()
click to toggle source
# File lib/brightcove_cms_api/video.rb, line 103 def check_token_expires set_authtoken if @token_expires < Time.now end
send_response()
click to toggle source
# File lib/brightcove_cms_api/video.rb, line 107 def send_response case @response.code when 200, 201, 204 @response.parse else raise CmsapiError, @response end end
set_authtoken()
click to toggle source
# File lib/brightcove_cms_api/video.rb, line 89 def set_authtoken response = HTTP.basic_auth(user: @client_id, pass: @client_secret) .post(OAUTH_ENDPOINT, form: { grant_type: "client_credentials" }) token_response = response.parse if response.status == 200 @token = token_response.fetch("access_token") @token_expires = Time.now + token_response.fetch("expires_in") else raise AuthenticationError, token_response.fetch("error_description") end end