Class: Sorenson::Services::Asset

Inherits:
Base show all
Defined in:
lib/sorenson/services/asset.rb

Overview

Allows you to access the resources associated with a sorenson services asset. An asset currently refers to video content.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

delete_from, get_from, host, login_no_resource, parse_response, post_to, put_to, verify_account_settings

Constructor Details

#initialize(data) ⇒ Asset

Returns a new instance of Asset.



142
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
# File 'lib/sorenson/services/asset.rb', line 142

def initialize(data)
  @encode_date         = data['encode_date']
  @frame_rate          = data['frame_rate']
  @height              = data['height']
  @date_last_modified  = data['date_last_modified']
  @video_bitrate_mode  = data['video_bitrate_mode']
  @media_type          = data['media_type']
  @id                  = data['id']
  @account_id          = data['account_id']
  @number_of_views     = data['number_of_views']
  @application         = data['application']
  @audio_codec         = data['audio_codec']
  @permalink_location  = data['permalink_location']
  @status              = data['status']
  @description         = data['description']
  @video_duration      = data['video_duration']
  @abstract_file_id    = data['abstract_file_id']
  @version_id          = data['version_id']
  @date_retrieved      = data['date_retrieved']
  @audio_data_rate     = data['audio_data_rate']
  @audio_bitrate_mode  = data['audio_bitrate_mode']
  @video_codec         = data['video_codec']
  @display_name        = data['display_name']
  @name                = data['name']
  @video_data_rate     = data['video_data_rate']
  @author_id           = data['author_id']
  @width               = data['width']
  @file_size           = data['file_size']
  @thumbnail_image_url = data['thumbnail_image_url']
  @direct_asset_url    = data['direct_asset_url']
  @group_id            = data['group_id']
  @embed_list          = data['embed_list']
  @video_guid          = @embed_list.empty? ? nil : @embed_list.to_a.first[1].match(/videoGUID=(.*?)&/)[1]
end

Instance Attribute Details

#abstract_file_idObject

Returns the value of attribute abstract_file_id.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def abstract_file_id
  @abstract_file_id
end

#account_idObject

Returns the value of attribute account_id.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def 
  @account_id
end

#applicationObject

Returns the value of attribute application.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def application
  @application
end

#audio_bitrate_modeObject

Returns the value of attribute audio_bitrate_mode.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def audio_bitrate_mode
  @audio_bitrate_mode
end

#audio_codecObject

Returns the value of attribute audio_codec.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def audio_codec
  @audio_codec
end

#audio_data_rateObject

Returns the value of attribute audio_data_rate.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def audio_data_rate
  @audio_data_rate
end

#author_idObject

Returns the value of attribute author_id.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def author_id
  @author_id
end

#date_last_modifiedObject

Returns the value of attribute date_last_modified.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def date_last_modified
  @date_last_modified
end

#date_retrievedObject

Returns the value of attribute date_retrieved.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def date_retrieved
  @date_retrieved
end

#descriptionObject

Returns the value of attribute description.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def description
  @description
end

#direct_asset_urlObject

Returns the value of attribute direct_asset_url.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def direct_asset_url
  @direct_asset_url
end

#display_nameObject

Returns the value of attribute display_name.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def display_name
  @display_name
end

#embed_listObject

Returns the value of attribute embed_list.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def embed_list
  @embed_list
end

#encode_dateObject

Returns the value of attribute encode_date.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def encode_date
  @encode_date
end

#file_sizeObject

Returns the value of attribute file_size.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def file_size
  @file_size
end

#frame_rateObject

Returns the value of attribute frame_rate.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def frame_rate
  @frame_rate
end

#group_idObject

Returns the value of attribute group_id.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def group_id
  @group_id
end

#heightObject

Returns the value of attribute height.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def height
  @height
end

#idObject

Returns the value of attribute id.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def id
  @id
end

#media_typeObject

Returns the value of attribute media_type.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def media_type
  @media_type
end

#metadataObject

Returns the value of attribute metadata.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def 
  @metadata
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def name
  @name
end

#number_of_viewsObject

Returns the value of attribute number_of_views.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def number_of_views
  @number_of_views
end

#passwordObject

Returns the value of attribute password.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def password
  @password
end

Returns the value of attribute permalink_location.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def permalink_location
  @permalink_location
end

#statusObject

Returns the value of attribute status.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def status
  @status
end

#streaming_server_and_video_pathObject

Returns the value of attribute streaming_server_and_video_path.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def streaming_server_and_video_path
  @streaming_server_and_video_path
end

#thumbnail_image_urlObject

Returns the value of attribute thumbnail_image_url.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def thumbnail_image_url
  @thumbnail_image_url
end

#version_idObject

Returns the value of attribute version_id.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def version_id
  @version_id
end

#video_bitrate_modeObject

Returns the value of attribute video_bitrate_mode.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def video_bitrate_mode
  @video_bitrate_mode
end

#video_codecObject

Returns the value of attribute video_codec.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def video_codec
  @video_codec
end

#video_data_rateObject

Returns the value of attribute video_data_rate.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def video_data_rate
  @video_data_rate
end

#video_durationObject

Returns the value of attribute video_duration.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def video_duration
  @video_duration
end

#video_guidObject

Returns the value of attribute video_guid.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def video_guid
  @video_guid
end

#widthObject

Returns the value of attribute width.



9
10
11
# File 'lib/sorenson/services/asset.rb', line 9

def width
  @width
end

Class Method Details

