carrierwave-ms-azure 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 557b5cb46db8f69c7545dceae04704ecf9b86892
4
+ data.tar.gz: 422ce4ff114fc9895c21e7d54c904d5c62e1eaec
5
+ SHA512:
6
+ metadata.gz: f1a42b9d3cf0783f508a1e981c8342ac304424c5eee0fba485be32fd7f608c0cdaebb1b07107d82c7f3babec7849dc21687e7bdad17135d06ced5e9a6b97a3a6
7
+ data.tar.gz: a26c77b059a9dfbef34b8ae3b19e5e0e48af845e7ceb4a855c98217907d46caac34a5efb270baab0d89b95246dfb23c934d71044d137dde2265aea67952f912d
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ spec/environment.rb
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 heathrow, inc.
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,53 @@
1
+ # Carrierwave::Azure
2
+
3
+ Windows Azure blob storage support for [CarrierWave](https://github.com/carrierwaveuploader/carrierwave)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'carrierwave-azure'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ ## Usage
16
+
17
+ First configure CarrierWave with your Azure storage credentials
18
+
19
+ see [Azure/azure-sdk-for-ruby](https://github.com/Azure/azure-sdk-for-ruby#via-code)
20
+
21
+ ```ruby
22
+ CarrierWave.configure do |config|
23
+ config.azure_storage_account_name = 'YOUR STORAGE ACCOUNT NAME'
24
+ config.azure_storage_access_key = 'YOUR STORAGE ACCESS KEY'
25
+ config.azure_storage_blob_host = 'YOUR STORAGE BLOB HOST' # optional
26
+ config.azure_container = 'YOUR CONTAINER NAME'
27
+ config.asset_host = 'YOUR CDN HOST' # optional
28
+ end
29
+ ```
30
+
31
+ And then in your uploader, set the storage to `:azure`
32
+
33
+ ```ruby
34
+ class ExampleUploader < CarrierWave::Uploader::Base
35
+ storage :azure
36
+ end
37
+ ```
38
+
39
+ ## Contributing
40
+
41
+ In order to run the integration specs you will need to configure some environment variables.
42
+ A sample file is provided as `spec/environment.rb.sample`.
43
+ Copy it over and plug in the appropriate values.
44
+
45
+ ```bash
46
+ cp spec/environment.rb.sample spec/environment.rb
47
+ ```
48
+
49
+ 1. Fork it
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,24 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'carrierwave/azure/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'carrierwave-azure'
7
+ gem.version = Carrierwave::Azure::VERSION
8
+ gem.authors = ['Yusuke Shibahara']
9
+ gem.email = ['yusuke.shibahara@heathrow.co.jp']
10
+ gem.summary = %q{Windows Azure blob storage support for CarrierWave}
11
+ gem.description = %q{Allows file upload to Azure with the officail sdk}
12
+ gem.homepage = 'https://github.com/unosk/carrierwave-azure'
13
+ gem.license = 'MIT'
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.test_files = gem.files.grep(%r{^rspec})
17
+ gem.require_paths = ['lib']
18
+
19
+ gem.add_dependency 'carrierwave'
20
+ gem.add_dependency 'azure'
21
+
22
+ gem.add_development_dependency 'rake'
23
+ gem.add_development_dependency 'rspec', '~> 3'
24
+ end
@@ -0,0 +1,24 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'carrierwave/azure/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'carrierwave-ms-azure'
7
+ gem.version = Carrierwave::Azure::VERSION
8
+ gem.authors = ['Yusuke Shibahara']
9
+ gem.email = ['yusuke.shibahara@heathrow.co.jp']
10
+ gem.summary = %q{Windows Azure blob storage support for CarrierWave}
11
+ gem.description = %q{Allows file upload to Azure with the officail sdk}
12
+ gem.homepage = 'https://github.com/unosk/carrierwave-azure'
13
+ gem.license = 'MIT'
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.test_files = gem.files.grep(%r{^rspec})
17
+ gem.require_paths = ['lib']
18
+
19
+ gem.add_dependency 'carrierwave'
20
+ gem.add_dependency 'azure'
21
+
22
+ gem.add_development_dependency 'rake'
23
+ gem.add_development_dependency 'rspec', '~> 3'
24
+ end
@@ -0,0 +1,14 @@
1
+ require 'carrierwave'
2
+ require 'carrierwave/azure/version'
3
+ require 'carrierwave/storage/azure'
4
+
5
+ class CarrierWave::Uploader::Base
6
+ add_config :azure_storage_account_name
7
+ add_config :azure_storage_access_key
8
+ add_config :azure_storage_blob_host
9
+ add_config :azure_container
10
+
11
+ configure do |config|
12
+ config.storage_engines[:azure] = 'CarrierWave::Storage::Azure'
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module Carrierwave
2
+ module Azure
3
+ VERSION = '0.0.4'
4
+ end
5
+ end
@@ -0,0 +1,120 @@
1
+ require 'azure'
2
+
3
+ module CarrierWave
4
+ module Storage
5
+ class Azure < Abstract
6
+ def store!(file)
7
+ azure_file = CarrierWave::Storage::Azure::File.new(uploader, connection, uploader.store_path)
8
+ azure_file.store!(file)
9
+ azure_file
10
+ end
11
+
12
+ def retrieve!(identifer)
13
+ CarrierWave::Storage::Azure::File.new(uploader, connection, uploader.store_path(identifer))
14
+ end
15
+
16
+ def connection
17
+ @connection ||= begin
18
+ %i(storage_account_name storage_access_key storage_blob_host).each do |key|
19
+ ::Azure.config.send("#{key}=", uploader.send("azure_#{key}"))
20
+ end
21
+ ::Azure::Blob::BlobService.new
22
+ end
23
+ end
24
+
25
+ class File
26
+ attr_reader :path
27
+
28
+ def initialize(uploader, connection, path)
29
+ @uploader = uploader
30
+ @connection = connection
31
+ @path = path
32
+ end
33
+
34
+ def store!(file)
35
+ @content_type = file.content_type
36
+ file_to_send = ::File.open(file.file, 'rb')
37
+ blocks = []
38
+ i = 0
39
+
40
+ until file_to_send.eof?
41
+ i += 1
42
+ @content = file_to_send.read 4194304 # Send 4MB chunk
43
+ @connection.create_blob_block @uploader.azure_container, @path, i.to_s, content
44
+ blocks << i.to_s
45
+ end
46
+
47
+ @connection.commit_blob_blocks @uploader.azure_container, @path, blocks
48
+
49
+ true
50
+ end
51
+
52
+ def url(options = {})
53
+ path = ::File.join @uploader.azure_container, @path
54
+ if @uploader.asset_host
55
+ "#{@uploader.asset_host}/#{path}"
56
+ else
57
+ @connection.generate_uri(path).to_s
58
+ end
59
+ end
60
+
61
+ def read
62
+ content
63
+ end
64
+
65
+ def content_type
66
+ @content_type = blob.properties[:content_type] if @content_type.nil? && !blob.nil?
67
+ @content_type
68
+ end
69
+
70
+ def content_type=(new_content_type)
71
+ @content_type = new_content_type
72
+ end
73
+
74
+ def exist?
75
+ blob.nil?
76
+ end
77
+
78
+ def size
79
+ blob.properties[:content_length] unless blob.nil?
80
+ end
81
+
82
+ def filename
83
+ URI.decode(url).gsub(/.*\/(.*?$)/, '\1')
84
+ end
85
+
86
+ def extension
87
+ @path.split('.').last
88
+ end
89
+
90
+ def delete
91
+ begin
92
+ @connection.delete_blob @uploader.azure_container, @path
93
+ true
94
+ rescue ::Azure::Core::Http::HTTPError
95
+ false
96
+ end
97
+ end
98
+
99
+ private
100
+
101
+ def blob
102
+ load_content if @blob.nil?
103
+ @blob
104
+ end
105
+
106
+ def content
107
+ load_content if @content.nil?
108
+ @content
109
+ end
110
+
111
+ def load_content
112
+ @blob, @content = begin
113
+ @connection.get_blob @uploader.azure_container, @path
114
+ rescue ::Azure::Core::Http::HTTPError
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe CarrierWave::Uploader::Base do
4
+ it 'should define azure as a storage engine' do
5
+ expect(described_class.storage_engines[:azure]).to eq 'CarrierWave::Storage::Azure'
6
+ end
7
+
8
+ it 'should define azure options' do
9
+ is_expected.to respond_to(:azure_storage_account_name)
10
+ is_expected.to respond_to(:azure_storage_access_key)
11
+ is_expected.to respond_to(:azure_storage_blob_host)
12
+ is_expected.to respond_to(:azure_container)
13
+ end
14
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe CarrierWave::Storage::Azure::File do
4
+ class TestUploader < CarrierWave::Uploader::Base
5
+ storage :azure
6
+ end
7
+
8
+ let(:uploader) { TestUploader.new }
9
+ let(:storage) { CarrierWave::Storage::Azure.new uploader }
10
+
11
+ describe '#url' do
12
+ before do
13
+ allow(uploader).to receive(:azure_container).and_return('test')
14
+ end
15
+
16
+ subject { CarrierWave::Storage::Azure::File.new(uploader, storage.connection, 'dummy.txt').url }
17
+
18
+ context 'with storage_blob_host' do
19
+ before do
20
+ allow(uploader).to receive(:azure_storage_blob_host).and_return('http://example.com')
21
+ end
22
+
23
+ it 'should return on asset_host' do
24
+ expect(subject).to eq 'http://example.com/test/dummy.txt'
25
+ end
26
+ end
27
+
28
+ context 'with asset_host' do
29
+ before do
30
+ allow(uploader).to receive(:asset_host).and_return('http://example.com')
31
+ end
32
+
33
+ it 'should return on asset_host' do
34
+ expect(subject).to eq 'http://example.com/test/dummy.txt'
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ CarrierWave.configure do |config|
2
+ config.azure_storage_account_name = 'YOUR STORAGE ACCOUNT NAME'
3
+ config.azure_storage_access_key = 'YOUR STORAGE ACCESS KEY'
4
+ config.azure_container = 'YOUR CONTAINER NAME'
5
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+ require 'carrierwave'
4
+ require 'carrierwave-ms-azure'
5
+ require 'environment'
6
+
7
+ RSpec.configure do |config|
8
+ config.order = :random
9
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carrierwave-ms-azure
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Yusuke Shibahara
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: carrierwave
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: azure
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3'
69
+ description: Allows file upload to Azure with the officail sdk
70
+ email:
71
+ - yusuke.shibahara@heathrow.co.jp
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - carrierwave-azure.gemspec
83
+ - carrierwave-ms-azure.gemspec
84
+ - lib/carrierwave-ms-azure.rb
85
+ - lib/carrierwave/azure/version.rb
86
+ - lib/carrierwave/storage/azure.rb
87
+ - spec/carrierwave-ms-azure_spec.rb
88
+ - spec/carrierwave/storage/azure_file_spec.rb
89
+ - spec/environment.rb.sample
90
+ - spec/spec_helper.rb
91
+ homepage: https://github.com/unosk/carrierwave-azure
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.2.2
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Windows Azure blob storage support for CarrierWave
115
+ test_files: []