Class: Stupeflix::StupeflixClient
- Inherits:
-
Base
- Object
- Base
- Stupeflix::StupeflixClient
show all
- Defined in:
- lib/stupeflix.rb
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
Methods inherited from Base
#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.
9
10
11
12
13
|
# File 'lib/stupeflix.rb', line 9
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
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/stupeflix.rb', line 68
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
176
177
178
179
180
181
182
183
184
185
186
187
|
# File 'lib/stupeflix.rb', line 176
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
26
27
28
29
30
31
|
# File 'lib/stupeflix.rb', line 26
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
19
20
21
22
23
|
# File 'lib/stupeflix.rb', line 19
def batchStart( maxSize = 1000000)
@batch = true
@batchData = "<batch>"
@batchMaxSize = maxSize
end
|
#createProfiles(user, resource, profiles) ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
# File 'lib/stupeflix.rb', line 109
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
154
155
156
|
# File 'lib/stupeflix.rb', line 154
def definitionBatchUrl
return "/batch/"
end
|
#definitionUrl(user, resource) ⇒ Object
helper functions : build non signed urls for each kind of action
149
150
151
|
# File 'lib/stupeflix.rb', line 149
def definitionUrl( user, resource)
return sprintf( "/%s/%s/definition/", user, resource)
end
|
#getDefinition(user, resource, filename) ⇒ Object
63
64
65
66
|
# File 'lib/stupeflix.rb', line 63
def getDefinition( user, resource, filename)
url = definitionUrl(user, resource)
return getContent(url, filename)['size']
end
|
#getMarker(status) ⇒ Object
139
140
141
142
143
144
145
146
|
# File 'lib/stupeflix.rb', line 139
def getMarker( status)
if status.length == 0
return nil
end
lastStatus = status[-1]
return []
end
|
#getProfile(user, resource, profile, filename) ⇒ Object
84
85
86
87
|
# File 'lib/stupeflix.rb', line 84
def getProfile( user, resource, profile, filename)
url = profileUrl(user, resource, profile)
getContent(url, filename)
end
|
#getProfileReport(user, resource, profile, filename) ⇒ Object
104
105
106
107
|
# File 'lib/stupeflix.rb', line 104
def getProfileReport( user, resource, profile, filename)
url = profileReportUrl(user, resource, profile)
getContent(url, filename)
end
|
#getProfileReportUrl(user, resource, profile, followRedirect = false) ⇒ Object
99
100
101
102
|
# File 'lib/stupeflix.rb', line 99
def getProfileReportUrl( user, resource, profile, followRedirect = false)
url = profileReportUrl(user, resource, profile)
return _getAbsoluteUrl(url, followRedirect)
end
|
#getProfileThumb(user, resource, profile, filename) ⇒ Object
94
95
96
97
|
# File 'lib/stupeflix.rb', line 94
def getProfileThumb( user, resource, profile, filename)
url = profileThumbUrl(user, resource, profile, "thumb.jpg")
getContent(url, filename)
end
|
#getProfileThumbUrl(user, resource, profile, followRedirect = false) ⇒ Object
89
90
91
92
|
# File 'lib/stupeflix.rb', line 89
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
79
80
81
82
|
# File 'lib/stupeflix.rb', line 79
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
132
133
134
135
136
137
|
# File 'lib/stupeflix.rb', line 132
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
170
171
172
173
174
|
# File 'lib/stupeflix.rb', line 170
def profileCreateUrl( user, resource, profiles)
s = sprintf( "/%s/%s/", user, resource)
parameters = {@XML_PARAMETER => profiles}
return s, parameters
end
|
#profileReportUrl(user, resource, profile) ⇒ Object
166
167
168
|
# File 'lib/stupeflix.rb', line 166
def profileReportUrl( user, resource, profile)
return sprintf( "/%s/%s/%s/%s/", user, resource, profile, "report.xml")
end
|
#profileThumbUrl(user, resource, profile, thumbname) ⇒ Object
162
163
164
|
# File 'lib/stupeflix.rb', line 162
def profileThumbUrl( user, resource, profile, thumbname)
return sprintf( "/%s/%s/%s/%s/", user, resource, profile, thumbname)
end
|
#profileUrl(user, resource, profile) ⇒ Object
158
159
160
|
# File 'lib/stupeflix.rb', line 158
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/stupeflix.rb', line 34
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
57
58
59
60
61
|
# File 'lib/stupeflix.rb', line 57
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
189
190
191
192
193
194
195
196
197
198
199
|
# File 'lib/stupeflix.rb', line 189
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
|