.all(offset = nil, quantity = nil) ⇒ Object

Get all of the assets as a list of guids. Use offset and quantity to return subsets.

Sorenson::Services::Account.login('username', 'password')
assets = Sorenson::Services::Asset.all
names  = assets.collect {|asset| asset.name}
=> names = ["name1", "name2"]


21
22
23
24
# File 'lib/sorenson/services/asset.rb', line 21

def self.all(offset = nil, quantity = nil)
  list = get_from("/assets", :offset => offset, :quantity => quantity)["asset_list"]
  list.collect {|a| new(a) }
end

.countObject



39
40
41
# File 'lib/sorenson/services/asset.rb', line 39

def self.count
  Base.get_from("/assets/count")["count"]
end

.find(id) ⇒ Object



43
44
45
46
47
# File 'lib/sorenson/services/asset.rb', line 43

def self.find(id)
  data = get_from("/assets/#{id}")
  return nil if data[:status].eql?('invalid asset id')
  new(data)
end

.find_all_by_flag(flag_name) ⇒ Object



31
32
33
# File 'lib/sorenson/services/asset.rb', line 31

def self.find_all_by_flag(flag_name)
  get_from("/flags/#{flag_name}/assets", :account_id => )
end

.find_all_by_tag(tag_name) ⇒ Object

Get a list of asset guids by passing a tag name



27
28
29
# File 'lib/sorenson/services/asset.rb', line 27

def self.find_all_by_tag(tag_name)
  get_from("/tags/#{tag_name}/assets", :account_id => )
end

Instance Method Details

#activateObject



57
58
59
# File 'lib/sorenson/services/asset.rb', line 57

def activate
  Base.post_to("/assets/#{id}/activate")["status"]
end

#add_category(name) ⇒ Object



69
70
71
# File 'lib/sorenson/services/asset.rb', line 69

def add_category(name)
  Category.new(Base.post_to("/assets/#{id}/categories", :category => {:name => name}))
end

#add_flags(flags) ⇒ Object



97
98
99
# File 'lib/sorenson/services/asset.rb', line 97

def add_flags(flags)
  Base.post_to("/assets/#{id}/flags", {:flag_list => flags})
end

#add_group(group) ⇒ Object



124
125
126
127
128
129
130
131
# File 'lib/sorenson/services/asset.rb', line 124

def add_group(group)
  data = Base.put_to("/groups/#{group.id}/assets/#{id}")
  if data['status'].eql?('Success')
    @group_id = group.id
  else
    data['status']
  end
end

#add_tags(tags) ⇒ Object



89
90
91
# File 'lib/sorenson/services/asset.rb', line 89

def add_tags(tags)
  Base.post_to("/assets/#{id}/tags", { :tag_list => tags })
end

#categoryObject



79
80
81
82
83
# File 'lib/sorenson/services/asset.rb', line 79

def category
  data = Base.get_from("/assets/#{id}/categories")
  return nil if data["result"] == 'failure'
  Category.new(data)
end

#deactivateObject



53
54
55
# File 'lib/sorenson/services/asset.rb', line 53

def deactivate
  Base.post_to("/assets/#{id}/deactivate")["status"]
end

#delete_metadata(key) ⇒ Object



101
102
103
# File 'lib/sorenson/services/asset.rb', line 101

def (key)
  Base.delete_from("/assets/#{id}/metadata/#{key}")[:status]
end

#destroyObject



61
62
63
# File 'lib/sorenson/services/asset.rb', line 61

def destroy
  Base.delete_from("/assets/#{id}")["status"]
end

#embed_codesObject



85
86
87
# File 'lib/sorenson/services/asset.rb', line 85

def embed_codes
  Base.get_from("/assets/#{id}/embed_codes")['embed_codes']
end

#flagsObject



93
94
95
# File 'lib/sorenson/services/asset.rb', line 93

def flags
  Base.get_from("/assets/#{id}/flags")
end

#get_metadata_value(key) ⇒ Object



105
106
107
108
109
# File 'lib/sorenson/services/asset.rb', line 105

def (key)
  data = Base.get_from("/assets/#{id}/metadata/#{key}")
  return nil if data["status"] == 404
  data["result"]
end

#groupObject



119
120
121
122
# File 'lib/sorenson/services/asset.rb', line 119

def group
  return nil if @group_id.nil?
  Group.new(Base.get_from("/groups/#{group_id}")['group'])
end

#preset_xmlObject



49
50
51
# File 'lib/sorenson/services/asset.rb', line 49

def preset_xml
  Base.get_from("/assets/#{id}/preset_xml")["preset_xml"]
end

#remove_categoryObject



73
74
75
76
77
# File 'lib/sorenson/services/asset.rb', line 73

def remove_category
  category = self.category
  return true if category.nil?
  Base.delete_from("/assets/#{id}/categories/#{category.id}")
end

#save(attributes = {}) ⇒ Object



65
66
67
# File 'lib/sorenson/services/asset.rb', line 65

def save(attributes={})
  Base.put_to("/assets/#{id}", :asset => {:name => name, :password => password, :description => description}.merge(attributes))
end

#set_metadata(key, value) ⇒ Object



111
112
113
# File 'lib/sorenson/services/asset.rb', line 111

def (key, value)
  data = Base.post_to("/assets/#{id}/metadata", {:key => key, :value => value})
end

#tagsObject



35
36
37
# File 'lib/sorenson/services/asset.rb', line 35

def tags
  Base.get_from("/assets/#{id}/tags")
end