carrierwave-truevault 0.0.1
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 +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +46 -0
- data/Rakefile +2 -0
- data/carrierwave-truevault.gemspec +26 -0
- data/lib/carrierwave/storage/truevault.rb +121 -0
- data/lib/carrierwave/truevault/client.rb +121 -0
- data/lib/carrierwave/truevault/version.rb +5 -0
- data/lib/carrierwave/truevault.rb +14 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1a52a2c2dc21a9cb6cd5f430e7d8ea9b9e45060c
|
4
|
+
data.tar.gz: dd3b9b48f9588cc2f96f08c7a7eafba0b34fa7a6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dd8658d7423a56697cf65650401f3045a708e0eb433f966253fb6a212cbabad30c73085f74c3e3d16383562b7cd59d43ab66e7d5f03c6bd829f89ca9e159a119
|
7
|
+
data.tar.gz: 76201253390d18e204f7b35c477d9fa3d598ee98ade47491aef05f6632151a95c0bf408867337c610b8e589b85cf820574fe2231ebb971bfcf6238d9f6684456
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
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
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Matthew McFarling
|
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,46 @@
|
|
1
|
+
# Carrierwave::TrueVault
|
2
|
+
|
3
|
+
This gem adds support for [TrueVault](https://truevault.com) to the CarrierWave.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'carrierwave-truevault'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install carrierwave-truevault
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
You'll need to add a configuration block in your ```
|
22
|
+
config/initializers/carrierwave.rb ``` file.
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
CarrierWave.configure do |config|
|
26
|
+
config.truevault_api_key = "xxxxxx......"
|
27
|
+
config.truevault_vault_id = "xxxxx......"
|
28
|
+
config.truevault_attributes = {}
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
In your uploader add truevault as the storage option:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
class DocumentUploader < CarrierWave::Uploader::Base
|
36
|
+
storage :truevault
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it ( https://github.com/[my-github-username]/carrierwave-truevault/fork )
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'carrierwave/truevault/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "carrierwave-truevault"
|
8
|
+
spec.version = Carrierwave::TrueVault::VERSION
|
9
|
+
spec.authors = ["Matthew McFarling"]
|
10
|
+
spec.email = ["matt@codemancode.com"]
|
11
|
+
spec.summary = %q{TrueVault integration for Carrierwave.}
|
12
|
+
spec.description = %q{Carrierwave storage for TrueVault.}
|
13
|
+
spec.homepage = "http://www.codemancode.com"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "carrierwave"
|
22
|
+
spec.add_dependency 'httparty'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module CarrierWave
|
4
|
+
module Storage
|
5
|
+
class TrueVault < Abstract
|
6
|
+
def store!(file)
|
7
|
+
f = CarrierWave::Storage::TrueVault::File.new(uploader, self, uploader.store_path)
|
8
|
+
f.store(file)
|
9
|
+
f
|
10
|
+
end
|
11
|
+
|
12
|
+
def retrieve!(identifier)
|
13
|
+
f = CarrierWave::Storage::TrueVault::File.new(uploader, self, uploader.store_path(identifier))
|
14
|
+
f.retrieve(identifier)
|
15
|
+
f
|
16
|
+
end
|
17
|
+
|
18
|
+
class File
|
19
|
+
include CarrierWave::Utilities::Uri
|
20
|
+
attr_reader :path
|
21
|
+
|
22
|
+
def filename
|
23
|
+
Pathname.new(path).basename
|
24
|
+
end
|
25
|
+
##
|
26
|
+
# Lookup value for file content-type header
|
27
|
+
#
|
28
|
+
# === Returns
|
29
|
+
#
|
30
|
+
# [String] value of content-type
|
31
|
+
#
|
32
|
+
def content_type
|
33
|
+
@content_type || file.content_type
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Set non-default content-type header (default is file.content_type)
|
38
|
+
#
|
39
|
+
# === Returns
|
40
|
+
#
|
41
|
+
# [String] returns new content type value
|
42
|
+
#
|
43
|
+
def content_type=(new_content_type)
|
44
|
+
@content_type = new_content_type
|
45
|
+
end
|
46
|
+
|
47
|
+
def initialize(uploader, base, path)
|
48
|
+
@uploader, @base, @path = uploader, base, path
|
49
|
+
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# Read content of file from service
|
53
|
+
#
|
54
|
+
# === Returns
|
55
|
+
#
|
56
|
+
# [String] contents of file
|
57
|
+
def read
|
58
|
+
file
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# Return size of file body
|
63
|
+
#
|
64
|
+
# === Returns
|
65
|
+
#
|
66
|
+
# [Integer] size of file body
|
67
|
+
#
|
68
|
+
def size
|
69
|
+
file.content_length
|
70
|
+
end
|
71
|
+
|
72
|
+
def truevault_attributes
|
73
|
+
attributes
|
74
|
+
end
|
75
|
+
|
76
|
+
##
|
77
|
+
# Write file to service
|
78
|
+
#
|
79
|
+
# === Returns
|
80
|
+
#
|
81
|
+
# [Boolean] true on success or raises error
|
82
|
+
#
|
83
|
+
def store(file)
|
84
|
+
truevault_file = file.to_file
|
85
|
+
@content_type ||= file.content_type
|
86
|
+
@file = client.create_blob(@uploader.truevault_vault_id, truevault_file)
|
87
|
+
@uploader.truevault_attributes.merge!(@file.parsed_response)
|
88
|
+
end
|
89
|
+
|
90
|
+
##
|
91
|
+
# Retrieve file from service
|
92
|
+
#
|
93
|
+
# === Returns
|
94
|
+
#
|
95
|
+
# [File]
|
96
|
+
#
|
97
|
+
def retrieve(identifier)
|
98
|
+
@file = client.get_blob(@uploader.truevault_vault_id, model.blob_id)
|
99
|
+
@file ||= @file.parsed_response
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
|
104
|
+
def model
|
105
|
+
@uploader.model
|
106
|
+
end
|
107
|
+
|
108
|
+
def client
|
109
|
+
CarrierWave::TrueVault::Client.new(@uploader.truevault_api_key)
|
110
|
+
end
|
111
|
+
|
112
|
+
def file
|
113
|
+
tmp = client.get_blob(@uploader.truevault_vault_id, model.blob_id)
|
114
|
+
@file ||= IO.binread(tmp.parsed_response)
|
115
|
+
@file
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# Code extracted from https://github.com/marks/truevault.rb
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
module CarrierWave
|
5
|
+
module TrueVault
|
6
|
+
# Custom parser class for TrueVault API
|
7
|
+
class Parser < HTTParty::Parser
|
8
|
+
SupportedFormats.merge!({"application/octet-stream" => :octet_stream})
|
9
|
+
|
10
|
+
def parse
|
11
|
+
case format
|
12
|
+
when :html
|
13
|
+
body
|
14
|
+
when :json
|
15
|
+
JSON.parse(body)
|
16
|
+
when :octet_stream
|
17
|
+
# TODO find a better way of doing this
|
18
|
+
# The issue is that no matter what it gets frmo TV
|
19
|
+
# the ContentType is always octet_stream
|
20
|
+
begin
|
21
|
+
JSON.parse(Base64.decode64(body))
|
22
|
+
rescue JSON::ParserError
|
23
|
+
file = Tempfile.new('blob')
|
24
|
+
file.binmode
|
25
|
+
file.write(body)
|
26
|
+
file.rewind
|
27
|
+
file
|
28
|
+
end
|
29
|
+
else
|
30
|
+
body
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
class Client
|
37
|
+
include HTTParty
|
38
|
+
require 'json'
|
39
|
+
require 'base64'
|
40
|
+
|
41
|
+
# debug_output
|
42
|
+
base_uri 'https://api.truevault.com'
|
43
|
+
parser Parser
|
44
|
+
|
45
|
+
def default_options_to_merge_with
|
46
|
+
{:basic_auth => {:username => @api_key, :password => nil}}
|
47
|
+
end
|
48
|
+
|
49
|
+
def hash_to_base64_json(hash = {})
|
50
|
+
Base64.encode64(hash.to_json)
|
51
|
+
end
|
52
|
+
|
53
|
+
# api_key should be a valid TrueVault API key
|
54
|
+
# account_id should be a valid TrueVault account ID
|
55
|
+
# api_version should be a valid API version (ex 'v1')
|
56
|
+
def initialize(api_key, api_version = 'v1')
|
57
|
+
@api_key = api_key
|
58
|
+
@api_ver = api_version
|
59
|
+
instance_variables.each do |variable|
|
60
|
+
raise ArgumentError, "#{variable} should not be nil or blank" if instance_variable_get(variable.to_sym).to_s == ""
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
####################################################
|
65
|
+
### JSON (structured text data store) API Methods
|
66
|
+
####################################################
|
67
|
+
|
68
|
+
# vault_id should be a valid vault ID
|
69
|
+
# document_id should be a valid document ID
|
70
|
+
# document_data should be a Ruby Hash. Method will convert it to JSON and base64 encode as required
|
71
|
+
def create_document(vault_id, document_data, options = {})
|
72
|
+
options.merge!(default_options_to_merge_with)
|
73
|
+
options[:body] = {:document => hash_to_base64_json(document_data)}
|
74
|
+
self.class.post("/#{@api_ver}/vaults/#{vault_id}/documents", options)
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_document(vault_id, document_id, options = {})
|
78
|
+
options.merge!(default_options_to_merge_with)
|
79
|
+
self.class.get("/#{@api_ver}/vaults/#{vault_id}/documents/#{document_id}", options)
|
80
|
+
end
|
81
|
+
|
82
|
+
def delete_document(vault_id, document_id, options = {})
|
83
|
+
options.merge!(default_options_to_merge_with)
|
84
|
+
self.class.delete("/#{@api_ver}/vaults/#{vault_id}/documents/#{document_id}", options)
|
85
|
+
end
|
86
|
+
|
87
|
+
def update_document(vault_id, document_id, document_data, options = {})
|
88
|
+
options.merge!(default_options_to_merge_with)
|
89
|
+
options[:body] = {:document => hash_to_base64_json(document_data)}
|
90
|
+
self.class.put("/#{@api_ver}/vaults/#{vault_id}/documents/#{document_id}", options)
|
91
|
+
end
|
92
|
+
|
93
|
+
#####################################
|
94
|
+
### BLOB (binary file) API Methods
|
95
|
+
#####################################
|
96
|
+
|
97
|
+
def create_blob(vault_id, file, options = {:headers => {"Content-Type"=>"application/octet-stream"}})
|
98
|
+
options.merge!(default_options_to_merge_with)
|
99
|
+
options[:body] = file.read
|
100
|
+
self.class.post("/#{@api_ver}/vaults/#{vault_id}/blobs", options)
|
101
|
+
end
|
102
|
+
|
103
|
+
def replace_blob(vault_id, blob_id, file, options = {:headers => {"Content-Type"=>"application/octet-stream"}})
|
104
|
+
options.merge!(default_options_to_merge_with)
|
105
|
+
options[:body] = file.read
|
106
|
+
self.class.put("/#{@api_ver}/vaults/#{vault_id}/blobs/#{blob_id}", options)
|
107
|
+
end
|
108
|
+
|
109
|
+
def delete_blob(vault_id, blob_id, options = {})
|
110
|
+
options.merge!(default_options_to_merge_with)
|
111
|
+
self.class.delete("/#{@api_ver}/vaults/#{vault_id}/blobs/#{blob_id}", options)
|
112
|
+
end
|
113
|
+
|
114
|
+
def get_blob(vault_id, blob_id, options = {})
|
115
|
+
options.merge!(default_options_to_merge_with)
|
116
|
+
self.class.get("/#{@api_ver}/vaults/#{vault_id}/blobs/#{blob_id}", options)
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'carrierwave'
|
2
|
+
require 'carrierwave/truevault/client'
|
3
|
+
require 'carrierwave/storage/truevault'
|
4
|
+
require "carrierwave/truevault/version"
|
5
|
+
|
6
|
+
class CarrierWave::Uploader::Base
|
7
|
+
add_config :truevault_api_key
|
8
|
+
add_config :truevault_vault_id
|
9
|
+
add_config :truevault_attributes
|
10
|
+
|
11
|
+
configure do |config|
|
12
|
+
config.storage_engines[:truevault] = 'CarrierWave::Storage::TrueVault'
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: carrierwave-truevault
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew McFarling
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-19 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: httparty
|
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: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Carrierwave storage for TrueVault.
|
70
|
+
email:
|
71
|
+
- matt@codemancode.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- carrierwave-truevault.gemspec
|
82
|
+
- lib/carrierwave/storage/truevault.rb
|
83
|
+
- lib/carrierwave/truevault.rb
|
84
|
+
- lib/carrierwave/truevault/client.rb
|
85
|
+
- lib/carrierwave/truevault/version.rb
|
86
|
+
homepage: http://www.codemancode.com
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.2.2
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: TrueVault integration for Carrierwave.
|
110
|
+
test_files: []
|