cw-az-custom 0.0.5

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 07b42b996982a78fdab0d47a63fe5f37405f946b
4
+ data.tar.gz: 3266ea7f5557b3679af66cf66d37441a24eb8c6b
5
+ SHA512:
6
+ metadata.gz: f63cfb69df4cac0a7cbfbe6023870678e2e77333528f3b8005222cabd63cb84c5efa2bfd1dce18b5e47c7dd4cc49244dceb6ec9534f06238ccdce6a0c6086d76
7
+ data.tar.gz: 32a813252c58aff5f640025f3bcfe43f33a5f9993edea22252f44b4d9685ad5ed47dde6b72cc5405c0b2d9094aa94278b70db4634cfe57a17e7f4383e5ab4fca
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ pkg
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
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 'cw-az-custom'
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 = 'cw-az-custom'
7
+ gem.version = Carrierwave::Azure::VERSION
8
+ gem.authors = ['Heerae']
9
+ gem.email = ['april174@gmail.com']
10
+ gem.summary = %q{Windows Azure blob storage support for CarrierWave(This gem is copy of carrierwave-azure, custom bug fix version)}
11
+ gem.description = %q{Allows file upload to Azure with the officail sdk}
12
+ gem.homepage = 'https://github.com/Heerae89/cw-az-custom'
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,5 @@
1
+ module Carrierwave
2
+ module Azure
3
+ VERSION = '0.0.5'
4
+ end
5
+ end
@@ -0,0 +1,122 @@
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
+ block_id = 0
38
+ blocks = []
39
+
40
+ until file_to_send.eof?
41
+ block_id += 1
42
+
43
+ @content = file_to_send.read 4194304 # Send 4MB chunk
44
+ @connection.create_blob_block @uploader.azure_container, @path, block_id.to_s, @content
45
+ blocks << block_id.to_s
46
+ end
47
+
48
+ # Commit block blobs
49
+ @connection.commit_blob_blocks @uploader.azure_container, @path, blocks, :blob_content_type => @content_type
50
+
51
+ true
52
+ end
53
+
54
+ def url(options = {})
55
+ path = ::File.join @uploader.azure_container, @path
56
+ if @uploader.asset_host
57
+ "#{@uploader.asset_host}/#{path}"
58
+ else
59
+ @connection.generate_uri(path).to_s
60
+ end
61
+ end
62
+
63
+ def read
64
+ content
65
+ end
66
+
67
+ def content_type
68
+ @content_type = blob.properties[:content_type] if @content_type.nil? && !blob.nil?
69
+ @content_type
70
+ end
71
+
72
+ def content_type=(new_content_type)
73
+ @content_type = new_content_type
74
+ end
75
+
76
+ def exist?
77
+ blob.nil?
78
+ end
79
+
80
+ def size
81
+ blob.properties[:content_length] unless blob.nil?
82
+ end
83
+
84
+ def filename
85
+ URI.decode(url).gsub(/.*\/(.*?$)/, '\1')
86
+ end
87
+
88
+ def extension
89
+ @path.split('.').last
90
+ end
91
+
92
+ def delete
93
+ begin
94
+ @connection.delete_blob @uploader.azure_container, @path
95
+ true
96
+ rescue ::Azure::Core::Http::HTTPError
97
+ false
98
+ end
99
+ end
100
+
101
+ private
102
+
103
+ def blob
104
+ load_content if @blob.nil?
105
+ @blob
106
+ end
107
+
108
+ def content
109
+ load_content if @content.nil?
110
+ @content
111
+ end
112
+
113
+ def load_content
114
+ @blob, @content = begin
115
+ @connection.get_blob @uploader.azure_container, @path
116
+ rescue ::Azure::Core::Http::HTTPError
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
122
+ 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,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,78 @@
1
+ require 'spec_helper'
2
+ require 'tempfile'
3
+ require 'open-uri'
4
+
5
+ describe CarrierWave::Storage::Azure do
6
+ class TestUploader < CarrierWave::Uploader::Base
7
+ storage :azure
8
+ end
9
+
10
+ let(:uploader) { TestUploader.new }
11
+ let(:storage) { CarrierWave::Storage::Azure.new uploader }
12
+
13
+ shared_examples_for 'an expected return value' do
14
+ let(:stored_file) do
15
+ allow(uploader).to receive(:store_path).and_return('test/dummy.png')
16
+ tempfile = Tempfile.new 'test.jpg'
17
+ open(tempfile.path, 'w') do |f|
18
+ f.print '1234567890'
19
+ end
20
+ storage.store! CarrierWave::SanitizedFile.new(
21
+ tempfile: tempfile,
22
+ filename: 'test.jpg',
23
+ content_type: 'image/png'
24
+ )
25
+ end
26
+
27
+ let(:retrieved_file) do
28
+ storage.retrieve! stored_file.path
29
+ end
30
+
31
+ it 'should have a path' do
32
+ expect(subject.path).to eq 'test/dummy.png'
33
+ end
34
+
35
+ it 'should have a url' do
36
+ url = subject.url
37
+ expect(url).to match /^https?:\/\//
38
+ expect(open(url).read).to eq '1234567890'
39
+ end
40
+
41
+ it 'should have a content' do
42
+ expect(subject.read).to eq '1234567890'
43
+ end
44
+
45
+ it 'should have a content_type' do
46
+ expect(subject.content_type).to eq 'image/png'
47
+ end
48
+
49
+ it 'should have a size' do
50
+ expect(subject.size).to eq 10
51
+ end
52
+
53
+ it 'should have a filename' do
54
+ expect(subject.filename).to eq 'dummy.png'
55
+ end
56
+
57
+ it 'should have an extension' do
58
+ expect(subject.extension).to eq 'png'
59
+ end
60
+
61
+ it 'should be deletable' do
62
+ subject.delete
63
+ expect{open subject.url}.to raise_error OpenURI::HTTPError
64
+ end
65
+ end
66
+
67
+ describe '#store!' do
68
+ it_should_behave_like 'an expected return value' do
69
+ subject { stored_file }
70
+ end
71
+ end
72
+
73
+ describe '#retrieve' do
74
+ it_should_behave_like 'an expected return value' do
75
+ subject { retrieved_file }
76
+ end
77
+ end
78
+ 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,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 'cw-az-custom'
5
+ require 'environment'
6
+
7
+ RSpec.configure do |config|
8
+ config.order = :random
9
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cw-az-custom
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Heerae
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-14 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
+ - april174@gmail.com
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
+ - cw-az-custom.gemspec
83
+ - lib/carrierwave/azure/version.rb
84
+ - lib/carrierwave/storage/azure.rb
85
+ - lib/cw-az-custom.rb
86
+ - spec/carrierwave/storage/azure_file_spec.rb
87
+ - spec/carrierwave/storage/azure_spec.rb
88
+ - spec/cw-az-custom_spec.rb
89
+ - spec/environment.rb.sample
90
+ - spec/spec_helper.rb
91
+ homepage: https://github.com/Heerae89/cw-az-custom
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.4.5.1
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Windows Azure blob storage support for CarrierWave(This gem is copy of carrierwave-azure,
115
+ custom bug fix version)
116
+ test_files: []