nesta-plugin-drop 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 +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +15 -0
- data/Rakefile +2 -0
- data/lib/nesta-plugin-drop/app.rb +18 -0
- data/lib/nesta-plugin-drop/client.rb +119 -0
- data/lib/nesta-plugin-drop/helpers.rb +30 -0
- data/lib/nesta-plugin-drop/init.rb +2 -0
- data/lib/nesta-plugin-drop/openuri_monkeypatch.rb +31 -0
- data/lib/nesta-plugin-drop/routes.rb +41 -0
- data/lib/nesta-plugin-drop/version.rb +7 -0
- data/lib/nesta-plugin-drop.rb +3 -0
- data/nesta-plugin-drop.gemspec +26 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b0ba4e2fdf619bc9bf6842dfdca56ae602e8a475
|
4
|
+
data.tar.gz: 38a32f55ebd5d0cc8b21b8aedc4c813b3c4db007
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 195083864b8e2354c6cfcc7f3984e031d63260939c08925af1b34a59f3281608ee9ac32636b440e748b7831cb9730711307abab5abe044397067f8f6db88e04a
|
7
|
+
data.tar.gz: 8ce7690430c6dfe5c25b10c0a8bad209f7baa1517b1fafda6b2a4a00131812599611e4d10442c46ba58852b380100eecaad459b5a7e7749a4642d372718b81dc
|
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) 2015 Glu IO Pty Ltd, Glenn Gillen
|
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,15 @@
|
|
1
|
+
# Nestadrop
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
## Contributing
|
10
|
+
|
11
|
+
1. Fork it ( https://github.com/gluio/nesta-plugin-drop/fork )
|
12
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
13
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
14
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
15
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "nesta-plugin-drop/client"
|
2
|
+
require "nesta-plugin-drop/helpers"
|
3
|
+
require "nesta-plugin-drop/routes"
|
4
|
+
module Nesta
|
5
|
+
class App
|
6
|
+
include Nesta::Plugin::Drop::Routes
|
7
|
+
helpers Nesta::Plugin::Drop::Helpers
|
8
|
+
before do
|
9
|
+
check_nestadrop
|
10
|
+
end
|
11
|
+
|
12
|
+
error do
|
13
|
+
set_common_variables
|
14
|
+
haml(:error)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'rest_client'
|
3
|
+
require 'yajl'
|
4
|
+
module Nesta
|
5
|
+
module Plugin
|
6
|
+
module Drop
|
7
|
+
class Client
|
8
|
+
def self.host
|
9
|
+
ENV["NESTADROP_URL"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.userinfo
|
13
|
+
URI.parse(host).userinfo.split(":")
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.lock
|
17
|
+
@lock ||= Mutex.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.confirm_synced!
|
21
|
+
return true if nestadrop_synced?
|
22
|
+
File.open("/tmp/.nestadropped", "w+") do |f|
|
23
|
+
f.write "synced"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.syncing?
|
28
|
+
lock.synchronize do
|
29
|
+
@syncing
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.nestadrop_synced?
|
34
|
+
File.exists?("/tmp/.nestadropped")
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.nestadrop_configured?
|
38
|
+
return true if nestadrop_synced?
|
39
|
+
json = RestClient.get "#{host}account", {
|
40
|
+
accept: :json, x_nestadrop_version: Nesta::Plugin::Drop::VERSION }
|
41
|
+
account = Yajl::Parser.parse json
|
42
|
+
account["uid"] && account["token"] && account["domain"]
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.bounce_server!
|
46
|
+
return if syncing?
|
47
|
+
puts "Restarting server..."
|
48
|
+
system("bundle exec pumactl -S /app/state phased-restart")
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.files
|
52
|
+
lock.synchronize do
|
53
|
+
@files ||= Yajl::Parser.parse(RestClient.get "#{host}files", {
|
54
|
+
accept: :json, x_nestadrop_version: Nesta::Plugin::Drop::VERSION })
|
55
|
+
end
|
56
|
+
@files
|
57
|
+
rescue RestClient::Unauthorized
|
58
|
+
return []
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.uncached_files
|
62
|
+
@uncached_files
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.uncached_files=(val)
|
66
|
+
lock.synchronize do
|
67
|
+
@uncached_files ||= val
|
68
|
+
end
|
69
|
+
@uncached_files
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.cache_file(file)
|
73
|
+
confirm_synced!
|
74
|
+
local_path = [Nesta::App.root, file].join("/")
|
75
|
+
puts "Caching: #{local_path}"
|
76
|
+
FileUtils.mkdir_p(File.dirname(local_path))
|
77
|
+
file_contents = RestClient.get "#{host}file?file=#{URI.encode(file)}"
|
78
|
+
File.open(local_path, 'w') do |fo|
|
79
|
+
fo.write file_contents
|
80
|
+
end
|
81
|
+
bounce_server!
|
82
|
+
rescue RuntimeError => ex
|
83
|
+
puts ex
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.cache_files
|
87
|
+
self.uncached_files = Client.files
|
88
|
+
return unless uncached_files.size > 0
|
89
|
+
@syncing = true
|
90
|
+
threads = []
|
91
|
+
5.times do
|
92
|
+
threads << Thread.new do
|
93
|
+
file = nil
|
94
|
+
lock.synchronize do
|
95
|
+
file = self.uncached_files.pop
|
96
|
+
end
|
97
|
+
cache_file(file) if file
|
98
|
+
end
|
99
|
+
end
|
100
|
+
threads.each(&:join)
|
101
|
+
@syncing = false
|
102
|
+
bounce_server!
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.remove_file(file)
|
106
|
+
local_path = [Nesta::App.root, file].join("/")
|
107
|
+
FileUtils.rm_r(File.dirname(local_path), secure: true)
|
108
|
+
bounce_server!
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.bootstrap!
|
112
|
+
unless nestadrop_synced?
|
113
|
+
cache_files
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Nesta
|
2
|
+
module Plugin
|
3
|
+
module Drop
|
4
|
+
module Helpers
|
5
|
+
def nestadrop_configured?
|
6
|
+
Client.nestadrop_configured?
|
7
|
+
end
|
8
|
+
|
9
|
+
def setup_nestadrop
|
10
|
+
redirect to("#{Nesta::Plugin::Drop::Client.host}account/setup?domain=#{request.host}")
|
11
|
+
end
|
12
|
+
|
13
|
+
def check_nestadrop
|
14
|
+
return if request.path_info =~ %r{\A/nestadrop\z}
|
15
|
+
setup_nestadrop unless nestadrop_configured?
|
16
|
+
end
|
17
|
+
|
18
|
+
def nestadrop_request?
|
19
|
+
expected_user, expected_pass = Client.userinfo
|
20
|
+
auth = Rack::Auth::Basic::Request.new(request.env)
|
21
|
+
if auth.provided? && auth.basic? && auth.credentials == [expected_user, expected_pass]
|
22
|
+
return true
|
23
|
+
else
|
24
|
+
return false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "uri"
|
2
|
+
module OpenURI
|
3
|
+
class <<self
|
4
|
+
alias_method :open_uri_original, :open_uri
|
5
|
+
alias_method :redirectable_cautious?, :redirectable?
|
6
|
+
|
7
|
+
def redirectable_baller? uri1, uri2
|
8
|
+
valid = /\A(?:https?|ftp)\z/i
|
9
|
+
valid =~ uri1.scheme.downcase && valid =~ uri2.scheme
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# The original open_uri takes *args but then doesn't do anything with them.
|
14
|
+
# Assume we can only handle a hash.
|
15
|
+
def self.open_uri name, options = {}
|
16
|
+
value = options.delete :allow_unsafe_redirects
|
17
|
+
if value
|
18
|
+
class <<self
|
19
|
+
remove_method :redirectable?
|
20
|
+
alias_method :redirectable?, :redirectable_baller?
|
21
|
+
end
|
22
|
+
else
|
23
|
+
class <<self
|
24
|
+
remove_method :redirectable?
|
25
|
+
alias_method :redirectable?, :redirectable_cautious?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
self.open_uri_original name, options
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Nesta
|
2
|
+
module Plugin
|
3
|
+
module Drop
|
4
|
+
module Routes
|
5
|
+
def included(app)
|
6
|
+
app.post "/nestadrop" do
|
7
|
+
if !nestadrop_request?
|
8
|
+
status 404
|
9
|
+
else
|
10
|
+
if params["file"]
|
11
|
+
Thread.new do
|
12
|
+
Nesta::Plugin::Drop::Client.cache_file(params["file"])
|
13
|
+
end
|
14
|
+
else
|
15
|
+
Thread.new do
|
16
|
+
Nesta::Plugin::Drop::Client.cache_files
|
17
|
+
end
|
18
|
+
end
|
19
|
+
status 200
|
20
|
+
""
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
app.delete "/nestadrop" do
|
25
|
+
if !nestadrop_request?
|
26
|
+
status 404
|
27
|
+
else
|
28
|
+
if params["file"]
|
29
|
+
Thread.new do
|
30
|
+
Nesta::Plugin::Drop::Client.remove_file(params["file"])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
status 200
|
34
|
+
""
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -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 'nesta-plugin-drop/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "nesta-plugin-drop"
|
8
|
+
spec.version = Nesta::Plugin::Drop::VERSION
|
9
|
+
spec.authors = ["Glenn Gillen"]
|
10
|
+
spec.email = ["me@glenngillen.com"]
|
11
|
+
spec.summary = %q{NestaCMS and Dropbox integration.}
|
12
|
+
spec.description = %q{Allows you to sync web content on Dropbox with a Ruby-based CMS}
|
13
|
+
spec.homepage = "https://nestadrop.io/"
|
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_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_runtime_dependency 'nesta', '>= 0.10.0'
|
24
|
+
spec.add_runtime_dependency 'rest-client'
|
25
|
+
spec.add_runtime_dependency 'yajl-ruby'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nesta-plugin-drop
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Glenn Gillen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-13 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: nesta
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.10.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.10.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rest-client
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yajl-ruby
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Allows you to sync web content on Dropbox with a Ruby-based CMS
|
84
|
+
email:
|
85
|
+
- me@glenngillen.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- lib/nesta-plugin-drop.rb
|
96
|
+
- lib/nesta-plugin-drop/app.rb
|
97
|
+
- lib/nesta-plugin-drop/client.rb
|
98
|
+
- lib/nesta-plugin-drop/helpers.rb
|
99
|
+
- lib/nesta-plugin-drop/init.rb
|
100
|
+
- lib/nesta-plugin-drop/openuri_monkeypatch.rb
|
101
|
+
- lib/nesta-plugin-drop/routes.rb
|
102
|
+
- lib/nesta-plugin-drop/version.rb
|
103
|
+
- nesta-plugin-drop.gemspec
|
104
|
+
homepage: https://nestadrop.io/
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.2.2
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: NestaCMS and Dropbox integration.
|
128
|
+
test_files: []
|