b2-client 1.0.3 → 1.0.4
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/lib/b2.rb +5 -21
- data/lib/b2/bucket.rb +4 -0
- data/lib/b2/connection.rb +24 -0
- data/lib/b2/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 006350eee9b61b446739d43bb95ade334a923b1580d8b979af6649835c4c0194
|
4
|
+
data.tar.gz: e3ee2264a88ff6d7b1992207ecb5b7a7d40fde199fabe1d001f701c91d22d70c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 287e941dec6ed6c401aae3a8980e95c9ee3ab49d887d3741113ad45724442f3278173c4ecfd07f4359bd133d0210ca404de2790e9ba717b0f5986987934be806
|
7
|
+
data.tar.gz: cc66419b6b343872265126c4edc2551d5c837475401a5bb082f574bfa374f2deb75789bef334246830fa58bfa29b25f6129440309bf43373b66d1092ce8c606b
|
data/lib/b2.rb
CHANGED
@@ -13,25 +13,14 @@ class B2
|
|
13
13
|
def initialize(account_id:, application_key:)
|
14
14
|
@account_id = account_id
|
15
15
|
@connection = B2::Connection.new(account_id, application_key)
|
16
|
-
@buckets_cache = []
|
17
16
|
end
|
18
17
|
|
19
18
|
def buckets
|
20
|
-
@connection.
|
21
|
-
B2::Bucket.new(b, @connection)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def lookup_bucket_id(name)
|
26
|
-
bucket = @buckets_cache.find{ |b| b.name == name }
|
27
|
-
return bucket.id if bucket
|
28
|
-
|
29
|
-
@buckets_cache = buckets
|
30
|
-
@buckets_cache.find{ |b| b.name == name }&.id
|
19
|
+
@connection.buckets
|
31
20
|
end
|
32
21
|
|
33
22
|
def file(bucket, key)
|
34
|
-
bucket_id = lookup_bucket_id(bucket)
|
23
|
+
bucket_id = @connection.lookup_bucket_id(bucket)
|
35
24
|
|
36
25
|
file = @connection.post('/b2api/v1/b2_list_file_names', {
|
37
26
|
bucketId: bucket_id,
|
@@ -55,7 +44,7 @@ class B2
|
|
55
44
|
|
56
45
|
def get_upload_token(bucket)
|
57
46
|
@connection.post("/b2api/v1/b2_get_upload_url", {
|
58
|
-
bucketId: lookup_bucket_id(bucket)
|
47
|
+
bucketId: @connection.lookup_bucket_id(bucket)
|
59
48
|
})
|
60
49
|
end
|
61
50
|
|
@@ -86,13 +75,8 @@ class B2
|
|
86
75
|
end
|
87
76
|
end
|
88
77
|
|
89
|
-
def get_download_url(bucket, filename,
|
90
|
-
|
91
|
-
bucketId: lookup_bucket_id(bucket),
|
92
|
-
fileNamePrefix: filename,
|
93
|
-
validDurationInSeconds: expires_in
|
94
|
-
})
|
95
|
-
@connection.download_url + '/file/' + bucket + '/' + filename + "?Authorization=" + response['authorizationToken']
|
78
|
+
def get_download_url(bucket, filename, **options)
|
79
|
+
@connection.get_download_url(bucket, filename, **options)
|
96
80
|
end
|
97
81
|
|
98
82
|
def download(bucket, key, to=nil, &block)
|
data/lib/b2/bucket.rb
CHANGED
@@ -67,6 +67,10 @@ class B2
|
|
67
67
|
file ? B2::File.new(file.merge({'bucketId' => @id}), @connection) : nil
|
68
68
|
end
|
69
69
|
|
70
|
+
def get_download_url(key, **options)
|
71
|
+
@connection.get_download_url(@name, key, **options)
|
72
|
+
end
|
73
|
+
|
70
74
|
def download(key, to=nil, &block)
|
71
75
|
@connection.download(@name, key, to, &block)
|
72
76
|
end
|
data/lib/b2/connection.rb
CHANGED
@@ -33,6 +33,7 @@ class B2
|
|
33
33
|
@recommended_part_size = resp['recommendedPartSize']
|
34
34
|
@auth_token = resp['authorizationToken']
|
35
35
|
@download_url = resp['downloadUrl']
|
36
|
+
@buckets_cache = []
|
36
37
|
end
|
37
38
|
|
38
39
|
def disconnect!
|
@@ -82,7 +83,30 @@ class B2
|
|
82
83
|
|
83
84
|
return_value
|
84
85
|
end
|
86
|
+
|
87
|
+
def buckets
|
88
|
+
post('/b2api/v1/b2_list_buckets', {accountId: @account_id})['buckets'].map do |b|
|
89
|
+
B2::Bucket.new(b, self)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def lookup_bucket_id(name)
|
94
|
+
bucket = @buckets_cache.find{ |b| b.name == name }
|
95
|
+
return bucket.id if bucket
|
85
96
|
|
97
|
+
@buckets_cache = buckets
|
98
|
+
@buckets_cache.find{ |b| b.name == name }&.id
|
99
|
+
end
|
100
|
+
|
101
|
+
def get_download_url(bucket, filename, expires_in: 3_600)
|
102
|
+
response = post("/b2api/v1/b2_get_download_authorization", {
|
103
|
+
bucketId: lookup_bucket_id(bucket),
|
104
|
+
fileNamePrefix: filename,
|
105
|
+
validDurationInSeconds: expires_in
|
106
|
+
})
|
107
|
+
@download_url + '/file/' + bucket + '/' + filename + "?Authorization=" + response['authorizationToken']
|
108
|
+
end
|
109
|
+
|
86
110
|
def download(bucket, key, to=nil, &block)
|
87
111
|
opened_file = (to && to.is_a?(String))
|
88
112
|
to = ::File.open(to, 'wb') if to.is_a?(String)
|
data/lib/b2/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: b2-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Bracy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|