Class: Stupeflixclient::StupeflixClient
Instance Method Summary
collapse
-
#_getAbsoluteUrl(url, followRedirect = false) ⇒ Object
-
#actionUrl(user, resource, profile, action) ⇒ Object
-
#batchEnd ⇒ Object
End a batch: actually send data.
-
#batchStart(maxSize = 1000000) ⇒ Object
Start a batch, used for speeduping video definition upload Operation that can be batched : sendDefinition and createProfiles Operation Only works for xml definition, not zip, and xml must be in UTF8.
-
#createProfiles(user, resource, profiles) ⇒ Object
-
#definitionBatchUrl ⇒ Object
helper functions : build non signed urls for each kind of action.
-
#definitionUrl(user, resource) ⇒ Object
helper functions : build non signed urls for each kind of action.
-
#getDefinition(user, resource, filename) ⇒ Object
-
#getMarker(status) ⇒ Object
-
#getProfile(user, resource, profile, filename) ⇒ Object
-
#getProfileReport(user, resource, profile, filename) ⇒ Object
-
#getProfileReportUrl(user, resource, profile, followRedirect = false) ⇒ Object
-
#getProfileThumb(user, resource, profile, filename) ⇒ Object
-
#getProfileThumbUrl(user, resource, profile, followRedirect = false) ⇒ Object
-
#getProfileUrl(user, resource, profile, followRedirect = false) ⇒ Object
-
#getStatus(user = nil, resource = nil, profile = nil, marker = nil, maxKeys = nil) ⇒ Object
-
#initialize(accessKey, privateKey, host = "http://services.stupeflix.com", service = 'stupeflix-1.0', debug = false) ⇒ StupeflixClient
constructor
A new instance of StupeflixClient.
-
#profileCreateUrl(user, resource, profiles) ⇒ Object
-
#profileReportUrl(user, resource, profile) ⇒ Object
-
#profileThumbUrl(user, resource, profile, thumbname) ⇒ Object
-
#profileUrl(user, resource, profile) ⇒ Object
-
#sendDefinition(user, resource, filename = nil, body = nil) ⇒ Object
Send a definition file to the API.
-
#sendDefinitionBatch(filename = nil, body = nil) ⇒ Object
Send a definition file to the API.
-
#statusUrl(user, resource, profile, marker = nil, maxKeys = nil) ⇒ Object
#answer_error, #connectionGet, #error, #getContent, #getContentUrl, #getContent_, #isZip, #logdebug, #md5FileOrBody, #paramString, #sendContent, #sign, #signUrl, #strToSign
Constructor Details
#initialize(accessKey, privateKey, host = "http://services.stupeflix.com", service = 'stupeflix-1.0', debug = false) ⇒ StupeflixClient
Returns a new instance of StupeflixClient.
7
8
9
10
11
|
# File 'lib/stupeflixclient/stupeflix_client.rb', line 7
def initialize(accessKey, privateKey, host = "http://services.stupeflix.com", service = 'stupeflix-1.0', debug = false)
super(accessKey, privateKey, host, service, debug)
@batch = false
@batchData = ""
end
|
Instance Method Details
#_getAbsoluteUrl(url, followRedirect = false) ⇒ Object
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/stupeflixclient/stupeflix_client.rb', line 66
def _getAbsoluteUrl( url, followRedirect = false)
urlPart = getContentUrl(url, 'GET', nil)
if followRedirect
conn = connection.Connection(@base_url, followRedirect = false)
response = conn.request_get(urlPart)
return response["headers"]["location"]
else
return @base_url + urlPart
end
end
|
#actionUrl(user, resource, profile, action) ⇒ Object
174
175
176
177
178
179
180
181
182
183
184
185
|
# File 'lib/stupeflixclient/stupeflix_client.rb', line 174
def actionUrl( user, resource, profile, action)
path = [user, resource, profile]
s = ""
path.each do |p|
if p == nil
break
end
s += sprintf( "/%s", p )
end
s += sprintf( "/%s/", action )
return s
end
|
#batchEnd ⇒ Object
End a batch: actually send data
24
25
26
27
28
29
|
# File 'lib/stupeflixclient/stupeflix_client.rb', line 24
def batchEnd
@batchData += "</batch>"
sendDefinitionBatch(body = @batchData)
@batchData = ""
@batch = false
end
|
#batchStart(maxSize = 1000000) ⇒ Object
Start a batch, used for speeduping video definition upload Operation that can be batched : sendDefinition and createProfiles Operation Only works for xml definition, not zip, and xml must be in UTF8
17
18
19
20
21
|
# File 'lib/stupeflixclient/stupeflix_client.rb', line 17
def batchStart( maxSize = 1000000)
@batch = true
@batchData = "<batch>"
@batchMaxSize = maxSize
end
|
#createProfiles(user, resource, profiles) ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/stupeflixclient/stupeflix_client.rb', line 107
def createProfiles( user, resource, profiles)
profileData = profiles.xmlGet
if @batch
@batchData += profileData
@batchData += "</task>"
if @batchData.length >= @batchMaxSize
begin
@batchEnd
finally
batchStart(@batchMaxSize)
end
end
else
url, parameters = profileCreateUrl(user, resource, profileData)
contentType = @APPLICATION_URLENCODED_CONTENT_TYPE
body = ""
parameters.each_pair do |k,v|
body += CGI::escape(k) + "=" + CGI::escape(v)
end
return sendContent("POST", url, contentType, filename = nil, body = body)
end
end
|
#definitionBatchUrl ⇒ Object
helper functions : build non signed urls for each kind of action
152
153
154
|
# File 'lib/stupeflixclient/stupeflix_client.rb', line 152
def definitionBatchUrl
return "/batch/"
end
|
#definitionUrl(user, resource) ⇒ Object
helper functions : build non signed urls for each kind of action
147
148
149
|
# File 'lib/stupeflixclient/stupeflix_client.rb', line 147
def definitionUrl( user, resource)
return sprintf( "/%s/%s/definition/", user, resource)
end
|
#getDefinition(user, resource, filename) ⇒ Object
61
62
63
64
|
# File 'lib/stupeflixclient/stupeflix_client.rb', line 61
def getDefinition( user, resource, filename)
url = definitionUrl(user, resource)
return getContent(url, filename)['size']
end
|
#getMarker(status) ⇒ Object
137
138
139
140
141
142
143
144
|
# File 'lib/stupeflixclient/stupeflix_client.rb', line 137
def getMarker( status)
if status.length == 0
return nil
end
lastStatus = status[-1]
return []
end
|
#getProfile(user, resource, profile, filename) ⇒ Object
82
83
84
85
|
# File 'lib/stupeflixclient/stupeflix_client.rb', line 82
def getProfile( user, resource, profile, filename)
url = profileUrl(user, resource, profile)
getContent(url, filename)
end
|
#getProfileReport(user, resource, profile, filename) ⇒ Object
102
103
104
105
|
# File 'lib/stupeflixclient/stupeflix_client.rb', line 102
def getProfileReport( user, resource, profile, filename)
url = profileReportUrl(user, resource, profile)
getContent(url, filename)
end
|
#getProfileReportUrl(user, resource, profile, followRedirect = false) ⇒ Object
97
98
99
100
|
# File 'lib/stupeflixclient/stupeflix_client.rb', line 97
def getProfileReportUrl( user, resource, profile, followRedirect = false)
url = profileReportUrl(user, resource, profile)
return _getAbsoluteUrl(url, followRedirect)
end
|
#getProfileThumb(user, resource, profile, filename) ⇒ Object
92
93
94
95
|
# File 'lib/stupeflixclient/stupeflix_client.rb', line 92
def getProfileThumb( user, resource, profile, filename)
url = profileThumbUrl(user, resource, profile, "thumb.jpg")
getContent(url, filename)
end
|
#getProfileThumbUrl(user, resource, profile, followRedirect = false) ⇒ Object
87
88
89
90
|
# File 'lib/stupeflixclient/stupeflix_client.rb', line 87
def getProfileThumbUrl( user, resource, profile, followRedirect = false)
url = profileThumbUrl(user, resource, profile, "thumb.jpg")
return _getAbsoluteUrl(url, followRedirect)
end
|
#getProfileUrl(user, resource, profile, followRedirect = false) ⇒ Object
77
78
79
80
|
# File 'lib/stupeflixclient/stupeflix_client.rb', line 77
def getProfileUrl( user, resource, profile, followRedirect = false)
url = profileUrl(user, resource, profile)
return _getAbsoluteUrl(url, followRedirect)
end
|
#getStatus(user = nil, resource = nil, profile = nil, marker = nil, maxKeys = nil) ⇒ Object
130
131
132
133
134
135
|
# File 'lib/stupeflixclient/stupeflix_client.rb', line 130
def getStatus( user = nil, resource = nil, profile = nil, marker = nil, maxKeys = nil)
url, parameters = statusUrl(user, resource, profile, marker, maxKeys)
ret = getContent(url, filename = nil, parameters = parameters)
status = JSON.parse(ret['body'])
return status
end
|
#profileCreateUrl(user, resource, profiles) ⇒ Object
168
169
170
171
172
|
# File 'lib/stupeflixclient/stupeflix_client.rb', line 168
def profileCreateUrl( user, resource, profiles)
s = sprintf( "/%s/%s/", user, resource)
parameters = {@XML_PARAMETER => profiles}
return s, parameters
end
|
#profileReportUrl(user, resource, profile) ⇒ Object
164
165
166
|
# File 'lib/stupeflixclient/stupeflix_client.rb', line 164
def profileReportUrl( user, resource, profile)
return sprintf( "/%s/%s/%s/%s/", user, resource, profile, "report.xml")
end
|
#profileThumbUrl(user, resource, profile, thumbname) ⇒ Object
160
161
162
|
# File 'lib/stupeflixclient/stupeflix_client.rb', line 160
def profileThumbUrl( user, resource, profile, thumbname)
return sprintf( "/%s/%s/%s/%s/", user, resource, profile, thumbname)
end
|
#profileUrl(user, resource, profile) ⇒ Object
156
157
158
|
# File 'lib/stupeflixclient/stupeflix_client.rb', line 156
def profileUrl( user, resource, profile)
return sprintf( "/%s/%s/%s/", user, resource, profile)
end
|
#sendDefinition(user, resource, filename = nil, body = nil) ⇒ Object
Send a definition file to the API
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/stupeflixclient/stupeflix_client.rb', line 32
def sendDefinition( user, resource, filename = nil, body = nil)
url = definitionUrl(user, resource)
if body
contentType = @TEXT_XML_CONTENT_TYPE;
elsif isZip(filename)
contentType = @APPLICATION_ZIP_CONTENT_TYPE
else
contentType = @TEXT_XML_CONTENT_TYPE
end
if @batch and contentType == @TEXT_XML_CONTENT_TYPE
@batchData += sprintf("<task user=\"%s\" resource=\"%s\">", user, resource)
if body
@batchData += body
else
@batchData += File.open(filename).read
end
else
return sendContent("PUT", url, contentType, filename, body)
end
end
|
#sendDefinitionBatch(filename = nil, body = nil) ⇒ Object
Send a definition file to the API
55
56
57
58
59
|
# File 'lib/stupeflixclient/stupeflix_client.rb', line 55
def sendDefinitionBatch( filename = nil, body = nil)
url = @definitionBatchUrl
contentType = @TEXT_XML_CONTENT_TYPE;
return sendContent("PUT", url, contentType, filename, body)
end
|
#statusUrl(user, resource, profile, marker = nil, maxKeys = nil) ⇒ Object
187
188
189
190
191
192
193
194
195
196
197
|
# File 'lib/stupeflixclient/stupeflix_client.rb', line 187
def statusUrl( user, resource, profile, marker = nil, maxKeys = nil)
params = {}
if marker != nil
params[@MARKER_PARAMETER] = marker.join('/')
end
if maxKeys != nil
params[@MAXKEYS_PARAMETER] = maxKeys
end
return [actionUrl(user, resource, profile, "status"), params]
end
|