paperclip-webmerge 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 +9 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +112 -0
- data/Rakefile +6 -0
- data/lib/paperclip_web_merge.rb +102 -0
- data/lib/paperclip_web_merge/version.rb +7 -0
- data/paperclip-webmerge.gemspec +25 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c8f6abbc6698c4131b6557f6c22006be00ca0713
|
4
|
+
data.tar.gz: 4cb92d7fd9605cf7271d07143100e9d141191870
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f04e61dd84e9218a6eb0723aa910266bd1dfde5ac6c80f9bd735095d2795806f600d9ef3518e2785a52ce56325588a1eb0874f04324e8aa96c364b692181ff10
|
7
|
+
data.tar.gz: ce14e3963b14fd479d1e9b932427be2e5850b5f8d0cab29588e73686a862aee79baaf5bd7014fde9bce250ceed39f027315e1bc35d2b83150fd5d0b758970855
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Joshua Plicque
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
# Paperclip WebMerge
|
2
|
+
|
3
|
+
This gem allows you to save [Paperclip](https://github.com/thoughtbot/paperclip) files on [WebMerge](https://www.webmerge.me/)
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile. Bundle, then restart your server.
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'paperclip-webmerge'
|
12
|
+
```
|
13
|
+
Migrate your model to have a `web_merge_id` integer attribute. When Paperclip saves your file, it will reference the document id on WebMerge with this attribute.
|
14
|
+
|
15
|
+
```
|
16
|
+
rails g migration add_web_merge_id_to_your_model web_merge_id:integer
|
17
|
+
rake db:migrate
|
18
|
+
```
|
19
|
+
|
20
|
+
|
21
|
+
## Setup
|
22
|
+
|
23
|
+
Example:
|
24
|
+
|
25
|
+
Add paperclip to your model, specifiying `:web_merge` as the storage adapter.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
class User
|
29
|
+
has_attached_file :document, storage: :web_merge, web_merge_credentials: Rails.root.join('config/web_merge.yml')
|
30
|
+
...
|
31
|
+
end
|
32
|
+
```
|
33
|
+
Add WebMerge your API credentials. You can get your credentials under "Api Access" over at [WebMerge](https://www.webmerge.me/)
|
34
|
+
|
35
|
+
```
|
36
|
+
# config/web_merge.yml
|
37
|
+
|
38
|
+
api_key: <%= ENV["WEB_MERGE_API_KEY"] %>,
|
39
|
+
api_secret: <%= ENV["WEB_MERGE_API_SECRET"] %>
|
40
|
+
```
|
41
|
+
|
42
|
+
You are fully setup. Your files now sync up with WebMerge!
|
43
|
+
|
44
|
+
|
45
|
+
## Usage
|
46
|
+
|
47
|
+
### The `:web_merge_credentials` option
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
:web_merge_credentials => Rails.root.join("config/web_merge.yml")
|
51
|
+
# or
|
52
|
+
:web_merge_credentials => {api_key: "foo", api_secret: "bar"}
|
53
|
+
```
|
54
|
+
|
55
|
+
For the list of required credentials, take a look at the `config/web_merge.yml`
|
56
|
+
above.
|
57
|
+
|
58
|
+
The YAML file supports ERB:
|
59
|
+
|
60
|
+
```
|
61
|
+
api_key: <%= ENV["WEB_MERGE_API_KEY"] %>
|
62
|
+
api_secret: <%= ENV["WEB_MERGE_API_SECRET"] %>
|
63
|
+
```
|
64
|
+
|
65
|
+
And it supports environment nesting (just like `database.yml`):
|
66
|
+
|
67
|
+
```yaml
|
68
|
+
development:
|
69
|
+
api_key: "..."
|
70
|
+
api_secret: "..."
|
71
|
+
production:
|
72
|
+
api_key: "..."
|
73
|
+
api_secret: "..."
|
74
|
+
```
|
75
|
+
|
76
|
+
### The `:path` option
|
77
|
+
|
78
|
+
To change the path of the file, use Paperclip's `:path` option:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
:path => ":style/:id_:filename" # Defaults to ":filename"
|
82
|
+
```
|
83
|
+
|
84
|
+
### URL options
|
85
|
+
|
86
|
+
If you want to force the browser to always download the file, you can use
|
87
|
+
the `:download` option.
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
user.document.url(:download => true)
|
91
|
+
```
|
92
|
+
|
93
|
+
### Check if the file exists
|
94
|
+
|
95
|
+
It may happen that a file on WebMerge gets deleted remotely. To check this in
|
96
|
+
your application, you can use the `#exists?` method:
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
user.document.exists?
|
100
|
+
# user.document.exists?(style)
|
101
|
+
```
|
102
|
+
|
103
|
+
## Contributing
|
104
|
+
|
105
|
+
After checking out the repo, run `bundle install` to install dependencies. Then, run `rake spec` to run the tests.
|
106
|
+
|
107
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/plicjo/paperclip-webmerge.
|
108
|
+
|
109
|
+
## License
|
110
|
+
|
111
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
112
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'paperclip_web_merge/version'
|
2
|
+
require 'web_merge'
|
3
|
+
|
4
|
+
module Paperclip
|
5
|
+
module Storage
|
6
|
+
module WebMerge
|
7
|
+
def self.extended base
|
8
|
+
begin
|
9
|
+
require 'web_merge'
|
10
|
+
rescue LoadError => e
|
11
|
+
e.message << " (You may need to install the web_merge gem)"
|
12
|
+
raise e
|
13
|
+
end
|
14
|
+
|
15
|
+
base.instance_eval do
|
16
|
+
@web_merge_credentials = parse_credentials(@options[:web_merge_credentials])
|
17
|
+
@client = ::WebMerge::API.new(secret: @web_merge_credentials[:api_secret], key: @web_merge_credentials[:api_key])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse_credentials creds
|
22
|
+
creds = find_credentials(creds).stringify_keys
|
23
|
+
creds.symbolize_keys
|
24
|
+
end
|
25
|
+
|
26
|
+
def exists?(style = default_style)
|
27
|
+
if original_filename
|
28
|
+
begin
|
29
|
+
::WebMerge::Document.find(instance.web_merge_id, client: @client)
|
30
|
+
rescue
|
31
|
+
false
|
32
|
+
end
|
33
|
+
else
|
34
|
+
false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def copy_to_local_file(style, local_dest_path)
|
39
|
+
log("copying #{path(style)} to local file #{local_dest_path}")
|
40
|
+
::File.open(local_dest_path, 'wb') do |local_file|
|
41
|
+
file_contents = @client.get_document_file(instance.web_merge_id)['contents']
|
42
|
+
web_merge_file = Base64.decode64(file_contents)
|
43
|
+
local_file.write(web_merge_file)
|
44
|
+
end
|
45
|
+
rescue
|
46
|
+
warn("cannot copy #{path(style)} to local file #{local_dest_path}")
|
47
|
+
false
|
48
|
+
end
|
49
|
+
|
50
|
+
def file_type(file)
|
51
|
+
{
|
52
|
+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
|
53
|
+
'application/pdf' => 'pdf',
|
54
|
+
'application/vnd.ms-excel' => 'xlsx',
|
55
|
+
'application/vnd.ms-excel.sheet.macroenabled.12' => 'xlsx',
|
56
|
+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx',
|
57
|
+
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx',
|
58
|
+
'application/vnd.ms-powerpoint' => 'pptx',
|
59
|
+
'application/zip' => -> { MIME::Types.type_for(file.path).first.to_s },
|
60
|
+
'application/octet-stream' => -> { MIME::Types.type_for(file.path).first.to_s }
|
61
|
+
}[file.content_type]
|
62
|
+
end
|
63
|
+
|
64
|
+
def flush_writes
|
65
|
+
@queued_for_write.each do |style, file|
|
66
|
+
log("Saving to WebMerge #{path(style)}")
|
67
|
+
document = ::WebMerge::Document.new(client: @client, name: path, type: file_type(file), output: file_type(file), file_path: file.path)
|
68
|
+
document.save!
|
69
|
+
instance.update_column(:web_merge_id, document.id)
|
70
|
+
end
|
71
|
+
@queued_for_write = {}
|
72
|
+
end
|
73
|
+
|
74
|
+
def flush_deletes
|
75
|
+
@queued_for_delete.each do |path|
|
76
|
+
begin
|
77
|
+
log("deleting #{path}")
|
78
|
+
@client.delete_document(instance.web_merge_id)
|
79
|
+
instance.update_column(:web_merge_id, nil)
|
80
|
+
rescue
|
81
|
+
log("error deleting #{path}")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
@queued_for_delete = []
|
85
|
+
end
|
86
|
+
|
87
|
+
def find_credentials creds
|
88
|
+
case creds
|
89
|
+
when File
|
90
|
+
YAML::load(ERB.new(File.read(creds.path)).result)
|
91
|
+
when String
|
92
|
+
YAML::load(ERB.new(File.read(creds)).result)
|
93
|
+
when Hash
|
94
|
+
creds
|
95
|
+
else
|
96
|
+
raise ArgumentError, "Credentials are not a path, file, or hash."
|
97
|
+
end
|
98
|
+
end
|
99
|
+
private :find_credentials
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'paperclip_web_merge/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "paperclip-webmerge"
|
8
|
+
spec.version = Paperclip::Storage::WebMerge::VERSION
|
9
|
+
spec.authors = ["Joshua Plicque"]
|
10
|
+
spec.email = ["plicjo@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A Paperclip storage adapter for WebMerge}
|
13
|
+
spec.description = %q{A Paperclip storage adapter for WebMerge}
|
14
|
+
spec.homepage = "http://github.com/plicjo/paperclip-web-merge"
|
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
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paperclip-webmerge
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joshua Plicque
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: A Paperclip storage adapter for WebMerge
|
56
|
+
email:
|
57
|
+
- plicjo@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/paperclip_web_merge.rb
|
69
|
+
- lib/paperclip_web_merge/version.rb
|
70
|
+
- paperclip-webmerge.gemspec
|
71
|
+
homepage: http://github.com/plicjo/paperclip-web-merge
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.5.1
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: A Paperclip storage adapter for WebMerge
|
95
|
+
test_files: []
|