three_sixty 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -3,11 +3,9 @@
3
3
 
4
4
  require 'rake'
5
5
  require 'rubygems'
6
- require 'cucumber'
7
- require 'cucumber/rake/task'
8
6
  require 'echoe'
9
7
 
10
- Echoe.new('three_sixty', '1.0.1') do |p|
8
+ Echoe.new('three_sixty', '1.0.2') do |p|
11
9
  p.description = "Ruby bindings for Sorenson 360 Backend"
12
10
  p.url = "https://github.com/sorenson/ThreeSixtyServices-Internal"
13
11
  p.author = "Sorenson Media"
@@ -19,3 +17,4 @@ end
19
17
  Dir['tasks/**/*.rake'].each { |t| load t }
20
18
 
21
19
  task :default => :spec
20
+ task :default => :spec
@@ -1,178 +1,152 @@
1
- # Sorenson Namespace
2
1
  module Sorenson
3
- # Sorenson Services Namespace
4
- module Services
5
- # Allows you to access the resources associated with a sorenson services asset. An asset currently refers to video content.
2
+ module ThreeSixty
6
3
  class Asset < Base
7
4
 
8
-
9
- attr_accessor :encode_date, :frame_rate, :height, :date_last_modified, :video_bitrate_mode,
10
- :media_type, :id, :account_id, :number_of_views, :application, :audio_codec,
11
- :permalink_location, :status, :description, :video_duration, :abstract_file_id, :version_id,
12
- :date_retrieved, :audio_data_rate, :audio_bitrate_mode, :video_codec, :display_name, :name,
13
- :video_data_rate, :author_id, :width, :file_size, :thumbnail_image_url, :direct_asset_url,
14
- :password, :metadata, :embed_list, :group_id, :video_guid, :streaming_server_and_video_path
15
-
16
- # Get all of the assets as a list of guids. Use offset and quantity to return subsets.
17
- # Sorenson::Services::Account.login('username', 'password')
18
- # assets = Sorenson::Services::Asset.all
19
- # names = assets.collect {|asset| asset.name}
20
- # => names = ["name1", "name2"]
21
- def self.all(offset = nil, quantity = nil)
22
- list = get_from("/assets", :offset => offset, :quantity => quantity)["asset_list"]
23
- list.collect {|a| new(a) }
24
- end
25
-
26
- # Get a list of asset guids by passing a tag name
27
- def self.find_all_by_tag(tag_name)
28
- get_from("/tags/#{tag_name}/assets", :account_id => account_id)
29
- end
30
-
31
- def self.find_all_by_flag(flag_name)
32
- get_from("/flags/#{flag_name}/assets", :account_id => account_id)
33
- end
34
-
35
- def tags
36
- Base.get_from("/assets/#{id}/tags")
5
+ # Attributes
6
+ attr_accessor :account, :encodeDate, :frameRate, :height, :dateLastModified, :videoBitrateMode, :mediaType, :id, :accountId, :numberOfViews, :presetXml, :application, :audioCodec, :permalinkLocation, :status, :description, :videoDuration, :abstractFileId, :versionId, :dateRetrieved, :audioDataRate, :audioBitrateMode, :videoCodec, :displayName, :name, :videoDataRate, :authorId, :width, :fileSize, :defaultEmbed, :thumbnailImageUrl, :filters, :embedList, :httpLocation, :directAssetUrl, :subaccountId, :videoGuid
7
+
8
+ # Class Methods
9
+ def self.find_all(account, offset = nil, quantity = nil)
10
+ data = post_to("/api/getMediaList?offset=#{offset}&quantity=#{quantity}&accountId=#{account.id}&sessionId=#{account.sessionId}&status=Live&sort=uploadDate")
11
+
12
+ assets = []
13
+
14
+ data['mediaList'].each do |entry|
15
+ assets << Asset.new(account, entry) if account.subaccountId.blank? || account.subaccountId == entry['subaccountId']
16
+ end
17
+
18
+ assets
19
+ end
20
+
21
+ def self.find(account, id)
22
+ data = post_to("/api/getAsset?mguid=#{id}&sessionId=#{account.sessionId}")
23
+ Asset.new(account, data['media'].merge({'thumbLocation' => data['thumbLocation'], 'permalink' => data['permalinkLocation']}))
24
+ end
25
+
26
+ def self.get_embed_codes(video_guid, sessionId, account)
27
+ data = post_to("/api/getAllEmbedcodes?vguid=#{video_guid}&sessionId=#{account.sessionId}")
28
+ data['embedList']
29
+ end
30
+
31
+ def self.get_streaming_server_url
32
+ "rtmp://cdnstreamingvideos.sorensonmedia.com/cfx/st"
33
+ end
34
+
35
+ # Instance Methods
36
+ def initialize(account, data)
37
+ self.account = account
38
+ self.presetXml = data['presetXml']
39
+ self.subaccountId = data['subaccountId']
40
+ self.encodeDate = data['encodeDate']
41
+ self.frameRate = data['frameRate']
42
+ self.height = data['height']
43
+ self.dateLastModified = data['dateLastModified']
44
+ self.videoBitrateMode = data['videoBitrateMode']
45
+ self.mediaType = data['mediaType']
46
+ self.id = data['id']
47
+ self.accountId = data['accountId']
48
+ self.numberOfViews = data['numberOfViews']
49
+ self.application = data['application']
50
+ self.audioCodec = data['audioCodec']
51
+ self.permalinkLocation = data['permalink']
52
+ self.status = data['status']
53
+ self.description = data['description']
54
+ self.videoDuration = data['videoDuration']
55
+ self.abstractFileId = data['abstractFileId']
56
+ self.versionId = data['versionId']
57
+ self.dateRetrieved = data['dateRetrieved']
58
+ self.audioDataRate = data['audioDataRate']
59
+ self.audioBitrateMode = data['audioBitrateMode']
60
+ self.videoCodec = data['videoCodec']
61
+ self.displayName = data['displayName']
62
+ self.name = data['name']
63
+ self.videoDataRate = data['videoDataRate']
64
+ self.authorId = data['authorId']
65
+ self.width = data['width']
66
+ self.fileSize = data['fileSize']
67
+ self.thumbnailImageUrl = data['thumbnail']['httpLocation'] if data['thumbnail']
68
+ self.thumbnailImageUrl = data['thumbLocation'] if data['thumbLocation']
69
+ self.httpLocation = data['httpLocation']
70
+ self.directAssetUrl = "http://360.sorensonmedia.com/redirector/fetchFile?vguid=#{self.id}"
71
+ self.videoGuid
72
+
73
+ self.filters = []
74
+ if data['filters']
75
+ data['filters'].each do |filter|
76
+ self.filters << filter['filterDescription']
77
+ end
78
+ end
79
+
80
+ self.embedList = {}
81
+ get_embed_codes
82
+
83
+ self.videoGuid = self.embedList.empty? ? nil : self.embedList.to_a.first[1].match(/videoGUID=(.*?)&/)[1]
37
84
  end
