nightcrawler_swift 0.3.0 → 0.4.0
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 +4 -4
- data/Changelog.md +11 -0
- data/Gemfile.lock +1 -1
- data/README.md +40 -25
- data/bin/nswift +8 -0
- data/lib/nightcrawler_swift/cli.rb +208 -0
- data/lib/nightcrawler_swift/command.rb +12 -2
- data/lib/nightcrawler_swift/{delete.rb → commands/delete.rb} +1 -1
- data/lib/nightcrawler_swift/{download.rb → commands/download.rb} +1 -1
- data/lib/nightcrawler_swift/{list.rb → commands/list.rb} +0 -0
- data/lib/nightcrawler_swift/{sync.rb → commands/sync.rb} +2 -2
- data/lib/nightcrawler_swift/commands/upload.rb +25 -0
- data/lib/nightcrawler_swift/connection.rb +44 -23
- data/lib/nightcrawler_swift/exceptions.rb +1 -0
- data/lib/nightcrawler_swift/tasks/asset_sync.rake +7 -1
- data/lib/nightcrawler_swift/version.rb +1 -1
- data/lib/nightcrawler_swift.rb +26 -9
- data/spec/fixtures/auth_success.json +6 -6
- data/spec/lib/nightcrawler_swift/cli_spec.rb +293 -0
- data/spec/lib/nightcrawler_swift/command_spec.rb +55 -14
- data/spec/lib/nightcrawler_swift/{delete_spec.rb → commands/delete_spec.rb} +15 -8
- data/spec/lib/nightcrawler_swift/{download_spec.rb → commands/download_spec.rb} +16 -7
- data/spec/lib/nightcrawler_swift/{list_spec.rb → commands/list_spec.rb} +12 -8
- data/spec/lib/nightcrawler_swift/{sync_spec.rb → commands/sync_spec.rb} +10 -1
- data/spec/lib/nightcrawler_swift/{upload_spec.rb → commands/upload_spec.rb} +23 -8
- data/spec/lib/nightcrawler_swift/connection_spec.rb +32 -20
- data/spec/lib/nightcrawler_swift/tasks/asset_sync_spec.rb +19 -3
- data/spec/lib/nightcrawler_swift_spec.rb +46 -15
- metadata +23 -18
- data/lib/nightcrawler_swift/upload.rb +0 -17
@@ -22,8 +22,8 @@ describe "asset_sync.rake" do
|
|
22
22
|
Rake::Task.define_task("assets:precompile")
|
23
23
|
end
|
24
24
|
|
25
|
-
describe "nightcrawler_swift:rails:
|
26
|
-
let(:task_name) { "nightcrawler_swift:rails:
|
25
|
+
describe "nightcrawler_swift:rails:sync" do
|
26
|
+
let(:task_name) { "nightcrawler_swift:rails:sync" }
|
27
27
|
subject { rake[task_name] }
|
28
28
|
|
29
29
|
before do
|
@@ -32,7 +32,6 @@ describe "asset_sync.rake" do
|
|
32
32
|
|
33
33
|
it "requires environment and assets:precompile" do
|
34
34
|
expect(subject.prerequisites).to include "environment"
|
35
|
-
expect(subject.prerequisites).to include "assets:precompile"
|
36
35
|
end
|
37
36
|
|
38
37
|
it "calls sync with Rails public dir path" do
|
@@ -56,4 +55,21 @@ describe "asset_sync.rake" do
|
|
56
55
|
end
|
57
56
|
end
|
58
57
|
end
|
58
|
+
|
59
|
+
describe "nightcrawler_swift:rails:asset_sync" do
|
60
|
+
let(:task_name) { "nightcrawler_swift:rails:asset_sync" }
|
61
|
+
subject { rake[task_name] }
|
62
|
+
|
63
|
+
it "calls 'assets:precompile' and 'nightcrawler_swift:rails:sync'" do
|
64
|
+
task1 = double("task1", invoke: true)
|
65
|
+
task2 = double("task2", invoke: true)
|
66
|
+
|
67
|
+
expect(Rake::Task).to receive(:[]).with("assets:precompile").and_return(task1)
|
68
|
+
expect(Rake::Task).to receive(:[]).with("nightcrawler_swift:rails:sync").and_return(task2)
|
69
|
+
expect(task1).to receive(:invoke)
|
70
|
+
expect(task2).to receive(:invoke)
|
71
|
+
|
72
|
+
subject.invoke
|
73
|
+
end
|
74
|
+
end
|
59
75
|
end
|
@@ -2,6 +2,9 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe NightcrawlerSwift do
|
4
4
|
|
5
|
+
let(:opts) { {bucket: "rogue"} }
|
6
|
+
let(:options) { OpenStruct.new(opts) }
|
7
|
+
|
5
8
|
subject do
|
6
9
|
NightcrawlerSwift
|
7
10
|
end
|
@@ -11,9 +14,12 @@ describe NightcrawlerSwift do
|
|
11
14
|
subject.logger = nil
|
12
15
|
end
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
context "when not configured" do
|
18
|
+
it "returns an instance of Logger with INFO level" do
|
19
|
+
expect(Logger).to receive(:new).with(STDOUT).and_call_original
|
20
|
+
subject.logger
|
21
|
+
expect(subject.logger.level).to eql(Logger::INFO)
|
22
|
+
end
|
17
23
|
end
|
18
24
|
|
19
25
|
it "returns the configured logger" do
|
@@ -24,23 +30,55 @@ describe NightcrawlerSwift do
|
|
24
30
|
end
|
25
31
|
|
26
32
|
describe "::configure" do
|
27
|
-
it "creates
|
28
|
-
opts
|
29
|
-
expect(
|
33
|
+
it "creates the options struct with the given values" do
|
34
|
+
subject.configure opts
|
35
|
+
expect(subject.options).to_not be_nil
|
36
|
+
opts.keys.each do |key|
|
37
|
+
expect(subject.options.send(key)).to eql(opts[key])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it "creates a new connection" do
|
42
|
+
expect(NightcrawlerSwift::Connection).to receive(:new).and_call_original
|
30
43
|
subject.configure opts
|
31
44
|
expect(subject.connection).to_not be_nil
|
32
45
|
end
|
46
|
+
|
47
|
+
context "verify_ssl" do
|
48
|
+
it "defauts to false" do
|
49
|
+
expect(subject.options.verify_ssl).to eql false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "and max_age isn't an integer" do
|
54
|
+
let(:opts) { {max_age: "a string"} }
|
55
|
+
|
56
|
+
it "raises NightcrawlerSwift::Exceptions::ConfigurationError" do
|
57
|
+
expect { subject.configure(opts) }.to raise_error(NightcrawlerSwift::Exceptions::ConfigurationError)
|
58
|
+
end
|
59
|
+
end
|
33
60
|
end
|
34
61
|
|
35
62
|
describe "::connection" do
|
36
63
|
it "returns the configured connection" do
|
37
64
|
connection = NightcrawlerSwift::Connection.new
|
38
|
-
expect(NightcrawlerSwift::Connection).to receive(:new).
|
39
|
-
NightcrawlerSwift.configure
|
65
|
+
expect(NightcrawlerSwift::Connection).to receive(:new).and_return(connection)
|
66
|
+
NightcrawlerSwift.configure opts
|
40
67
|
expect(NightcrawlerSwift.connection).to eql(connection)
|
41
68
|
end
|
42
69
|
end
|
43
70
|
|
71
|
+
describe "::options" do
|
72
|
+
before do
|
73
|
+
allow(NightcrawlerSwift::Connection).to receive(:new)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "returns the given options" do
|
77
|
+
NightcrawlerSwift.configure(opts)
|
78
|
+
expect(NightcrawlerSwift.options).to eql(OpenStruct.new(opts.merge(verify_ssl: false)))
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
44
82
|
describe "::sync" do
|
45
83
|
let :dir_path do
|
46
84
|
"path"
|
@@ -54,14 +92,7 @@ describe NightcrawlerSwift do
|
|
54
92
|
NightcrawlerSwift.configure
|
55
93
|
end
|
56
94
|
|
57
|
-
it "connects" do
|
58
|
-
allow(NightcrawlerSwift::Sync).to receive(:new).and_return(sync_instance)
|
59
|
-
expect(NightcrawlerSwift.connection).to receive(:connect!)
|
60
|
-
NightcrawlerSwift.sync dir_path
|
61
|
-
end
|
62
|
-
|
63
95
|
it "uses Sync command with the given dir_path" do
|
64
|
-
expect(NightcrawlerSwift.connection).to receive(:connect!)
|
65
96
|
expect(NightcrawlerSwift::Sync).to receive(:new).and_return(sync_instance)
|
66
97
|
expect(sync_instance).to receive(:execute).with(dir_path)
|
67
98
|
NightcrawlerSwift.sync dir_path
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nightcrawler_swift
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tulios
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-09-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -100,7 +100,8 @@ description: Like the X-Men nightcrawler this gem teleports your assets to a Ope
|
|
100
100
|
email:
|
101
101
|
- ornelas.tulio@gmail.com
|
102
102
|
- roberto.tech@gmail.com
|
103
|
-
executables:
|
103
|
+
executables:
|
104
|
+
- nswift
|
104
105
|
extensions: []
|
105
106
|
extra_rdoc_files: []
|
106
107
|
files:
|
@@ -115,17 +116,19 @@ files:
|
|
115
116
|
- LICENSE.txt
|
116
117
|
- README.md
|
117
118
|
- Rakefile
|
119
|
+
- bin/nswift
|
118
120
|
- lib/nightcrawler_swift.rb
|
121
|
+
- lib/nightcrawler_swift/cli.rb
|
119
122
|
- lib/nightcrawler_swift/command.rb
|
123
|
+
- lib/nightcrawler_swift/commands/delete.rb
|
124
|
+
- lib/nightcrawler_swift/commands/download.rb
|
125
|
+
- lib/nightcrawler_swift/commands/list.rb
|
126
|
+
- lib/nightcrawler_swift/commands/sync.rb
|
127
|
+
- lib/nightcrawler_swift/commands/upload.rb
|
120
128
|
- lib/nightcrawler_swift/connection.rb
|
121
|
-
- lib/nightcrawler_swift/delete.rb
|
122
|
-
- lib/nightcrawler_swift/download.rb
|
123
129
|
- lib/nightcrawler_swift/exceptions.rb
|
124
|
-
- lib/nightcrawler_swift/list.rb
|
125
130
|
- lib/nightcrawler_swift/railtie.rb
|
126
|
-
- lib/nightcrawler_swift/sync.rb
|
127
131
|
- lib/nightcrawler_swift/tasks/asset_sync.rake
|
128
|
-
- lib/nightcrawler_swift/upload.rb
|
129
132
|
- lib/nightcrawler_swift/version.rb
|
130
133
|
- nightcrawler_swift.gemspec
|
131
134
|
- spec/fixtures/assets/css1.css
|
@@ -134,14 +137,15 @@ files:
|
|
134
137
|
- spec/fixtures/assets/ex3/ex4.txt
|
135
138
|
- spec/fixtures/assets/js1.js
|
136
139
|
- spec/fixtures/auth_success.json
|
140
|
+
- spec/lib/nightcrawler_swift/cli_spec.rb
|
137
141
|
- spec/lib/nightcrawler_swift/command_spec.rb
|
142
|
+
- spec/lib/nightcrawler_swift/commands/delete_spec.rb
|
143
|
+
- spec/lib/nightcrawler_swift/commands/download_spec.rb
|
144
|
+
- spec/lib/nightcrawler_swift/commands/list_spec.rb
|
145
|
+
- spec/lib/nightcrawler_swift/commands/sync_spec.rb
|
146
|
+
- spec/lib/nightcrawler_swift/commands/upload_spec.rb
|
138
147
|
- spec/lib/nightcrawler_swift/connection_spec.rb
|
139
|
-
- spec/lib/nightcrawler_swift/delete_spec.rb
|
140
|
-
- spec/lib/nightcrawler_swift/download_spec.rb
|
141
|
-
- spec/lib/nightcrawler_swift/list_spec.rb
|
142
|
-
- spec/lib/nightcrawler_swift/sync_spec.rb
|
143
148
|
- spec/lib/nightcrawler_swift/tasks/asset_sync_spec.rb
|
144
|
-
- spec/lib/nightcrawler_swift/upload_spec.rb
|
145
149
|
- spec/lib/nightcrawler_swift_spec.rb
|
146
150
|
- spec/spec_helper.rb
|
147
151
|
homepage: https://github.com/tulios/nightcrawler_swift
|
@@ -176,13 +180,14 @@ test_files:
|
|
176
180
|
- spec/fixtures/assets/ex3/ex4.txt
|
177
181
|
- spec/fixtures/assets/js1.js
|
178
182
|
- spec/fixtures/auth_success.json
|
183
|
+
- spec/lib/nightcrawler_swift/cli_spec.rb
|
179
184
|
- spec/lib/nightcrawler_swift/command_spec.rb
|
185
|
+
- spec/lib/nightcrawler_swift/commands/delete_spec.rb
|
186
|
+
- spec/lib/nightcrawler_swift/commands/download_spec.rb
|
187
|
+
- spec/lib/nightcrawler_swift/commands/list_spec.rb
|
188
|
+
- spec/lib/nightcrawler_swift/commands/sync_spec.rb
|
189
|
+
- spec/lib/nightcrawler_swift/commands/upload_spec.rb
|
180
190
|
- spec/lib/nightcrawler_swift/connection_spec.rb
|
181
|
-
- spec/lib/nightcrawler_swift/delete_spec.rb
|
182
|
-
- spec/lib/nightcrawler_swift/download_spec.rb
|
183
|
-
- spec/lib/nightcrawler_swift/list_spec.rb
|
184
|
-
- spec/lib/nightcrawler_swift/sync_spec.rb
|
185
191
|
- spec/lib/nightcrawler_swift/tasks/asset_sync_spec.rb
|
186
|
-
- spec/lib/nightcrawler_swift/upload_spec.rb
|
187
192
|
- spec/lib/nightcrawler_swift_spec.rb
|
188
193
|
- spec/spec_helper.rb
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'digest'
|
2
|
-
|
3
|
-
module NightcrawlerSwift
|
4
|
-
class Upload < Command
|
5
|
-
|
6
|
-
def execute path, file
|
7
|
-
content_type = MultiMime.by_file(file).content_type
|
8
|
-
content = file.read
|
9
|
-
etag = '"%s"' % Digest::MD5.new.update(content).hexdigest
|
10
|
-
headers = {etag: etag, content_type: content_type}
|
11
|
-
headers.merge!({cache_control: "max-age=#{connection.opts.max_age}"}) if connection.opts.max_age
|
12
|
-
response = put "#{connection.upload_url}/#{path}", body: content, headers: headers
|
13
|
-
[200, 201].include?(response.code)
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|