nesta-plugin-drop 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nesta-plugin-drop/app.rb +1 -0
- data/lib/nesta-plugin-drop/client.rb +11 -2
- data/lib/nesta-plugin-drop/helpers.rb +5 -0
- data/lib/nesta-plugin-drop/logger.rb +21 -0
- data/lib/nesta-plugin-drop/version.rb +1 -1
- data/nesta-plugin-drop.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e8b7961a0cddf63a2411dbc964ffff5e1dcc8dd
|
4
|
+
data.tar.gz: d40d0f0e380e50c23439d0262175aba35a39ca55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02a6c1bd54d946dfce9c14add2a76358c77dc39c486fe3aaa5681cac417ddac9a2cfe838fdc3a35ccbdc2ea7ae3ef54f24cd5f9dff87a487c28b6e4d9eda227b
|
7
|
+
data.tar.gz: 35f5e85fc3dc396c3b381bc3341d1bc7ec00c952661a00e15dbfa6dd947a5d675711b7aa7ce20b8f7054ed430342816da23542a3100525181eb126c2b79dba51
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
require 'rest_client'
|
3
3
|
require 'yajl'
|
4
|
+
require 'nesta-plugin-drop/logger'
|
4
5
|
module Nesta
|
5
6
|
module Plugin
|
6
7
|
module Drop
|
@@ -19,6 +20,7 @@ module Nesta
|
|
19
20
|
|
20
21
|
def self.confirm_synced!
|
21
22
|
return true if nestadrop_synced?
|
23
|
+
Nesta::Plugin::Drop.logger.debug "NESTADROP: Syncing with Dropbox filesystem."
|
22
24
|
File.open("/tmp/.nestadropped", "w+") do |f|
|
23
25
|
f.write "synced"
|
24
26
|
end
|
@@ -36,6 +38,7 @@ module Nesta
|
|
36
38
|
|
37
39
|
def self.nestadrop_configured?
|
38
40
|
return true if nestadrop_synced?
|
41
|
+
Nesta::Plugin::Drop.logger.debug "NESTADROP: Checking if account is linked to Dropbox."
|
39
42
|
json = RestClient.get "#{host}account", {
|
40
43
|
accept: :json, x_nestadrop_version: Nesta::Plugin::Drop::VERSION }
|
41
44
|
account = Yajl::Parser.parse json
|
@@ -44,12 +47,13 @@ module Nesta
|
|
44
47
|
|
45
48
|
def self.bounce_server!
|
46
49
|
return if syncing?
|
47
|
-
|
50
|
+
Nesta::Plugin::Drop.logger.info "NESTADROP: Restarting server..."
|
48
51
|
system("bundle exec pumactl -S /tmp/.app_state phased-restart")
|
49
52
|
end
|
50
53
|
|
51
54
|
def self.files
|
52
55
|
lock.synchronize do
|
56
|
+
Nesta::Plugin::Drop.logger.debug "NESTADROP: Retrieving file list..."
|
53
57
|
@files ||= Yajl::Parser.parse(RestClient.get "#{host}files", {
|
54
58
|
accept: :json, x_nestadrop_version: Nesta::Plugin::Drop::VERSION })
|
55
59
|
end
|
@@ -72,12 +76,13 @@ module Nesta
|
|
72
76
|
def self.cache_file(file)
|
73
77
|
confirm_synced!
|
74
78
|
local_path = [Nesta::App.root, file].join("/")
|
75
|
-
|
79
|
+
Nesta::Plugin::Drop.logger.debug "NESTADROP: Caching '#{file}' to local filesystem at '#{local_path}'..."
|
76
80
|
FileUtils.mkdir_p(File.dirname(local_path))
|
77
81
|
file_contents = RestClient.get "#{host}file?file=#{URI.encode(file)}"
|
78
82
|
File.open(local_path, 'w') do |fo|
|
79
83
|
fo.write file_contents
|
80
84
|
end
|
85
|
+
Nesta::Plugin::Drop.logger.debug "NESTADROP: Cached '#{local_path}'."
|
81
86
|
bounce_server!
|
82
87
|
rescue RuntimeError => ex
|
83
88
|
puts ex
|
@@ -90,12 +95,14 @@ module Nesta
|
|
90
95
|
threads = []
|
91
96
|
5.times do
|
92
97
|
threads << Thread.new do
|
98
|
+
Nesta::Plugin::Drop.logger.debug "NESTADROP: Creating worker thread to cache files..."
|
93
99
|
file = nil
|
94
100
|
lock.synchronize do
|
95
101
|
file = self.uncached_files.pop
|
96
102
|
end
|
97
103
|
cache_file(file) if file
|
98
104
|
end
|
105
|
+
Nesta::Plugin::Drop.logger.debug "NESTADROP: Worker thread complete."
|
99
106
|
end
|
100
107
|
threads.each(&:join)
|
101
108
|
@syncing = false
|
@@ -104,11 +111,13 @@ module Nesta
|
|
104
111
|
|
105
112
|
def self.remove_file(file)
|
106
113
|
local_path = [Nesta::App.root, file].join("/")
|
114
|
+
Nesta::Plugin::Drop.logger.debug "NESTADROP: Removing locally cached file at '#{local_path}'."
|
107
115
|
FileUtils.rm_r(File.dirname(local_path), secure: true)
|
108
116
|
bounce_server!
|
109
117
|
end
|
110
118
|
|
111
119
|
def self.bootstrap!
|
120
|
+
Nesta::Plugin::Drop.logger.debug "NESTADROP: Bootstrapping local instance..."
|
112
121
|
unless nestadrop_synced?
|
113
122
|
cache_files
|
114
123
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'nesta-plugin-drop/logger'
|
1
2
|
module Nesta
|
2
3
|
module Plugin
|
3
4
|
module Drop
|
@@ -7,6 +8,7 @@ module Nesta
|
|
7
8
|
end
|
8
9
|
|
9
10
|
def setup_nestadrop
|
11
|
+
Nesta::Plugin::Drop.logger.debug "NESTADROP: Redirecting to nestadrop.io to complete account setup."
|
10
12
|
redirect to("#{Nesta::Plugin::Drop::Client.host}account/setup?domain=#{request.host}")
|
11
13
|
end
|
12
14
|
|
@@ -16,11 +18,14 @@ module Nesta
|
|
16
18
|
end
|
17
19
|
|
18
20
|
def nestadrop_request?
|
21
|
+
Nesta::Plugin::Drop.logger.debug "NESTADROP: Authenticating Dropbox webhook request..."
|
19
22
|
expected_user, expected_pass = Client.userinfo
|
20
23
|
auth = Rack::Auth::Basic::Request.new(request.env)
|
21
24
|
if auth.provided? && auth.basic? && auth.credentials == [expected_user, expected_pass]
|
25
|
+
Nesta::Plugin::Drop.logger.debug "NESTADROP: Authenticated."
|
22
26
|
return true
|
23
27
|
else
|
28
|
+
Nesta::Plugin::Drop.logger.debug "NESTADROP: Authentication failed."
|
24
29
|
return false
|
25
30
|
end
|
26
31
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'logger'
|
2
|
+
module Nesta
|
3
|
+
module Plugin
|
4
|
+
module Drop
|
5
|
+
def self.logger
|
6
|
+
return @logger if @logger
|
7
|
+
@logger = Logger.new(STDOUT)
|
8
|
+
@logger.level = Logger::WARN
|
9
|
+
if level = ENV["NESTADROP_LOG_LEVEL"]
|
10
|
+
levels = ["FATAL", "ERROR", "WARN", "INFO", "DEBUG"]
|
11
|
+
if levels.include? level.upcase
|
12
|
+
@logger.level = Logger.const_get(level.upcase.to_sym)
|
13
|
+
else
|
14
|
+
@logger.warn "Log level '#{level.upcase}' is unknown. Supported levels are: #{levels.join(", ")}."
|
15
|
+
end
|
16
|
+
end
|
17
|
+
@logger
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/nesta-plugin-drop.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.6"
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
spec.add_runtime_dependency 'nesta', '>= 0.10.0'
|
24
|
+
spec.add_runtime_dependency 'redcarpet', '~> 3.2.2'
|
24
25
|
spec.add_runtime_dependency 'rest-client'
|
25
26
|
spec.add_runtime_dependency 'yajl-ruby'
|
26
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nesta-plugin-drop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Glenn Gillen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.10.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: redcarpet
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.2.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.2.2
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rest-client
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -97,6 +111,7 @@ files:
|
|
97
111
|
- lib/nesta-plugin-drop/client.rb
|
98
112
|
- lib/nesta-plugin-drop/helpers.rb
|
99
113
|
- lib/nesta-plugin-drop/init.rb
|
114
|
+
- lib/nesta-plugin-drop/logger.rb
|
100
115
|
- lib/nesta-plugin-drop/openuri_monkeypatch.rb
|
101
116
|
- lib/nesta-plugin-drop/routes.rb
|
102
117
|
- lib/nesta-plugin-drop/version.rb
|