38
85
 
39
- def self.count
40
- Base.get_from("/assets/count")["count"]
41
- end
42
-
43
- def self.find(id)
44
- data = get_from("/assets/#{id}")
45
- return nil if data[:status].eql?('invalid asset id')
46
- new(data)
86
+ def get_streaming_video_path
87
+ data = post_to("/api/getPlayerData?vguid=#{self.videoGuid}&cms=true")
88
+ data['media']['accessLocation']['s3KeyName']
47
89
  end
48
90
 
49
- def preset_xml
50
- Base.get_from("/assets/#{id}/preset_xml")["preset_xml"]
91
+ def delete
92
+ data = post_to("/api/deleteAsset?fileVersionId=#{id}&sessionId=#{account.sessionId}")
51
93
  end
52
-
94
+
53
95
  def deactivate
54
- Base.post_to("/assets/#{id}/deactivate")["status"]
96
+ data = post_to("/api/deactivateAsset?fileVersionId=#{id}&sessionId=#{account.sessionId}")
55
97
  end
56
-
98
+
57
99
  def activate
58
- Base.post_to("/assets/#{id}/activate")["status"]
59
- end
60
-
61
- def destroy
62
- Base.delete_from("/assets/#{id}")["status"]
63
- end
64
-
65
- def save(attributes={})
66
- Base.put_to("/assets/#{id}", :asset => {:name => name, :password => password, :description => description}.merge(attributes))
67
- end
68
-
69
- def add_category(name)
70
- Category.new(Base.post_to("/assets/#{id}/categories", :category => {:name => name}))
71
- end
72
-
73
- def remove_category
74
- category = self.category
75
- return true if category.nil?
76
- Base.delete_from("/assets/#{id}/categories/#{category.id}")
100
+ data = post_to("/api/activateAsset?fileVersionId=#{id}&sessionId=#{account.sessionId}")
77
101
  end
78
102
 
79
- def category
80
- data = Base.get_from("/assets/#{id}/categories")
81
- return nil if data["result"] == 'failure'
82
- Category.new(data)
103
+ def setName(name)
104
+ data = post_to("/api/setAssetName?fileVersionId=#{id}&newName=#{name}&sessionId=#{account.sessionId}")
83
105
  end
84
106
 
85
- def embed_codes
86
- Base.get_from("/assets/#{id}/embed_codes")['embed_codes']
107
+ def setDescription(description)
108
+ data = post_to("/api/setAssetDescription?fileVersionId=#{id}&newDescription=#{description}&sessionId=#{account.sessionId}")
87
109
  end
