directwave 0.0.1 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,12 @@
1
+ ## v0.0.3
2
+
3
+ * moved out from deprecated InstanceMethods idiom
4
+
5
+ ## v0.0.2
6
+
7
+ * adding retrieve method to cache version file
8
+ * adding cache_dir to configuration
9
+
1
10
  ## v0.0.1
2
11
 
3
12
  * initial release
data/README.md CHANGED
@@ -6,7 +6,7 @@ such as zencoder.com or pandastream.com.
6
6
 
7
7
  It works well with Rack based web applications, such as Ruby on Rails.
8
8
 
9
- Inspired by [CarrierWave](http://github.com/jnicklas/DirectWave) and used in [radiant.fm](http://radiant.fm)
9
+ Inspired by [CarrierWave](https://github.com/jnicklas/carrierwave) and used in [radiant.fm](http://radiant.fm).
10
10
 
11
11
  ## Information
12
12
 
@@ -15,7 +15,7 @@ Inspired by [CarrierWave](http://github.com/jnicklas/DirectWave) and used in [ra
15
15
 
16
16
  ## Getting Help
17
17
 
18
- * Please report bugs on the [issue tracker]https://github.com/radiantfm/directwave/issues).
18
+ * Please report bugs on the [issue tracker](https://github.com/radiantfm/directwave/issues).
19
19
 
20
20
  ## Installation
21
21
 
@@ -26,16 +26,16 @@ Install the latest stable release:
26
26
  In Rails, add it to your Gemfile:
27
27
 
28
28
  ``` ruby
29
- gem 'directwave'
29
+ gem "directwave"
30
30
  ```
31
31
 
32
32
  ## Getting Started
33
33
 
34
- Start off by generating an uploader:
34
+ Start off generating an uploader:
35
35
 
36
36
  rails generate directwave Audio
37
37
 
38
- this should give you a file in:
38
+ this should give you the following file:
39
39
 
40
40
  app/uploaders/audio_uploader.rb
41
41
 
@@ -47,9 +47,9 @@ class AudioUploader < DirectWave::Uploader::Base
47
47
  end
48
48
  ```
49
49
 
50
- Most of the time you are going to want to use DirectWave together with an ORM.
51
- It is quite simple to mount uploaders on columns in your model, so you can
52
- simply assign files and get going:
50
+ Time after time you can use DirectWave together with an ORM.
51
+ It is quite simple to mount uploaders on columns in your model,
52
+ so in fact you can assign files and get going:
53
53
 
54
54
  ## ActiveRecord
55
55
 
@@ -67,8 +67,8 @@ class Track < ActiveRecord::Base
67
67
  end
68
68
  ```
69
69
 
70
- Now you can cache files by assigning them to the attribute, they will
71
- automatically be stored when the record is saved.
70
+ Now you can cache files by assigning them to the attribute,
71
+ they will be stored automatically after the record save.
72
72
 
73
73
  ``` ruby
74
74
  u = Track.new(:audio_from_key => params[:key])
@@ -79,7 +79,7 @@ u.audio.url # => '/url/to/file.png'
79
79
  ## Rails
80
80
 
81
81
  You can use different flash uploaders for multiple direct upload,
82
- such as [Uploadify](http://sd.r). For example in Rails with CoffeeScript and Nokogiri
82
+ such as [Uploadify](http://www.uploadify.com). For example in Rails with CoffeeScript and Nokogiri
83
83
  generate uploader controller at first:
84
84
 
85
85
  rails g controller Uploads new create
@@ -103,7 +103,7 @@ class UploadsController < ApplicationController
103
103
  end
104
104
  ```
105
105
 
106
- when in `assets/javascript/uploads.js.coffe` insert:
106
+ then in `assets/javascript/uploads.js.coffe` insert:
107
107
 
108
108
  ``` html
109
109
  $(document).ready ->
@@ -149,8 +149,8 @@ in `views/uploads/new.html.erb`:
149
149
 
150
150
  ## Changing the directories
151
151
 
152
- In order to change where uploaded files are stored, just override the `store_dir`
153
- method:
152
+ In order to change the location where uploaded files are stored,
153
+ just override the `store_dir` method:
154
154
 
155
155
  ``` ruby
156
156
  class MyUploader < DirectWave::Uploader::Base
@@ -160,12 +160,11 @@ class MyUploader < DirectWave::Uploader::Base
160
160
  end
161
161
  ```
162
162
 
163
- If you want change where files will be uploaded, override the `upload_dir`
164
- method:
163
+ If you want to change where files will be uploaded, override the `upload_dir` method:
165
164
 
166
165
  ``` ruby
167
166
  class MyUploader < DirectWave::Uploader::Base
168
- def store_dir
167
+ def upload_dir
169
168
  '/my/upload/directory/tmp'
170
169
  end
171
170
  end
@@ -197,9 +196,7 @@ class Audio < DirectWave::Uploader::Base
197
196
  label: "aac",
198
197
  url: "s3://#{@uploader.s3_bucket}.s3.amazonaws.com/#{@uploader.versions[:aac].key}",
199
198
  format: "aac",
200
- notifications: [
201
- { url: "http://zencoderfetcher/", format: "json" }
202
- ]
199
+ notifications: [{ url: "http://zencoderfetcher/", format: "json" }]
203
200
  } # aac
204
201
  ] # outputs
205
202
  }
@@ -210,8 +207,8 @@ class Audio < DirectWave::Uploader::Base
210
207
  end
211
208
  ```
212
209
 
213
- When this uploader is used, a version called aac is then created, which is processed with `process`.
214
- The uploader could be used like this:
210
+ When the uploader is used, a version named aac will be created
211
+ which is processed with `process` method. The uploader could be used like this:
215
212
 
216
213
  ``` ruby
217
214
  uploader.url # => '/url/to/original/file.png'
@@ -220,7 +217,7 @@ uploader.aac.url # => '/url/to/aac/file.png'
220
217
  uploader.url(:aac) # => '/url/to/aac/file.png'
221
218
  ```
222
219
 
223
- You can also override `global_process` method wich called after
220
+ You can also override `global_process` method which called after
224
221
  all process within versions:
225
222
 
226
223
  ``` ruby
@@ -239,17 +236,13 @@ class Audio < DirectWave::Uploader::Base
239
236
  label: "aac",
240
237
  url: "s3://#{s3_bucket}.s3.amazonaws.com/#{versions[:aac].key}",
241
238
  format: "aac",
242
- notifications: [
243
- { url: "http://zencoderfetcher/", format: :json }
244
- ]
239
+ notifications: [{ url: "http://zencoderfetcher/", format: :json }]
245
240
  }, # aac
