gemini_upload-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Matthew Zikherman
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # GeminiUpload::Rails
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'gemini_upload-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install gemini_upload-rails
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,5 @@
1
+ module GeminiUpload
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require "gemini_upload/rails/version"
2
+
3
+ module GeminiUpload
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,100 @@
1
+ var $;
2
+ $ = jQuery;
3
+ $.fn.extend({
4
+ geminiUpload: function(options) {
5
+ var encodedCredentials;
6
+ encodedCredentials = this.encode(options.geminiKey, '');
7
+ return $.ajax({
8
+ type: 'GET',
9
+ dataType: 'json',
10
+ url: "" + options.geminiApp + "/uploads/new.json",
11
+ data: {
12
+ acl: options.acl
13
+ },
14
+ headers: {
15
+ 'Authorization': "Basic " + encodedCredentials
16
+ },
17
+ success: (function(_this) {
18
+ return function(resp) {
19
+ return _this.attachFileUploadUI(resp, _.extend(options, {
20
+ credentials: encodedCredentials
21
+ }));
22
+ };
23
+ })(this)
24
+ });
25
+ },
26
+ encode: function(key, secret) {
27
+ return btoa(unescape(encodeURIComponent([key, secret].join(':'))));
28
+ },
29
+ seedForm: function(data, options) {
30
+ var $form, acl, base64Policy, bucket, key, s3Key, signature, successAction, uploadBucket;
31
+ bucket = data.policy_document.conditions[0].bucket;
32
+ key = "" + data.policy_document.conditions[1][2] + "/${filename}";
33
+ acl = data.policy_document.conditions[2].acl;
34
+ successAction = data.policy_document.conditions[3].success_action_status;
35
+ base64Policy = data.policy_encoded;
36
+ signature = data.signature;
37
+ s3Key = options.s3Key;
38
+ uploadBucket = bucket;
39
+ $form = this.find('form');
40
+ $form.find('input[name=key]').val(key);
41
+ $form.find('input[name=AWSAccessKeyId]').val(s3Key);
42
+ $form.find('input[name=acl]').val(acl);
43
+ $form.find('input[name=success_action_status]').val(successAction);
44
+ $form.find('input[name=policy]').val(base64Policy);
45
+ $form.find('input[name=signature]').val(signature);
46
+ return $form.get(0).setAttribute('action', "https://" + uploadBucket + ".s3.amazonaws.com");
47
+ },
48
+ attachFileUploadUI: function(data, options) {
49
+ var $form, bucket, key, metadata;
50
+ $form = this.find('form');
51
+ bucket = data.policy_document.conditions[0].bucket;
52
+ key = "" + data.policy_document.conditions[1][2] + "/${filename}";
53
+ this.seedForm(data, options);
54
+ metadata = {
55
+ _type: options._type,
56
+ id: options.id
57
+ };
58
+ return $form.fileupload({
59
+ type: 'POST',
60
+ dataType: 'xml',
61
+ done: (function(_this) {
62
+ return function(e, data) {
63
+ var fileName;
64
+ fileName = data.files[0].name;
65
+ key = key.replace('${filename}', fileName);
66
+ return $.ajax({
67
+ type: 'POST',
68
+ dataType: 'json',
69
+ url: "" + options.geminiApp + "/entries.json",
70
+ data: {
71
+ entry: {
72
+ source_key: key,
73
+ source_bucket: bucket,
74
+ template_key: options.templateKey,
75
+ metadata: metadata
76
+ }
77
+ },
78
+ headers: {
79
+ 'Authorization': "Basic " + options.credentials
80
+ },
81
+ success: function(resp) {
82
+ if (options.successCb !== null) {
83
+ return options.successCb(resp);
84
+ }
85
+ }
86
+ });
87
+ };
88
+ })(this),
89
+ add: (function(_this) {
90
+ return function(e, data) {
91
+ var fileName, fileType;
92
+ fileName = data.files[0].name;
93
+ fileType = data.files[0].type;
94
+ $(_this).find("form input[name='Content-Type']").val(fileType);
95
+ return data.submit();
96
+ };
97
+ })(this)
98
+ });
99
+ }
100
+ });
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gemini_upload-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matthew Zikherman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-07-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: railties
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '4.0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ description: Packages up gemini upload widget
63
+ email:
64
+ - matt@bestvendor.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - lib/gemini_upload/rails/version.rb
70
+ - lib/gemini_upload/rails.rb
71
+ - vendor/assets/jvaascripts/gemini_upload.js
72
+ - LICENSE.txt
73
+ - README.md
74
+ homepage: ''
75
+ licenses:
76
+ - MIT
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 1.8.25
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Gemini upload widget for Rails
99
+ test_files: []
100
+ has_rdoc: