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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90351edd9bc9e92242bf093a853d0ee2c9a2f2dc7bd5c6d5f9d4a11f966c7082
4
- data.tar.gz: f244abd20dafe43ea6e1c259637ce6d8182d6595997e7148dc4e313128fafbf5
3
+ metadata.gz: 006350eee9b61b446739d43bb95ade334a923b1580d8b979af6649835c4c0194
4
+ data.tar.gz: e3ee2264a88ff6d7b1992207ecb5b7a7d40fde199fabe1d001f701c91d22d70c
5
5
  SHA512:
6
- metadata.gz: f8062646a787ed2d5fdd7b7d1ffe4ccd359f3dc4fed0f43f8210bae0c7d20dbcaa9cb552cb44b7a26a4160a9729d9dbf140276c8adf39f42f74c022f9ece3cc8
7
- data.tar.gz: af4f4d63cb24311935f3fcb273b294c61597624ed15dca8def02ebffade49e618d549169bc0708421d005dca1fcebb9c58c7acd8da7e0f7ade326cee8ab8dbe1
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.post('/b2api/v1/b2_list_buckets', {accountId: @account_id})['buckets'].map do |b|
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, expires_in: 3_600)
90
- response = @connection.post("/b2api/v1/b2_get_download_authorization", {
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)
@@ -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
@@ -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)
@@ -1,3 +1,3 @@
1
1
  class B2
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
3
3
  end
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.3
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-08 00:00:00.000000000 Z
11
+ date: 2018-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake