-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
example.rb
69 lines (53 loc) · 1.54 KB
/
example.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require 'logger'
require 'pp'
$:.push(File.expand_path("../../lib", __FILE__))
require_relative "../lib/fog/backblaze"
if !ENV['B2_ACCOUNT_ID'] || ENV['B2_ACCOUNT_ID'] == ""
puts "Missing env B2_ACCOUNT_ID"
exit 1
end
if !ENV['B2_ACCOUNT_TOKEN'] || ENV['B2_ACCOUNT_TOKEN'] == ""
puts "Missing env B2_ACCOUNT_TOKEN"
exit 1
end
connection = Fog::Storage.new(
provider: 'backblaze',
b2_account_id: ENV['B2_ACCOUNT_ID'],
b2_account_token: ENV['B2_ACCOUNT_TOKEN'],
#b2_bucket_name: ENV['B2_BUCKET'],
#b2_bucket_id: '111222333444',
logger: ENV['DEBUG'] ? Logger.new(STDOUT) : nil
)
connection.delete_bucket("fog-smoke-test") rescue nil
puts "Put a bucket..."
puts "----------------"
pp connection.put_bucket("fog-smoke-test", public: true).json
puts
puts "Get the bucket..."
puts "-----------------"
pp connection.get_bucket("fog-smoke-test").json
puts
puts "Put a test file..."
puts "---------------"
pp connection.put_object("fog-smoke-test", "my file", "THISISATESTFILE").json
puts
puts "Get the test file..."
puts "---------------"
p connection.get_object("fog-smoke-test", "my file")
puts
puts "Head file..."
puts "---------------"
pp connection.head_object("fog-smoke-test", "my file").headers
puts
puts "Object URL..."
puts "---------------"
p connection.get_object_url("fog-smoke-test", "my file")
puts
puts "Delete the test file..."
puts "---------------"
pp connection.delete_object("fog-smoke-test", "my file").json
puts
puts "Delete the bucket..."
puts "------------------"
pp connection.delete_bucket("fog-smoke-test").json
puts