246
241
  {
247
242
  label: "wav",
248
243
  url: "s3://#{s3_bucket}.s3.amazonaws.com/#{versions[:wav].key}",
249
244
  format: "wav",
250
- notifications: [
251
- { url: "http://zencoderfetcher/", format: :json }
252
- ]
245
+ notifications: [{ url: "http://zencoderfetcher/", format: :json }]
253
246
  } # wav
254
247
 
255
248
  ] # outputs
@@ -4,52 +4,50 @@ module DirectWave
4
4
  module Accreditation
5
5
  extend ActiveSupport::Concern
6
6
 
7
- module InstanceMethods
8
- ##
9
- # === Returns
10
- #
11
- # [String] Amazon S3 acl
12
- #
13
- def s3_acl
14
- @s3_acl ||= s3_access_policy.to_s.gsub("_", "-")
15
- end
7
+ ##
8
+ # === Returns
9
+ #
10
+ # [String] Amazon S3 acl
11
+ #
12
+ def s3_acl
13
+ @s3_acl ||= s3_access_policy.to_s.gsub("_", "-")
14
+ end
16
15
 
17
- ##
18
- # === Returns
19
- #
20
- # [Boolean] Amazon S3 policy
21
- #
22
- def s3_policy
23
- @s3_policy ||= Base64.encode64(
24
- {
25
- "expiration" => expiration_date,
26
- "conditions" => [
27
- {"bucket" => s3_bucket},
28
- ["starts-with", "$key", upload_dir],
29
- {"success_action_status" => "201"},
30
- ["starts-with", "$filename", ""],
31
- ["starts-with", "$folder", ""],
32
- {"acl" => s3_acl},
33
- ["content-length-range", 1, max_file_size]
34
- ]
35
- }.to_json
36
- ).gsub("\n","")
37
- end
38
-
39
- ##
40
- # === Returns
41
- #
42
- # [Boolean] Amazon S3 signature
43
- #
44
- def s3_signature
45
- @s3_signature ||= Base64.encode64(
46
- OpenSSL::HMAC.digest(
47
- OpenSSL::Digest::Digest.new("sha1"),
48
- s3_secret_access_key, s3_policy
49
- )
50
- ).gsub("\n","")
51
- end
52
- end # InstanceMethods
16
+ ##
17
+ # === Returns
18
+ #
19
+ # [Boolean] Amazon S3 policy
20
+ #
21
+ def s3_policy
22
+ @s3_policy ||= Base64.encode64(
23
+ {
24
+ "expiration" => expiration_date,
25
+ "conditions" => [
26
+ {"bucket" => s3_bucket},
27
+ ["starts-with", "$key", upload_dir],
28
+ {"acl" => s3_acl},
29
+ {"success_action_status" => "201"},
30
+ ["content-length-range", 0, max_file_size],
31
+ ["starts-with", "$Filename", ""],
32
+ ['starts-with', '#{content_type}', '']
33
+ ]
34
+ }.to_json
35
+ ).gsub("\n","")
36
+ end
37
+
38
+ ##
39
+ # === Returns
40
+ #
41
+ # [Boolean] Amazon S3 signature
42
+ #
43
+ def s3_signature
44
+ @s3_signature ||= Base64.encode64(
45
+ OpenSSL::HMAC.digest(
46
+ OpenSSL::Digest::Digest.new("sha1"),
47
+ s3_secret_access_key, s3_policy
48
+ )
49
+ ).gsub("\n","")
50
+ end
53
51
 
