Class: BOTR::Video

Inherits:
Object show all
Defined in:
lib/botr/videos/video.rb

Overview

The BOTR::Video class contains calls for creating (uploading) videos, searching for videos, editing video metadata (title, description, tags etc.) and deleting videos.

A video object is a metadata container that actually contains multiple video files (conversions). It does not reference the actual video file located on the content server.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Authentication

#signature

Methods included from API

#api_call_class, #api_format, #api_key, #api_nonce, #api_protocol, #api_secret_key, #api_server, #api_timestamp, #api_url, #api_version, #progress_url, #upload_address, #upload_key, #upload_protocol, #upload_token, #upload_url

Methods included from HTTP

#client, #delete_request, #get_request, #post_request, #put_request

Constructor Details

#initialize(params = {}) ⇒ Video

Returns a new instance of Video.



115
116
117
118
119
120
121
# File 'lib/botr/videos/video.rb', line 115

def initialize(params = {})
	params.each do |key, val|
		param = "@#{key.to_s}"
		next unless methods.include? key.to_sym
		instance_variable_set(param, val)
	end		
end

Class Attribute Details

.last_statusObject (readonly)

Returns the value of attribute last_status.



14
15
16
# File 'lib/botr/videos/video.rb', line 14

def last_status
  @last_status
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



111
112
113
# File 'lib/botr/videos/video.rb', line 111

def author
  @author
end

#dateObject (readonly)

Returns the value of attribute date.



111
112
113
# File 'lib/botr/videos/video.rb', line 111

def date
  @date
end

#descriptionObject (readonly)

Returns the value of attribute description.



111
112
113
# File 'lib/botr/videos/video.rb', line 111

def description
  @description
end

#download_urlObject (readonly)

Returns the value of attribute download_url.



111
112
113
# File 'lib/botr/videos/video.rb', line 111

def download_url
  @download_url
end

#durationObject (readonly)

Returns the value of attribute duration.



111
112
113
# File 'lib/botr/videos/video.rb', line 111

def duration
  @duration
end

#errorObject (readonly)

Returns the value of attribute error.



111
112
113
# File 'lib/botr/videos/video.rb', line 111

def error
  @error
end

#fileObject (readonly)

Returns the value of attribute file.



111
112
113
# File 'lib/botr/videos/video.rb', line 111

def file
  @file
end

#keyObject (readonly)

Returns the value of attribute key.



111
112
113
# File 'lib/botr/videos/video.rb', line 111

def key
  @key
end

#last_statusObject (readonly)

Returns the value of attribute last_status.



111
112
113
# File 'lib/botr/videos/video.rb', line 111

def last_status
  @last_status
end

Returns the value of attribute link.



111
112
113
# File 'lib/botr/videos/video.rb', line 111

def link
  @link
end

#md5Object (readonly)

Returns the value of attribute md5.



111
112
113
# File 'lib/botr/videos/video.rb', line 111

def md5
  @md5
end

#mediatypeObject (readonly)

Returns the value of attribute mediatype.



111
112
113
# File 'lib/botr/videos/video.rb', line 111

def mediatype
  @mediatype
end

#sizeObject (readonly)

Returns the value of attribute size.



111
112
113
# File 'lib/botr/videos/video.rb', line 111

def size
  @size
end

#sourcetypeObject (readonly)

Returns the value of attribute sourcetype.



111
112
113
# File 'lib/botr/videos/video.rb', line 111

def sourcetype
  @sourcetype
end

#statusObject (readonly)

Returns the value of attribute status.



111
112
113
# File 'lib/botr/videos/video.rb', line 111

def status
  @status
end

#tagsObject (readonly)

Returns the value of attribute tags.



111
112
113
# File 'lib/botr/videos/video.rb', line 111

def tags
  @tags
end

#titleObject (readonly)

Returns the value of attribute title.



111
112
113
# File 'lib/botr/videos/video.rb', line 111

def title
  @title
end

#viewsObject (readonly)

Returns the value of attribute views.



111
112
113
# File 'lib/botr/videos/video.rb', line 111

def views
  @views
end

Class Method Details

.allObject

Note:

Same as calling list with no arguments given.

Return a list of all videos.



87
88
89
# File 'lib/botr/videos/video.rb', line 87

def all
	list({})
end

.list(**options) ⇒ Array

Return a list of videos.

Parameters:

  • options (Hash)

    search parameters

