paperclip-atompub 0.0.3.3 → 0.0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +20 -20
- data/README.rdoc +44 -44
- data/Rakefile +27 -27
- data/app/assets/javascripts/paperclip_atompub/application.js +15 -15
- data/app/assets/stylesheets/paperclip_atompub/application.css +13 -13
- data/app/controllers/paperclip_atompub/application_controller.rb +4 -4
- data/app/models/paperclip_atompub/attachment.rb +6 -6
- data/app/views/layouts/paperclip_atompub/application.html.erb +14 -14
- data/config/routes.rb +2 -2
- data/db/migrate/20121108051952_create_paperclip_atompub_attachments.rb +16 -16
- data/lib/paperclip-atompub.rb +1 -1
- data/lib/paperclip/storage/atompub.rb +116 -116
- data/lib/paperclip_atompub.rb +7 -7
- data/lib/paperclip_atompub/engine.rb +5 -5
- data/lib/paperclip_atompub/version.rb +3 -3
- data/lib/tasks/paperclip_atompub_tasks.rake +4 -4
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d389b88b87897623ac64620356041236b834b3fa
|
4
|
+
data.tar.gz: 3e94ebf2967d067b7ce24a0f5223b287a3801708
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3adc821eb89371d372bdcec7747576efac089f97531e42c52ea62543f798b3976f45150fac914ae86bc1e33ef0931c1a97aaa4b3bef7cac6394ef8eda2ef22e8
|
7
|
+
data.tar.gz: e32e99dc894a07bcd12adf8321f1d8312fcccc262e1315de9afd707bd7f862b2959bd4f280ecd542b906e667a9a224edf2a76ef4cc1c23adc6dbeebdb84ed8b5
|
data/MIT-LICENSE
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
Copyright 2012 YOURNAME
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
Copyright 2012 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
CHANGED
@@ -1,44 +1,44 @@
|
|
1
|
-
= Paperclip Atompub Storage
|
2
|
-
|
3
|
-
(Atompub Media Resource only.)
|
4
|
-
|
5
|
-
== Installation
|
6
|
-
|
7
|
-
gem 'paperclip-atompub', '~> 0.0.1'
|
8
|
-
|
9
|
-
bundle exec rake paperclip_atompub:install:migrations
|
10
|
-
bundle exec rake db:migrate
|
11
|
-
|
12
|
-
== Usage
|
13
|
-
|
14
|
-
=== Simple
|
15
|
-
|
16
|
-
class User < ActiveRecord::Base
|
17
|
-
attr_accessible :name, :avatar
|
18
|
-
has_attached_file :avatar,
|
19
|
-
:storage => :atompub,
|
20
|
-
:atompub_config => {
|
21
|
-
:service_uri => 'http://atompub.host/atomsvc',
|
22
|
-
:media_collection_uri => 'http://atompub.host/resources'
|
23
|
-
},
|
24
|
-
:atompub_credentials => {
|
25
|
-
:username => 'USERNAME',
|
26
|
-
:password => 'PASSWORD'
|
27
|
-
},
|
28
|
-
:styles => { :medium => "300x300>", :thumb => "100x100>" }
|
29
|
-
end
|
30
|
-
|
31
|
-
=== Dynamic Credentials
|
32
|
-
|
33
|
-
:atompub_credentials => lambda { |attachment|
|
34
|
-
user = attachment.instance # => #<User id:1>
|
35
|
-
{ :username => user.atompub_username, :password => user.atompub_password }
|
36
|
-
},
|
37
|
-
|
38
|
-
== Contributing to paperclip-atompub
|
39
|
-
|
40
|
-
Fork, fix, then send me a pull request.
|
41
|
-
|
42
|
-
== Copyright
|
43
|
-
|
44
|
-
Copyright(c) 2012 Yuichi Takeuchi, released under the MIT license
|
1
|
+
= Paperclip Atompub Storage
|
2
|
+
|
3
|
+
(Atompub Media Resource only.)
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
gem 'paperclip-atompub', '~> 0.0.1'
|
8
|
+
|
9
|
+
bundle exec rake paperclip_atompub:install:migrations
|
10
|
+
bundle exec rake db:migrate
|
11
|
+
|
12
|
+
== Usage
|
13
|
+
|
14
|
+
=== Simple
|
15
|
+
|
16
|
+
class User < ActiveRecord::Base
|
17
|
+
attr_accessible :name, :avatar
|
18
|
+
has_attached_file :avatar,
|
19
|
+
:storage => :atompub,
|
20
|
+
:atompub_config => {
|
21
|
+
:service_uri => 'http://atompub.host/atomsvc',
|
22
|
+
:media_collection_uri => 'http://atompub.host/resources'
|
23
|
+
},
|
24
|
+
:atompub_credentials => {
|
25
|
+
:username => 'USERNAME',
|
26
|
+
:password => 'PASSWORD'
|
27
|
+
},
|
28
|
+
:styles => { :medium => "300x300>", :thumb => "100x100>" }
|
29
|
+
end
|
30
|
+
|
31
|
+
=== Dynamic Credentials
|
32
|
+
|
33
|
+
:atompub_credentials => lambda { |attachment|
|
34
|
+
user = attachment.instance # => #<User id:1>
|
35
|
+
{ :username => user.atompub_username, :password => user.atompub_password }
|
36
|
+
},
|
37
|
+
|
38
|
+
== Contributing to paperclip-atompub
|
39
|
+
|
40
|
+
Fork, fix, then send me a pull request.
|
41
|
+
|
42
|
+
== Copyright
|
43
|
+
|
44
|
+
Copyright(c) 2012 Yuichi Takeuchi, released under the MIT license
|
data/Rakefile
CHANGED
@@ -1,27 +1,27 @@
|
|
1
|
-
#!/usr/bin/env rake
|
2
|
-
begin
|
3
|
-
require 'bundler/setup'
|
4
|
-
rescue LoadError
|
5
|
-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
-
end
|
7
|
-
begin
|
8
|
-
require 'rdoc/task'
|
9
|
-
rescue LoadError
|
10
|
-
require 'rdoc/rdoc'
|
11
|
-
require 'rake/rdoctask'
|
12
|
-
RDoc::Task = Rake::RDocTask
|
13
|
-
end
|
14
|
-
|
15
|
-
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
-
rdoc.rdoc_dir = 'rdoc'
|
17
|
-
rdoc.title = 'PaperclipAtompub'
|
18
|
-
rdoc.options << '--line-numbers'
|
19
|
-
rdoc.rdoc_files.include('README.rdoc')
|
20
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
Bundler::GemHelper.install_tasks
|
27
|
-
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'PaperclipAtompub'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
@@ -1,15 +1,15 @@
|
|
1
|
-
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
-
// listed below.
|
3
|
-
//
|
4
|
-
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
-
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
-
//
|
7
|
-
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
-
// the compiled file.
|
9
|
-
//
|
10
|
-
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
-
// GO AFTER THE REQUIRES BELOW.
|
12
|
-
//
|
13
|
-
//= require jquery
|
14
|
-
//= require jquery_ujs
|
15
|
-
//= require_tree .
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require_tree .
|
@@ -1,13 +1,13 @@
|
|
1
|
-
/*
|
2
|
-
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
-
* listed below.
|
4
|
-
*
|
5
|
-
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
-
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
-
*
|
8
|
-
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
-
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
-
*
|
11
|
-
*= require_self
|
12
|
-
*= require_tree .
|
13
|
-
*/
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module PaperclipAtompub
|
2
|
-
class ApplicationController < ActionController::Base
|
3
|
-
end
|
4
|
-
end
|
1
|
+
module PaperclipAtompub
|
2
|
+
class ApplicationController < ActionController::Base
|
3
|
+
end
|
4
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
module PaperclipAtompub
|
2
|
-
class Attachment < ActiveRecord::Base
|
3
|
-
attr_accessible :attachment_name, :instance_id, :instance_type, :resource_uri, :style
|
4
|
-
belongs_to :instance, :polymorphic => true
|
5
|
-
end
|
6
|
-
end
|
1
|
+
module PaperclipAtompub
|
2
|
+
class Attachment < ActiveRecord::Base
|
3
|
+
attr_accessible :attachment_name, :instance_id, :instance_type, :resource_uri, :style
|
4
|
+
belongs_to :instance, :polymorphic => true
|
5
|
+
end
|
6
|
+
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>PaperclipAtompub</title>
|
5
|
-
<%= stylesheet_link_tag "paperclip_atompub/application", :media => "all" %>
|
6
|
-
<%= javascript_include_tag "paperclip_atompub/application" %>
|
7
|
-
<%= csrf_meta_tags %>
|
8
|
-
</head>
|
9
|
-
<body>
|
10
|
-
|
11
|
-
<%= yield %>
|
12
|
-
|
13
|
-
</body>
|
14
|
-
</html>
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>PaperclipAtompub</title>
|
5
|
+
<%= stylesheet_link_tag "paperclip_atompub/application", :media => "all" %>
|
6
|
+
<%= javascript_include_tag "paperclip_atompub/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/config/routes.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
PaperclipAtompub::Engine.routes.draw do
|
2
|
-
end
|
1
|
+
PaperclipAtompub::Engine.routes.draw do
|
2
|
+
end
|
@@ -1,16 +1,16 @@
|
|
1
|
-
class CreatePaperclipAtompubAttachments < ActiveRecord::Migration
|
2
|
-
def change
|
3
|
-
create_table :paperclip_atompub_attachments do |t|
|
4
|
-
t.string :instance_type, :null => false
|
5
|
-
t.integer :instance_id, :null => false
|
6
|
-
t.string :attachment_name, :null => false
|
7
|
-
t.string :style, :null => false
|
8
|
-
t.string :resource_uri, :null => false
|
9
|
-
t.string :content_src, :null => false
|
10
|
-
t.timestamps
|
11
|
-
end
|
12
|
-
add_index :paperclip_atompub_attachments, [:instance_type, :instance_id], :name => 'attachments_on_instance_type_and_instance_id'
|
13
|
-
add_index :paperclip_atompub_attachments, [:instance_type, :instance_id, :attachment_name], :name => 'instance_type_and_instance_id_and_attachment_name'
|
14
|
-
add_index :paperclip_atompub_attachments, [:instance_type, :instance_id, :attachment_name, :style], :unique => true, :name => 'instance_type_and_instance_id_and_attachment_name_and_style'
|
15
|
-
end
|
16
|
-
end
|
1
|
+
class CreatePaperclipAtompubAttachments < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :paperclip_atompub_attachments do |t|
|
4
|
+
t.string :instance_type, :null => false
|
5
|
+
t.integer :instance_id, :null => false
|
6
|
+
t.string :attachment_name, :null => false
|
7
|
+
t.string :style, :null => false
|
8
|
+
t.string :resource_uri, :null => false
|
9
|
+
t.string :content_src, :null => false
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
add_index :paperclip_atompub_attachments, [:instance_type, :instance_id], :name => 'attachments_on_instance_type_and_instance_id'
|
13
|
+
add_index :paperclip_atompub_attachments, [:instance_type, :instance_id, :attachment_name], :name => 'instance_type_and_instance_id_and_attachment_name'
|
14
|
+
add_index :paperclip_atompub_attachments, [:instance_type, :instance_id, :attachment_name, :style], :unique => true, :name => 'instance_type_and_instance_id_and_attachment_name_and_style'
|
15
|
+
end
|
16
|
+
end
|
data/lib/paperclip-atompub.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require "paperclip_atompub"
|
1
|
+
require "paperclip_atompub"
|
@@ -1,116 +1,116 @@
|
|
1
|
-
require 'atomutil'
|
2
|
-
|
3
|
-
module Paperclip
|
4
|
-
module Storage
|
5
|
-
module Atompub
|
6
|
-
def self.extended(base)
|
7
|
-
base.instance_eval do
|
8
|
-
(@options.delete(:atompub_config) || {}).each do |key, value|
|
9
|
-
@options[:"atompub_#{key}"] = value
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def path(style_name = default_style)
|
15
|
-
style_name
|
16
|
-
end
|
17
|
-
|
18
|
-
def url(style_name = default_style)
|
19
|
-
attachment = atompub_attachment(style_name)
|
20
|
-
attachment ? attachment.content_src : nil
|
21
|
-
end
|
22
|
-
|
23
|
-
def exists?(style_name = default_style)
|
24
|
-
if original_filename
|
25
|
-
! atompub_entry(style_name).nil?
|
26
|
-
else
|
27
|
-
false
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def flush_writes #:nodoc:
|
32
|
-
@queued_for_write.each do |style, file|
|
33
|
-
begin
|
34
|
-
log("saving #{path(style)}")
|
35
|
-
attachment = atompub_attachment(style)
|
36
|
-
attachment.resource_uri = atompub_client.create_media(options[:atompub_media_collection_uri], file.path, file.content_type)
|
37
|
-
attachment.content_src = atompub_client.get_entry(attachment.resource_uri).content.src
|
38
|
-
attachment.save!
|
39
|
-
ensure
|
40
|
-
file.rewind
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def flush_deletes #:nodoc:
|
46
|
-
@queued_for_delete.each do |path|
|
47
|
-
begin
|
48
|
-
log("deleting #{path}")
|
49
|
-
entry = atompub_entry(path)
|
50
|
-
attachment = atompub_attachment(path).destroy
|
51
|
-
attachment.destroy
|
52
|
-
atompub_client.delete_media(entry.edit_media_link)
|
53
|
-
rescue ::Atompub::RequestError
|
54
|
-
# Ignore this.
|
55
|
-
end
|
56
|
-
end
|
57
|
-
@queued_for_delete = []
|
58
|
-
end
|
59
|
-
|
60
|
-
private
|
61
|
-
def atompub_auth
|
62
|
-
@atompub_auth ||= ::Atompub::Auth::Wsse.new(atompub_credentials)
|
63
|
-
end
|
64
|
-
|
65
|
-
def atompub_client
|
66
|
-
@atompub_client ||= begin
|
67
|
-
client = ::Atompub::Client.new(:auth => atompub_auth)
|
68
|
-
client.get_service(options[:atompub_service_uri])
|
69
|
-
client
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
def atompub_credentials
|
75
|
-
@atompub_credentials ||= parse_credentials(options[:atompub_credentials]).with_indifferent_access
|
76
|
-
end
|
77
|
-
|
78
|
-
def parse_credentials(creds)
|
79
|
-
creds = creds.respond_to?('call') ? creds.call(self) : creds
|
80
|
-
creds = find_credentials(creds).stringify_keys
|
81
|
-
env = Object.const_defined?(:Rails) ? Rails.env : nil
|
82
|
-
(creds[env] || creds).symbolize_keys
|
83
|
-
end
|
84
|
-
|
85
|
-
def find_credentials(creds)
|
86
|
-
case creds
|
87
|
-
when File
|
88
|
-
YAML::load(ERB.new(File.read(creds.path)).result)
|
89
|
-
when String, Pathname
|
90
|
-
YAML::load(ERB.new(File.read(creds)).result)
|
91
|
-
when Hash
|
92
|
-
creds
|
93
|
-
else
|
94
|
-
raise ArgumentError, "Credentials are not a path, file, proc, or hash."
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def atompub_attachment(style_name = default_style)
|
99
|
-
PaperclipAtompub::Attachment.where(:style => style_name,
|
100
|
-
:instance_type => self.instance.class.name,
|
101
|
-
:instance_id => self.instance.id,
|
102
|
-
:attachment_name => self.name).first_or_initialize
|
103
|
-
end
|
104
|
-
|
105
|
-
def atompub_entry(style_name = default_style)
|
106
|
-
entry = atompub_attachment(style_name)
|
107
|
-
return nil if entry.new_record?
|
108
|
-
|
109
|
-
return atompub_client.get_entry(entry.resource_uri)
|
110
|
-
rescue ::Atompub::RequestError
|
111
|
-
return nil
|
112
|
-
end
|
113
|
-
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
1
|
+
require 'atomutil'
|
2
|
+
|
3
|
+
module Paperclip
|
4
|
+
module Storage
|
5
|
+
module Atompub
|
6
|
+
def self.extended(base)
|
7
|
+
base.instance_eval do
|
8
|
+
(@options.delete(:atompub_config) || {}).each do |key, value|
|
9
|
+
@options[:"atompub_#{key}"] = value
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def path(style_name = default_style)
|
15
|
+
style_name
|
16
|
+
end
|
17
|
+
|
18
|
+
def url(style_name = default_style)
|
19
|
+
attachment = atompub_attachment(style_name)
|
20
|
+
attachment ? attachment.content_src : nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def exists?(style_name = default_style)
|
24
|
+
if original_filename
|
25
|
+
! atompub_entry(style_name).nil?
|
26
|
+
else
|
27
|
+
false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def flush_writes #:nodoc:
|
32
|
+
@queued_for_write.each do |style, file|
|
33
|
+
begin
|
34
|
+
log("saving #{path(style)}")
|
35
|
+
attachment = atompub_attachment(style)
|
36
|
+
attachment.resource_uri = atompub_client.create_media(options[:atompub_media_collection_uri], file.path, file.content_type, original_filename)
|
37
|
+
attachment.content_src = atompub_client.get_entry(attachment.resource_uri).content.src
|
38
|
+
attachment.save!
|
39
|
+
ensure
|
40
|
+
file.rewind
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def flush_deletes #:nodoc:
|
46
|
+
@queued_for_delete.each do |path|
|
47
|
+
begin
|
48
|
+
log("deleting #{path}")
|
49
|
+
entry = atompub_entry(path)
|
50
|
+
attachment = atompub_attachment(path).destroy
|
51
|
+
attachment.destroy
|
52
|
+
atompub_client.delete_media(entry.edit_media_link)
|
53
|
+
rescue ::Atompub::RequestError
|
54
|
+
# Ignore this.
|
55
|
+
end
|
56
|
+
end
|
57
|
+
@queued_for_delete = []
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
def atompub_auth
|
62
|
+
@atompub_auth ||= ::Atompub::Auth::Wsse.new(atompub_credentials)
|
63
|
+
end
|
64
|
+
|
65
|
+
def atompub_client
|
66
|
+
@atompub_client ||= begin
|
67
|
+
client = ::Atompub::Client.new(:auth => atompub_auth)
|
68
|
+
client.get_service(options[:atompub_service_uri])
|
69
|
+
client
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
def atompub_credentials
|
75
|
+
@atompub_credentials ||= parse_credentials(options[:atompub_credentials]).with_indifferent_access
|
76
|
+
end
|
77
|
+
|
78
|
+
def parse_credentials(creds)
|
79
|
+
creds = creds.respond_to?('call') ? creds.call(self) : creds
|
80
|
+
creds = find_credentials(creds).stringify_keys
|
81
|
+
env = Object.const_defined?(:Rails) ? Rails.env : nil
|
82
|
+
(creds[env] || creds).symbolize_keys
|
83
|
+
end
|
84
|
+
|
85
|
+
def find_credentials(creds)
|
86
|
+
case creds
|
87
|
+
when File
|
88
|
+
YAML::load(ERB.new(File.read(creds.path)).result)
|
89
|
+
when String, Pathname
|
90
|
+
YAML::load(ERB.new(File.read(creds)).result)
|
91
|
+
when Hash
|
92
|
+
creds
|
93
|
+
else
|
94
|
+
raise ArgumentError, "Credentials are not a path, file, proc, or hash."
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def atompub_attachment(style_name = default_style)
|
99
|
+
PaperclipAtompub::Attachment.where(:style => style_name,
|
100
|
+
:instance_type => self.instance.class.name,
|
101
|
+
:instance_id => self.instance.id,
|
102
|
+
:attachment_name => self.name).first_or_initialize
|
103
|
+
end
|
104
|
+
|
105
|
+
def atompub_entry(style_name = default_style)
|
106
|
+
entry = atompub_attachment(style_name)
|
107
|
+
return nil if entry.new_record?
|
108
|
+
|
109
|
+
return atompub_client.get_entry(entry.resource_uri)
|
110
|
+
rescue ::Atompub::RequestError
|
111
|
+
return nil
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
data/lib/paperclip_atompub.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require "paperclip_atompub/engine"
|
2
|
-
|
3
|
-
require 'paperclip'
|
4
|
-
require 'paperclip/storage/atompub'
|
5
|
-
|
6
|
-
module PaperclipAtompub
|
7
|
-
end
|
1
|
+
require "paperclip_atompub/engine"
|
2
|
+
|
3
|
+
require 'paperclip'
|
4
|
+
require 'paperclip/storage/atompub'
|
5
|
+
|
6
|
+
module PaperclipAtompub
|
7
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
module PaperclipAtompub
|
2
|
-
class Engine < ::Rails::Engine
|
3
|
-
isolate_namespace PaperclipAtompub
|
4
|
-
end
|
5
|
-
end
|
1
|
+
module PaperclipAtompub
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace PaperclipAtompub
|
4
|
+
end
|
5
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
module PaperclipAtompub
|
2
|
-
VERSION = "0.0.3.
|
3
|
-
end
|
1
|
+
module PaperclipAtompub
|
2
|
+
VERSION = "0.0.3.4"
|
3
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# desc "Explaining what the task does"
|
2
|
-
# task :paperclip-atompub do
|
3
|
-
# # Task goes here
|
4
|
-
# end
|
1
|
+
# desc "Explaining what the task does"
|
2
|
+
# task :paperclip-atompub do
|
3
|
+
# # Task goes here
|
4
|
+
# end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip-atompub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.3.
|
4
|
+
version: 0.0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuichi Takeuchi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05
|
11
|
+
date: 2013-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -101,19 +101,19 @@ executables: []
|
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
|
-
- app/models/paperclip_atompub/attachment.rb
|
105
|
-
- app/controllers/paperclip_atompub/application_controller.rb
|
106
|
-
- app/assets/stylesheets/paperclip_atompub/application.css
|
107
104
|
- app/assets/javascripts/paperclip_atompub/application.js
|
105
|
+
- app/assets/stylesheets/paperclip_atompub/application.css
|
106
|
+
- app/controllers/paperclip_atompub/application_controller.rb
|
107
|
+
- app/models/paperclip_atompub/attachment.rb
|
108
108
|
- app/views/layouts/paperclip_atompub/application.html.erb
|
109
109
|
- config/routes.rb
|
110
110
|
- db/migrate/20121108051952_create_paperclip_atompub_attachments.rb
|
111
|
+
- lib/paperclip/storage/atompub.rb
|
112
|
+
- lib/paperclip-atompub.rb
|
111
113
|
- lib/paperclip_atompub/engine.rb
|
112
114
|
- lib/paperclip_atompub/version.rb
|
113
|
-
- lib/paperclip-atompub.rb
|
114
|
-
- lib/tasks/paperclip_atompub_tasks.rake
|
115
|
-
- lib/paperclip/storage/atompub.rb
|
116
115
|
- lib/paperclip_atompub.rb
|
116
|
+
- lib/tasks/paperclip_atompub_tasks.rake
|
117
117
|
- MIT-LICENSE
|
118
118
|
- Rakefile
|
119
119
|
- README.rdoc
|
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
136
|
version: '0'
|
137
137
|
requirements: []
|
138
138
|
rubyforge_project:
|
139
|
-
rubygems_version: 2.0.
|
139
|
+
rubygems_version: 2.0.3
|
140
140
|
signing_key:
|
141
141
|
specification_version: 4
|
142
142
|
summary: Adds Atompub Media Resource strage support for the Paperclip
|