88
-
89
- def add_tags(tags)
90
- Base.post_to("/assets/#{id}/tags", { :tag_list => tags })
91
- end
92
-
93
- def flags
94
- Base.get_from("/assets/#{id}/flags")
95
- end
96
-
97
- def add_flags(flags)
98
- Base.post_to("/assets/#{id}/flags", {:flag_list => flags})
99
- end
100
-
101
- def delete_metadata(key)
102
- Base.delete_from("/assets/#{id}/metadata/#{key}")[:status]
103
- end
104
-
105
- def get_metadata_value(key)
106
- data = Base.get_from("/assets/#{id}/metadata/#{key}")
107
- return nil if data["status"] == 404
108
- data["result"]
109
- end
110
-
111
- def set_metadata(key, value)
112
- data = Base.post_to("/assets/#{id}/metadata", {:key => key, :value => value})
113
- end
114
-
115
- def metadata
116
- Base.get_from("/assets/#{id}/metadata")
117
- end
118
-
119
- def group
120
- return nil if @group_id.nil?
121
- Group.new(Base.get_from("/groups/#{group_id}")['group'])
122
- end
123
-
124
- def add_group(group)
125
- data = Base.put_to("/groups/#{group.id}/assets/#{id}")
126
- if data['status'].eql?('Success')
127
- @group_id = group.id
110
+
111
+ def setPassword(password)
112
+ data = nil
113
+ if password == '' || password.nil?
114
+ data = post_to("/api/removeAssetSecurity?fileVersionId=#{id}&security=#{password}&sessionId=#{account.sessionId}")
128
115
  else
129
- data['status']
116
+ data = post_to("/api/setAssetSecurity?fileVersionId=#{id}&security=#{password}&sessionId=#{account.sessionId}")
130
117
  end
131
- end
132
-
133
- def streaming_server_and_video_path
134
- data = Base.get_from("/videos/#{id}/streaming_url")
135
- if data['status'].eql?("not found")
136
- nil
137
- else
138
- data
118
+ data
119
+ end
120
+
121
+ def getAllSubaccounts
122
+ data = post_to("/api/getAllSubaccount?accountId=#{id}&sessionId=#{sessionId}")
123
+ data
124
+ end
125
+
126
+ private
127
+ def get_embed_codes
128
+ data = post_to("/api/getAllEmbedcodes?vguid=#{id}&sessionId=#{account.sessionId}")
129
+
130
+ if data['embedList']
131
+ data['embedList'].each do |embed|
132
+ embed =~ /width="(\d+)"/
133
+ width = $1
134
+
135
+ embed =~ /height="(\d+)"/
136
+ height = $1
137
+
138
+ ratio = (width.to_f / height.to_f)
139
+
140
+ aspect = (ratio <= 1.33 ? 'Full Screen' : 'Widescreen')
141
+
142
+ self.embedList["#{width}x#{height} - #{aspect}"] = embed
143
+
144
+ end
139
145
  end
146
+
147
+ self.defaultEmbed = data['defaultEmbed']
140
148
  end
141
149
 
142
- def initialize(data)
143
- @encode_date = data['encode_date']
144
- @frame_rate = data['frame_rate']
145
- @height = data['height']
146
- @date_last_modified = data['date_last_modified']
147
- @video_bitrate_mode = data['video_bitrate_mode']
148
- @media_type = data['media_type']
149
- @id = data['id']
150
- @account_id = data['account_id']
151
- @number_of_views = data['number_of_views']
152
- @application = data['application']
153
- @audio_codec = data['audio_codec']
154
- @permalink_location = data['permalink_location']
155
- @status = data['status']
156
- @description = data['description']
157
- @video_duration = data['video_duration']
158
- @abstract_file_id = data['abstract_file_id']
159
- @version_id = data['version_id']
160
- @date_retrieved = data['date_retrieved']
161
- @audio_data_rate = data['audio_data_rate']
162
- @audio_bitrate_mode = data['audio_bitrate_mode']
163
- @video_codec = data['video_codec']
164
- @display_name = data['display_name']
165
- @name = data['name']
166
- @video_data_rate = data['video_data_rate']
167
- @author_id = data['author_id']
168
- @width = data['width']
169
- @file_size = data['file_size']
170
- @thumbnail_image_url = data['thumbnail_image_url']
171
- @direct_asset_url = data['direct_asset_url']
172
- @group_id = data['group_id']
173
- @embed_list = data['embed_list']
174
- @video_guid = @embed_list.empty? ? nil : @embed_list.to_a.first[1].match(/videoGUID=(.*?)&/)[1]
175
- end
176
150
  end
177
151
  end
178
152
  end
data/three_sixty.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{three_sixty}
5
- s.version = "1.0.1"
5
+ s.version = "1.0.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Sorenson Media"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: three_sixty
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sorenson Media