Options Hash (**options):

  • tags (String)

    restrict the search to videos tagged with these tags (multiple tags should be comma-separated)

  • tags_mode (String)

    tags search mode: "all" -- a video will only be listed if it has all tags specified in the tags parameter or "any" -- a video will be listed if it has at least one tag specified in the tags parameter

  • search (String)

    case-insensitive search in the author, description, link, md5, tags, title and video_key fields

  • mediatypes_filter (String)

    list only videos with the specified media types: "unknown", "audio", "video"

  • statuses_filter (String)

    list only videos with the specified statuses: "created", "processing", "ready", "updating", "failed"

  • order_by (String)

    specifies parameters by which returned result should be ordered; ":asc" and ":desc" can be appended accordingly

  • start_date (Integer)

    video creation date starting from which videos list should be returned as a UNIX timestamp

  • end_date (Integer)

    video creation date until (and including) which videos list should be returned as a UNIX timestamp

  • result_limit (Integer)

    specifies maximum number of videos to return; default is 50 and maximum result limit is 1000

  • result_offset (Integer)

    specifies how many videos should be skipped at the beginning of the result set; default is 0

Returns:

  • (Array)

    a list of video objects matching the search criteria



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/botr/videos/video.rb', line 71

def list(**options)
	json = get_request(options.merge(:method => 'list'))
	res = JSON.parse(json.body)
	
	if json.status == 200
		results = process_list_response(res)
	else
		raise "HTTP Error #{json.status}: #{json.body}"
	end

	return results
end

.show(video_key) ⇒ BOTR::Video Also known as: find

Returns a new object with the properties of the video referenced by the video_key.

Parameters:

  • video_key (String)

    key of the video for which to show information

Returns:

  • (BOTR::Video)

    a new object with the properties of the video referenced by the video_key



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/botr/videos/video.rb', line 23

def show(video_key)
	json = get_request({:method => 'show', :video_key => video_key})
	res = JSON.parse(json.body)

	if json.status == 200
		params = process_show_response(res)
	else
		raise "HTTP Error #{json.status}: #{json.body}"
	end

	return new(params)
end

Instance Method Details

#create(**options) ⇒ BOTR::Video

Create a new video by sending metadata and requesting an upload URL.

Parameters:

  • options (Hash)

    video parameters

Options Hash (**options):

  • title (String)

    title of the video

  • tags (String)

    tags for the video; multiple tags should be comma-separated

  • description (String)

    description of the video

  • author (String)

    author of the video

  • date (Integer)

    video creation date as UNIX timestamp

  • link (String)

    the URL of the web page where this video is published

  • download_url (String)

    URL from where to fetch a video file; only URLs with the http protocol are supported

  • md5 (String)

    video file MD5 message digest

  • size (Integer)

    video file size

Returns:

  • (BOTR::Video)

    this video object with the parameters specified in the options hash and an upload link



142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/botr/videos/video.rb', line 142

def create(**options)
	json = get_request(options.merge(:method => 'create'))
	res = JSON.parse(json.body)

	if json.status == 200
		process_create_response(res)
	else
		raise "HTTP Error #{json.status}: #{json.body}"
	end

	return self
end

#deleteBOTR::Video

Remove a video and all of its conversions from the server.

Returns:



203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/botr/videos/video.rb', line 203

def delete
	json = delete_request({:video_key => @key})
	res = JSON.parse(json.body)

	if json.status == 200
		process_delete_response(res)
	else
		raise "HTTP Error #{json.status}: #{json.body}"
	end

	return self
end

#update(**options) ⇒ BOTR::Video

Update the properties of a video.

Parameters:

  • options (Hash)

    video parameters

Options Hash (**options):

  • title (String)

    title of the video

  • tags (String)

    tags for the video; multiple tags should be comma-separated

  • description (String)

    description of the video

  • author (String)

    author of the video

  • date (Integer)

    video creation date as UNIX timestamp

  • link (String)

    the URL of the web page where this video is published

  • download_url (String)

    URL from where to fetch a video file; only URLs with the http protocol are supported

  • md5 (String)

    video file MD5 message digest

  • size (Integer)

    video file size

Returns:

  • (BOTR::Video)

    this object with the properties of the video referenced by the options hash



187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/botr/videos/video.rb', line 187

def update(**options)
	json = put_request(options.merge(:video_key => @key))
	res = JSON.parse(json.body)

	if json.status == 200
		process_update_response(res, options)
	else
		raise "HTTP Error #{json.status}: #{json.body}"
	end

	return self
end

#upload(data_path, **options) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/botr/videos/video.rb', line 155

def upload(data_path, **options)
	json = post_request(options, data_path)
	res = JSON.parse(json.body)

	if json.status == 200
		process_upload_response(res)
	else
		raise "HTTP Error #{json.status}: #{json.body}"
	end

	return self
end