vzaar 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog +5 -0
- data/LICENSE +0 -0
- data/README +12 -0
- data/demo.rb +37 -0
- data/lib/rails/controllers/vzaar_controller.rb +37 -0
- data/lib/rails/views/view_helpers.rb +177 -0
- data/lib/vzaar/account_type.rb +31 -0
- data/lib/vzaar/base.rb +455 -0
- data/lib/vzaar/errors.rb +6 -0
- data/lib/vzaar/signature.rb +31 -0
- data/lib/vzaar/user.rb +28 -0
- data/lib/vzaar/video.rb +38 -0
- data/lib/vzaar/video_details.rb +33 -0
- data/lib/vzaar.rb +67 -0
- data/rails_generators/vzaar_uploader/USAGE +1 -0
- data/rails_generators/vzaar_uploader/templates/flash/swfupload.swf +0 -0
- data/rails_generators/vzaar_uploader/templates/flash/swfupload_fp9.swf +0 -0
- data/rails_generators/vzaar_uploader/templates/images/cancelbutton.gif +0 -0
- data/rails_generators/vzaar_uploader/templates/javascripts/fileprogress.js +197 -0
- data/rails_generators/vzaar_uploader/templates/javascripts/handlers.js +259 -0
- data/rails_generators/vzaar_uploader/templates/javascripts/json_parse.js +345 -0
- data/rails_generators/vzaar_uploader/templates/javascripts/swfupload.js +1132 -0
- data/rails_generators/vzaar_uploader/templates/javascripts/swfupload.queue.js +98 -0
- data/rails_generators/vzaar_uploader/templates/stylesheets/swfupload.css +335 -0
- data/rails_generators/vzaar_uploader/templates/views/uploader.html.erb +15 -0
- data/rails_generators/vzaar_uploader/vzaar_uploader_generator.rb +52 -0
- metadata +114 -0
data/Changelog
ADDED
data/LICENSE
ADDED
File without changes
|
data/README
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
== Vzaar API gem - access and manage your resources on vzaar.com.
|
2
|
+
|
3
|
+
Use the demo.rb example to get started.
|
4
|
+
|
5
|
+
= Installation
|
6
|
+
|
7
|
+
You need following gems as dependencies:
|
8
|
+
|
9
|
+
* httpclient
|
10
|
+
* oauth.
|
11
|
+
|
12
|
+
Author:: Mariusz Lusiak <mailto:mariusz@applicake.com>
|
data/demo.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'vzaar'
|
3
|
+
|
4
|
+
login = ''
|
5
|
+
application_token = ''
|
6
|
+
server_name = 'vzaar.com'
|
7
|
+
|
8
|
+
if (1..3).include? ARGV.size
|
9
|
+
login = ARGV[0]
|
10
|
+
application_token = ARGV[1] if ARGV.size > 1
|
11
|
+
server_name = ARGV[2] if ARGV.size > 2
|
12
|
+
else
|
13
|
+
puts "Usage 1: ruby demo.rb some_vzaar_login"
|
14
|
+
puts "Usage 2: ruby demo.rb your_vzaar_login your_vzaar_application_token"
|
15
|
+
puts "Usage 3: ruby demo.rb your_vzaar_login your_vzaar_application_token server_name"
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
|
19
|
+
vzaar = Vzaar::Base.new :login => login, :application_token => application_token,
|
20
|
+
:server => server_name
|
21
|
+
|
22
|
+
if application_token.length > 0
|
23
|
+
puts 'Testing whoami call.'
|
24
|
+
puts "Whoami: #{vzaar.whoami}"
|
25
|
+
end
|
26
|
+
|
27
|
+
puts "Public videos by #{login}:"
|
28
|
+
vzaar.video_list(login).each do |video|
|
29
|
+
puts video.title
|
30
|
+
end
|
31
|
+
|
32
|
+
if application_token.length > 0
|
33
|
+
puts "All videos (public and private) by #{login}:"
|
34
|
+
vzaar.video_list(login, true).each do |video|
|
35
|
+
puts video.title
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class VzaarController < ApplicationController
|
2
|
+
|
3
|
+
def index
|
4
|
+
respond_to do |format|
|
5
|
+
format.html
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def process_video
|
10
|
+
guid = params[:guid]
|
11
|
+
title = params[:filename]
|
12
|
+
Vzaar.connection.process_video :guid => guid, :title => title,
|
13
|
+
:description => 'some description',
|
14
|
+
:profile => '1'
|
15
|
+
render :nothing => true
|
16
|
+
end
|
17
|
+
|
18
|
+
def signature
|
19
|
+
signature = Vzaar.connection.signature :flash_request => true
|
20
|
+
json_signature = {}
|
21
|
+
json_signature[:AWSAccessKeyId] = signature.aws_access_key
|
22
|
+
json_signature[:key] = signature.key
|
23
|
+
json_signature[:acl] = signature.acl
|
24
|
+
json_signature[:policy] = signature.policy
|
25
|
+
json_signature[:signature] = signature.signature
|
26
|
+
json_signature[:success_action_status] = '201'
|
27
|
+
json_signature['content-type'] = 'binary/octet-stream'
|
28
|
+
json_signature[:guid] = signature.guid
|
29
|
+
respond_to do |format|
|
30
|
+
format.json do
|
31
|
+
render :json => json_signature.to_json
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,177 @@
|
|
1
|
+
require 'vzaar/base'
|
2
|
+
|
3
|
+
module Vzaar
|
4
|
+
|
5
|
+
module ViewHelpers
|
6
|
+
|
7
|
+
def include_vzaar_javascripts
|
8
|
+
javascript_include_tag 'vzaar/json_parse', 'vzaar/swfupload', 'vzaar/handlers',
|
9
|
+
'vzaar/swfupload.queue', 'vzaar/fileprogress'
|
10
|
+
end
|
11
|
+
|
12
|
+
def link_vzaar_stylesheets
|
13
|
+
stylesheet_link_tag 'vzaar/swfupload.css'
|
14
|
+
end
|
15
|
+
|
16
|
+
#
|
17
|
+
# <%=
|
18
|
+
# vzaar_flash_uploader :vzaar_params => {},
|
19
|
+
# :success_url => 'http://localhost/videos/'
|
20
|
+
# %>
|
21
|
+
#
|
22
|
+
# TODO: Handle succuess url correctly
|
23
|
+
#
|
24
|
+
def vzaar_flash_uploader(options = {})
|
25
|
+
default_options = {
|
26
|
+
:flash_request => true,
|
27
|
+
:connection => Vzaar.connection
|
28
|
+
}
|
29
|
+
options = default_options.merge options
|
30
|
+
connection = options[:connection]
|
31
|
+
signature = connection.signature options
|
32
|
+
result = ''
|
33
|
+
result += flash_uploader_script signature, options
|
34
|
+
result += flash_uploader_html
|
35
|
+
result
|
36
|
+
end
|
37
|
+
|
38
|
+
# TODO: documentation
|
39
|
+
# if using metadata you should change x-amz-meta-title and x-amz-meta-profile
|
40
|
+
# to relevant values using javascript
|
41
|
+
# TODO: change to use Vzaar.connection
|
42
|
+
def vzaar_basic_uploader(options = {})
|
43
|
+
default_options = {
|
44
|
+
:success_action_redirect => nil,
|
45
|
+
:include_metadata => false,
|
46
|
+
:vzaar_params => {}
|
47
|
+
}
|
48
|
+
options = default_options.merge options
|
49
|
+
vz = Vzaar::Base.new options[:vzaar_params]
|
50
|
+
signature = vz.signature options
|
51
|
+
upload_form = %Q{
|
52
|
+
<form action="http://#{signature.bucket}.s3.amazonaws.com/" method="post"
|
53
|
+
enctype="multipart/form-data" id="uploadToS3">
|
54
|
+
<div class="uploadFieldsWrapper" style="width:490px; float:left">
|
55
|
+
<input type="hidden" name="key" value="#{signature.key}">
|
56
|
+
<input type="hidden" name="AWSAccessKeyId" value="#{signature.aws_access_key}">
|
57
|
+
<input type="hidden" name="acl" value="#{signature.acl}">
|
58
|
+
<input type="hidden" name="success_action_status" value="201">
|
59
|
+
<input type="hidden" name="policy" value="#{signature.policy}">
|
60
|
+
<input type="hidden" name="signature" value="#{signature.signature}">
|
61
|
+
}
|
62
|
+
if signature.profile and signature.title
|
63
|
+
upload_form += %Q{
|
64
|
+
<input id='vzaar-title' type="hidden" name="x-amz-meta-title"
|
65
|
+
value="#{signature.title}">
|
66
|
+
<input id='vzaar-profile' type="hidden" name="x-amz-meta-profile"
|
67
|
+
value="#{signature.profile}">
|
68
|
+
}
|
69
|
+
end
|
70
|
+
if signature.success_action_redirect
|
71
|
+
upload_form += %Q{
|
72
|
+
<input type="hidden" name="success_action_redirect"
|
73
|
+
value="#{signature.success_action_redirect}">
|
74
|
+
}
|
75
|
+
end
|
76
|
+
upload_form += %Q{
|
77
|
+
<label class='videoFileStep'>video file to be uploaded</label>
|
78
|
+
<input name="file" type="file" id="fileField" onchange="EnableBasicButton();">
|
79
|
+
<br />
|
80
|
+
<input name="upload" type="submit" />
|
81
|
+
</div>
|
82
|
+
</form>
|
83
|
+
}
|
84
|
+
upload_form
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def flash_uploader_post_params(signature)
|
90
|
+
result = {}
|
91
|
+
result[:AWSAccessKeyId] = signature.aws_access_key
|
92
|
+
result[:key] = signature.key
|
93
|
+
result[:acl] = signature.acl
|
94
|
+
result[:policy] = signature.policy
|
95
|
+
result[:signature] = signature.signature
|
96
|
+
result[:success_action_status] = '201'
|
97
|
+
result['content-type'] = 'binary/octet-stream'
|
98
|
+
result
|
99
|
+
end
|
100
|
+
|
101
|
+
def flash_uploader_script(signature, options = {})
|
102
|
+
result = ''
|
103
|
+
result += %Q{
|
104
|
+
<script type="text/javascript">
|
105
|
+
}
|
106
|
+
if options[:success_url]
|
107
|
+
url = options[:success_url]
|
108
|
+
url += url.include?('?') ? '&' : '?'
|
109
|
+
url += "guid=" + signature.guid
|
110
|
+
result += "var successURL = '#{url}';"
|
111
|
+
end
|
112
|
+
result += %Q{
|
113
|
+
var swfu;
|
114
|
+
window.onload = function () {
|
115
|
+
swfu = new SWFUpload({
|
116
|
+
upload_url: "http://#{signature.bucket}.s3.amazonaws.com/",
|
117
|
+
http_success : [201],
|
118
|
+
assume_success_timeout : 0,
|
119
|
+
// File Upload Settings
|
120
|
+
file_post_name: 'file',
|
121
|
+
file_types : "*.*",
|
122
|
+
file_types_description : "All Files",
|
123
|
+
file_upload_limit : "10",
|
124
|
+
file_queue_limit : 0,
|
125
|
+
// Event Handler Settings - these functions as defined in handlers.js
|
126
|
+
file_queued_handler : fileQueued,
|
127
|
+
file_queue_error_handler : fileQueueError,
|
128
|
+
file_dialog_complete_handler : fileDialogComplete,
|
129
|
+
upload_start_handler : uploadStart,
|
130
|
+
upload_progress_handler : uploadProgress,
|
131
|
+
upload_error_handler : uploadError,
|
132
|
+
upload_success_handler : uploadSuccess,
|
133
|
+
upload_complete_handler : uploadComplete,
|
134
|
+
// Button Settings
|
135
|
+
button_width: "65",
|
136
|
+
button_height: "29",
|
137
|
+
button_placeholder_id: "spanButtonPlaceHolder",
|
138
|
+
button_text: '<span class="theFont">Browse</span>',
|
139
|
+
button_text_style: ".theFont { font-size: 16; }",
|
140
|
+
button_text_left_padding: 6,
|
141
|
+
button_text_top_padding: 3,
|
142
|
+
button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
|
143
|
+
button_cursor: SWFUpload.CURSOR.HAND,
|
144
|
+
moving_average_history_size: 10,
|
145
|
+
// Flash Settings
|
146
|
+
flash_url : "/flash/vzaar/swfupload.swf",
|
147
|
+
flash9_url : "/flash/vzaar/swfupload_fp9.swf",
|
148
|
+
custom_settings : {
|
149
|
+
progressTarget : "fsUploadProgress",
|
150
|
+
uploaded_files : []
|
151
|
+
},
|
152
|
+
// Debug Settings
|
153
|
+
debug: false
|
154
|
+
});
|
155
|
+
};
|
156
|
+
</script>
|
157
|
+
}
|
158
|
+
result
|
159
|
+
end
|
160
|
+
|
161
|
+
def flash_uploader_html
|
162
|
+
result = %Q{
|
163
|
+
<div id="content">
|
164
|
+
<form id="vzaar_upload" action="" method="post" enctype="multipart/form-data">
|
165
|
+
<div class="fieldset flash" id="fsUploadProgress">
|
166
|
+
<span class="legend">Upload Queue</span>
|
167
|
+
</div>
|
168
|
+
<span id="spanButtonPlaceHolder"></span>
|
169
|
+
</form>
|
170
|
+
</div>
|
171
|
+
}
|
172
|
+
result
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Vzaar
|
2
|
+
|
3
|
+
class AccountType
|
4
|
+
|
5
|
+
attr_accessor :xml, :version, :id, :title, :monthly, :currency, :bandwidth,
|
6
|
+
:borderless, :search_enhancer
|
7
|
+
|
8
|
+
def initialize(xml)
|
9
|
+
@xml = xml
|
10
|
+
doc = REXML::Document.new xml
|
11
|
+
@version = doc.elements['account/version'] ?
|
12
|
+
doc.elements['account/version'].text : ''
|
13
|
+
@id = doc.elements['account/account_id'] ?
|
14
|
+
doc.elements['account/account_id'].text : ''
|
15
|
+
@title = doc.elements['account/title'] ?
|
16
|
+
doc.elements['account/title'].text : ''
|
17
|
+
@monthly = doc.elements['account/cost/monthly'] ?
|
18
|
+
doc.elements['account/cost/monthly'].text : ''
|
19
|
+
@currency = doc.elements['account/cost/currency'] ?
|
20
|
+
doc.elements['account/cost/currency'].text : ''
|
21
|
+
@bandwidth = doc.elements['account/bandwidth'] ?
|
22
|
+
doc.elements['account/bandwidth'].text : ''
|
23
|
+
@borderless = doc.elements['account/rights/borderless'] ?
|
24
|
+
doc.elements['account/rights/borderless'].text : ''
|
25
|
+
@search_enhancer = doc.elements['account/rights/searchEnhancer'] ?
|
26
|
+
doc.elements['account/rights/searchEnhancer'].text : ''
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|