54
52
  private
55
53
 
@@ -17,6 +17,7 @@ module DirectWave
17
17
 
18
18
  add_config :store_dir
19
19
  add_config :upload_dir
20
+ add_config :cache_dir
20
21
 
21
22
  reset_config
22
23
  end
@@ -57,8 +58,9 @@ module DirectWave
57
58
  config.max_file_size = 300.megabytes
58
59
  config.expiration_date = 6.hours.from_now.utc.iso8601
59
60
 
60
- config.store_dir = "uploads"
61
+ config.store_dir = "uploads"
61
62
  config.upload_dir = "uploads/tmp"
63
+ config.cache_dir = 'uploads/cache'
62
64
  end
63
65
  end
64
66
  end # ClassMethods
@@ -4,47 +4,44 @@ module DirectWave
4
4
  module Paths
5
5
  extend ActiveSupport::Concern
6
6
 
7
- module InstanceMethods
8
- def url(version=:original)
9
- versions[version.to_sym].url || default_url
10
- end
11
-
12
- def key(version=:original)
13
- versions[version.to_sym].key
14
- end
15
-
16
- def default_url
17
- puts "default_url"
18
- end
7
+ def url(version=:original)
8
+ versions[version.to_sym].url || default_url
9
+ end
10
+
11
+ def key(version=:original)
12
+ versions[version.to_sym].key
13
+ end
14
+
15
+ def default_url
16
+ puts "default_url"
17
+ end
18
+
19
+ def filename(part=nil)
20
+ return original_filename unless has_store_key?
19
21
 
20
- def filename(part=nil)
21
- return original_filename unless has_store_key?
22
-
23
- key_path = store_key.split("/")
24
- filename_parts = []
25
- filename = filename_parts.unshift(key_path.pop)
26
- unique_key = key_path.pop
27
- filename_parts.unshift(unique_key) if unique_key
28
- filename_parts.join("/")
29
- end
30
-
31
- def original_filename
32
- model[mounted_as.to_s] if model.respond_to?(mounted_as)
33
- end
22
+ key_path = store_key.split("/")
23
+ filename_parts = []
24
+ filename = filename_parts.unshift(key_path.pop)
25
+ unique_key = key_path.pop
26
+ filename_parts.unshift(unique_key) if unique_key
27
+ filename_parts.join("/")
28
+ end
34
29
 
