carrierwave-box 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c68f877b0544dfa2182eafb75e03da479bdfe6f8
4
+ data.tar.gz: 2b7c4b88e7fadf057067db7532bfa828e2207b1a
5
+ SHA512:
6
+ metadata.gz: 5d68a1d314aa58966e744db5fee9fbd96ae3d0270d32becb17b281216219abb0886ded96146609c37a1219e403e60540f36a07a44e54226eef1397f93b01fb4c
7
+ data.tar.gz: 31a67219276077922b0e1d718f6eb9789b881e098df1a12e3e9448e1401859502c7299070c45ac9239fabecfb435250ebe7b5f5df653251ae88484a31d49837e
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in carrierwave-box.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 thiensubs - Vo Tien An
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 thiensubs - Vo Tien An
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,92 @@
1
+ # Carrierwave::Box
2
+
3
+ Now you can use box.net/box.com with Carrierwave.
4
+
5
+ Easy to config, easy use, and helpful.
6
+
7
+ You can use box.net/box.com to store image (i was check, it working with rails to show image in view).
8
+
9
+ Gem will auto generater access token, don't worry about access token. :D
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'carrierwave-box'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install carrierwave-box
26
+ ##Note:
27
+
28
+ In your developer web view, you need to set return uri to: http://localhost
29
+
30
+ ## Usage
31
+
32
+ So simple:
33
+
34
+ - Config for carrierwave:
35
+
36
+ ```ruby
37
+
38
+ CarrierWave.configure do |config|
39
+ config.box_client_id = 'your_client_id'
40
+ config.box_client_secret = 'your_secret_id'
41
+ config.box_email = 'your_box_email'
42
+ config.box_password = 'your_box_password'
43
+ config.box_access_type = "box"
44
+ config.cache_dir = "#{Rails.root}/tmp/uploads"
45
+ config.enable_processing = true
46
+ end
47
+ ```
48
+
49
+ Special of this gem:
50
+
51
+ - Gem will auto generater access token.
52
+
53
+ - No need time to get access token.
54
+
55
+ - Why box.net/box.com is so difficult to do gem: Access token is only valid in 60 minutes. :(
56
+
57
+ - With gem you can easy to use, but notice time to upload will be longer. (it depend your internet and your vps/computer).
58
+
59
+ - How to integate:
60
+
61
+ ```ruby
62
+ class FileUpload < ActiveRecord::Base
63
+ # Upload picture
64
+ mount_uploader :file_name, AbcUploader
65
+ end
66
+ ```
67
+
68
+ ```ruby
69
+ class AbcUploader < CarrierWave::Uploader::Base
70
+ # Include RMagick or MiniMagick support:
71
+ # include CarrierWave::RMagick
72
+ # include CarrierWave::MiniMagick
73
+ # Choose what kind of storage to use for this uploader:
74
+ storage :box
75
+ end
76
+ ```
77
+
78
+ - To show image in view with Rails
79
+
80
+ EX:
81
+
82
+ = image_tag FileUpload.last.file_name.url
83
+
84
+ ## Contributing
85
+
86
+ Bug reports and pull requests are welcome on GitHub at https://github.com/thiensubs/carrierwave-box. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
87
+
88
+
89
+ ## License
90
+ Copyright (c) 2015 thiensubs - Vo Tien An
91
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
92
+
@@ -0,0 +1,25 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new("test_unit") do |t|
5
+ t.libs << "test"
6
+ t.pattern = 'test/**/*_test.rb'
7
+ t.verbose = true
8
+ t.description = "Run the unit tests without loading .credentials.yml"
9
+ end
10
+
11
+ # task :load_credentials do
12
+ # require 'yaml'
13
+
14
+ # path = File.expand_path("../.credentials.yml", __FILE__)
15
+ # hash = YAML.load(File.read(path))
16
+
17
+ # hash.each do |key, value|
18
+ # ENV[key.upcase] ||= value
19
+ # end
20
+ # end
21
+
22
+ desc "Run the unit tests"
23
+ task test: [:load_credentials, :test_unit]
24
+
25
+ task default: :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "carrierwave/box"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'carrierwave/box/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "carrierwave-box"
8
+ spec.version = Carrierwave::Box::VERSION
9
+ spec.authors = ["Vo Tien An"]
10
+ spec.email = ["nguoitinh.cuaanh.12@gmail.com"]
11
+
12
+ spec.summary = %q{CarrierWave storage for Box.net/Box.com}
13
+ spec.description = %q{Box.net/Box.com integration for CarrierWave.}
14
+ spec.homepage = "https://github.com/thiensubs/carrierwave-box"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+ spec.add_dependency "carrierwave", "~> 0.10"
22
+ spec.add_dependency "boxr"
23
+ spec.add_dependency "mechanize"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.10"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "activerecord", "~> 4.2"
29
+ end
@@ -0,0 +1,14 @@
1
+ require 'carrierwave'
2
+ require 'carrierwave/storage/box'
3
+ require "carrierwave/box/version"
4
+
5
+ class CarrierWave::Uploader::Base
6
+ add_config :box_client_id
7
+ add_config :box_client_secret
8
+ add_config :box_email
9
+ add_config :box_password
10
+ add_config :box_access_type
11
+ configure do |config|
12
+ config.storage_engines[:box] = 'CarrierWave::Storage::Box'
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module Carrierwave
2
+ module Box
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,117 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'boxr'
4
+ require 'mechanize'
5
+
6
+
7
+ module CarrierWave
8
+ module Storage
9
+ class Box < Abstract
10
+ # Stubs we must implement to create and save
11
+ attr_reader :client_box
12
+ # Store a single file
13
+ def store!(file)
14
+ @client_box = box_client
15
+ # if @client_box
16
+ path_folders = uploader.store_dir.split('/')
17
+ begin
18
+ path_temp = path_folders[0...-1].join('/')
19
+
20
+ folder_will_up = @client_box.folder_from_path(path_temp)
21
+ begin
22
+ @client_box.create_folder(path_folders.last, folder_will_up)
23
+ rescue Boxr::BoxrError => e
24
+ end
25
+ folder_will_up = @client_box.folder_from_path(uploader.store_dir)
26
+ file_up = @client_box.upload_file(file.to_file, folder_will_up)
27
+ file
28
+ rescue Boxr::BoxrError => e
29
+
30
+ path_folders.each_with_index do |path, index|
31
+ if index==0
32
+ begin
33
+ @client_box.create_folder("#{path}", "#{Boxr::ROOT}")
34
+ rescue Boxr::BoxrError => e
35
+ next
36
+ end
37
+ else
38
+ begin
39
+ parent = @client_box.folder_from_path("#{path_folders[0..index-1].join('/')}")
40
+ @client_box.create_folder("#{path}", parent)
41
+ rescue Boxr::BoxrError => e
42
+ next
43
+ end
44
+ end
45
+ end
46
+
47
+ folder_will_up = @client_box.folder_from_path(uploader.store_dir)
48
+ file_up = @client_box.upload_file(file.to_file, uploader.store_dir)
49
+ end
50
+
51
+ file
52
+ end
53
+
54
+ # Retrieve a single file
55
+ def retrieve!(file)
56
+ @client_box = box_client
57
+ CarrierWave::Storage::Box::File.new(uploader, config, uploader.store_path(file), @client_box)
58
+ end
59
+
60
+ private
61
+ def link_out client_id
62
+ "https://www.box.com/api/oauth2/authorize?client_id=#{client_id}&redirect_uri=http%3A%2F%2Flocalhost&response_type=code"
63
+ end
64
+ def box_client
65
+ @mechanize = Mechanize.new
66
+ page = @mechanize.get(link_out(uploader.box_client_id))
67
+ @mechanize.follow_meta_refresh = true
68
+ form = page.form
69
+ form.login = "#{uploader.box_email}"
70
+ form.password = "#{uploader.box_password}"
71
+ page1 = form.submit
72
+ form1 = page1.form
73
+ page_next = form1.submit
74
+ code = page_next.uri.to_s.split('code=').last
75
+ box_client = Boxr::get_tokens(code, grant_type: "authorization_code", assertion: nil, scope: nil, username: nil, client_id: uploader.box_client_id, client_secret: uploader.box_client_secret).access_token
76
+ Boxr::Client.new(box_client)
77
+ end
78
+ def config
79
+ @config ||= {}
80
+
81
+ @config[:box_client_id] ||= uploader.box_client_id
82
+ @config[:box_client_secret] ||= uploader.box_client_secret
83
+ @config[:box_email] ||= uploader.box_email
84
+ @config[:box_password] ||= uploader.box_password
85
+ @config[:box_access_type] ||= uploader.box_access_type || "box"
86
+
87
+ @config
88
+ end
89
+
90
+ class File
91
+ include CarrierWave::Utilities::Uri
92
+ attr_reader :path
93
+
94
+ def initialize(uploader, config, path, client)
95
+ @uploader, @config, @path, @client = uploader, config, path, client
96
+ end
97
+
98
+ def url
99
+ file_temp = @client.file_from_path(path)
100
+ file = @client.download_url(file_temp, version: nil)
101
+ end
102
+
103
+ def to_s
104
+ url ||= ''
105
+ end
106
+
107
+ def delete
108
+ file_temp = @client.file_from_path(@path)
109
+ begin
110
+ @client.delete_file(file_temp, if_match: nil)
111
+ rescue Boxr::BoxrError => e
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carrierwave-box
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Vo Tien An
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-11 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.10'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: boxr
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: mechanize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: activerecord
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '4.2'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '4.2'
111
+ description: Box.net/Box.com integration for CarrierWave.
112
+ email:
113
+ - nguoitinh.cuaanh.12@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - CODE_OF_CONDUCT.md
122
+ - Gemfile
123
+ - LICENSE
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - bin/console
128
+ - bin/setup
129
+ - carrierwave-box.gemspec
130
+ - lib/carrierwave/box.rb
131
+ - lib/carrierwave/box/version.rb
132
+ - lib/carrierwave/storage/box.rb
133
+ homepage: https://github.com/thiensubs/carrierwave-box
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.4.8
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: CarrierWave storage for Box.net/Box.com
157
+ test_files: []