35
- def store_key=(string)
36
- @store_key = string
37
- end
38
-
39
- def store_key
40
- @store_key ||= "#{upload_dir}/#{guid}/${filename}"
41
- end
30
+ def original_filename
31
+ model[mounted_as.to_s] if model.respond_to?(mounted_as)
32
+ end
33
+
34
+ def store_key=(string)
35
+ @store_key = string
36
+ end
42
37
 
43
- def has_store_key?
44
- @store_key.present? && !(@store_key =~ /#{Regexp.escape("${filename}")}\z/)
45
- end
46
- end # InstanceMethods
47
-
38
+ def store_key
39
+ @store_key ||= "#{upload_dir}/#{guid}/${filename}"
40
+ end
41
+
42
+ def has_store_key?
43
+ @store_key.present? && !(@store_key =~ /#{Regexp.escape("${filename}")}\z/)
44
+ end
48
45
  end # Paths
49
46
  end # Uploader
50
47
 
@@ -35,12 +35,27 @@ module DirectWave
35
35
  @filename = nil
36
36
  @url = nil
37
37
  @key = nil
38
+ @date = nil
38
39
  end
39
40
 
40
41
  def delete
41
42
  file.delete if file.exists?
42
43
  end
43
44
 
45
+ def retrieve
46
+ @data ||= file.read
47
+ begin
48
+ temp_file = Tempfile.new([extract(:basename), extract(:extname)], @uploader.cache_dir)
49
+ temp_file.binmode
50
+ temp_file.write(@data)
51
+ temp_file.flush
52
+ yield(temp_file)
53
+ ensure
54
+ # temp_file.close
55
+ #temp_file.unlink
56
+ end
57
+ end
58
+
44
59
  private
45
60
 
46
61
  def extract(part)
@@ -1,3 +1,3 @@
1
1
  module Directwave
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: directwave
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-16 00:00:00.000000000Z
12
+ date: 2012-04-18 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70271860063960 !ruby/object:Gem::Requirement
16
+ requirement: &70104029175840 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70271860063960
24
+ version_requirements: *70104029175840
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: uuid
27
- requirement: &70271860063360 !ruby/object:Gem::Requirement
27
+ requirement: &70104029172540 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70271860063360
35
+ version_requirements: *70104029172540
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: aws-sdk
38
- requirement: &70271860062320 !ruby/object:Gem::Requirement
38
+ requirement: &70104029170460 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70271860062320
46
+ version_requirements: *70104029170460
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rails
49
- requirement: &70271860060580 !ruby/object:Gem::Requirement
49
+ requirement: &70104029169380 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '3.1'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70271860060580
57
+ version_requirements: *70104029169380
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &70271860056780 !ruby/object:Gem::Requirement
60
+ requirement: &70104029168580 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70271860056780
68
+ version_requirements: *70104029168580
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
- requirement: &70271858520620 !ruby/object:Gem::Requirement
71
+ requirement: &70104029167540 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70271858520620
79
+ version_requirements: *70104029167540
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: sqlite3
82
- requirement: &70271858518980 !ruby/object:Gem::Requirement
82
+ requirement: &70104029166660 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70271858518980
90
+ version_requirements: *70104029166660
91
91
  description: A simple way to direct upload big files to Amazon S3 storage from Ruby
92
92
  applications and process it with cloud encoding service.
93
93
  email:
@@ -157,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
157
157
  version: '0'
158
158
  segments:
159
159
  - 0
160
- hash: 2087257516633304039
160
+ hash: 258924082708884621
161
161
  required_rubygems_version: !ruby/object:Gem::Requirement
162
162
  none: false
163
163
  requirements:
@@ -166,10 +166,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
166
  version: '0'
167
167
  segments:
168
168
  - 0
169
- hash: 2087257516633304039
169
+ hash: 258924082708884621
170
170
  requirements: []
171
171
  rubyforge_project: directwave
172
- rubygems_version: 1.8.10
172
+ rubygems_version: 1.8.15
173
173
  signing_key:
174
174
  specification_version: 3
175
175
  summary: Ruby direct uploader to Amazon S3