bkblz 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a78f7af9b064373a818c24c9f74c5402a153317f
4
- data.tar.gz: 76c95a222b762d6b741313849c92be7162546aa8
3
+ metadata.gz: 276cd7b864f9a13fd8a32ea5839514f041afbd02
4
+ data.tar.gz: c87c7242a87241a7b6e48f3bef5aab55117ef37b
5
5
  SHA512:
6
- metadata.gz: '028ede1e92325f7808d1dc3769f8c29b9ac4017bd50ff26205e90bcb6cb6ed288e3f13765f2f11262c5d7a58700b4782fef4f7a9ea0f4d37e56fb1941bf5c3ff'
7
- data.tar.gz: 9ba3b10ead315fced6c2ab188fa75db3544bfe2da810f662955f0583c285cd33efa10d2138d8bb9cac5f6df07aee9414257fb8f3655dd8a5eac6a5faab4c56a5
6
+ metadata.gz: 5ac0e9aa47318c48169be640350dede4d116d83b15980520b99289e19ea9b1ae7a2ae79c5a24a8e3c0e92f3dc7733e311888630b099ff150705a293a77715d10
7
+ data.tar.gz: 53ac8463bd04b6a747f853837f825a6cb1908c1c55cefa837c472e0a83f575f12933969ed540ffb40fa9aad7c7d6a8f64f9553eca91ae4e3330c4366087c9956
data/bin/bkblz CHANGED
@@ -127,6 +127,25 @@ module Bkblz
127
127
  print_model file_info
128
128
  end
129
129
 
130
+ desc "downloadbyname <bucket> <name> <dir>", "downloads file by <bucket> " +
131
+ "and <name> to directory <dir>"
132
+ def downloadbyname(bucket_name, file_name, dir_path)
133
+ parse_opts
134
+
135
+ file_info = run_task do
136
+ Bkblz::Task::DownloadFile.run Bkblz.config, {
137
+ :file_name => file_name,
138
+ :bucket_name => bucket_name,
139
+ :dir_path => dir_path,
140
+ :use_filename => true
141
+ }
142
+ end
143
+
144
+ print_header "File Info"
145
+ print_model file_info
146
+ end
147
+
148
+ # TODO(erick): Rename to downloadbyid
130
149
  desc "download <id> <dir>", "downloads file <id> to directory <dir>"
131
150
  def download(file_id, dir_path)
132
151
  parse_opts
@@ -134,7 +153,8 @@ module Bkblz
134
153
  file_info = run_task do
135
154
  Bkblz::Task::DownloadFile.run Bkblz.config, {
136
155
  :file_id => file_id,
137
- :dir_path => dir_path
156
+ :dir_path => dir_path,
157
+ :use_filename => options[:by_name]
138
158
  }
139
159
  end
140
160
 
@@ -4,14 +4,22 @@ module Bkblz
4
4
  module Task
5
5
  class DownloadFile < BaseTask
6
6
 
7
- task_param :file_id, :required => true
8
7
  task_param :dir_path, :required => true
9
8
 
9
+ # for downalod by id
10
+ task_param :file_id
11
+
12
+ # for download by name
13
+ task_param :bucket_name
14
+ task_param :file_name
15
+ task_param :use_filename
16
+
10
17
  def run_internal(session, params)
11
- partial_file_info =
12
- Bkblz::V1::Model::PartialFileInfo.new :file_id => params[:file_id]
13
- download_file_info = session.send(
14
- Bkblz::V1::DownloadFileByIdRequest.new partial_file_info).to_model
18
+ download_file_info = if params[:use_filename]
19
+ download_by_name(session, params)
20
+ else
21
+ download_by_id(session, params)
22
+ end
15
23
 
16
24
  unless download_file_info.sha1 == Digest::SHA1.hexdigest(download_file_info.body)
17
25
  raise "invalid checksum"
@@ -37,6 +45,25 @@ module Bkblz
37
45
  map[:body] = "<omitted>"
38
46
  Bkblz::V1::Model::FileDownload.new map
39
47
  end
48
+
49
+ def download_by_name(session, params)
50
+ raise 'missing file name' unless params[:file_name]
51
+ raise 'missing bucket name' unless params[:bucket_name]
52
+
53
+ bucket = find_bucket_by_name session, params[:bucket_name]
54
+ file = params[:file_name]
55
+ session.send(
56
+ Bkblz::V1::DownloadFileByNameRequest.new bucket, file).to_model
57
+ end
58
+
59
+ def download_by_id(session, params)
60
+ raise 'missing file id' unless params[:file_id]
61
+
62
+ partial_file_info =
63
+ Bkblz::V1::Model::PartialFileInfo.new :file_id => params[:file_id]
64
+ session.send(
65
+ Bkblz::V1::DownloadFileByIdRequest.new partial_file_info).to_model
66
+ end
40
67
  end
41
68
  end
42
69
  end
@@ -60,7 +60,8 @@ module Bkblz
60
60
 
61
61
  private
62
62
  def url_for_file(session)
63
- session.create_url(["file", @bucket.bucket_name, @file_name].join "/")
63
+ session.create_download_url(
64
+ ["file", @bucket.bucket_name, @file_name].join "/")
64
65
  end
65
66
  end
66
67
  end
@@ -37,6 +37,11 @@ module Bkblz
37
37
  !!auth_response && !!auth_response.authorization_token
38
38
  end
39
39
 
40
+ def create_download_url(url_suffix)
41
+ check_authorized
42
+ URI.join auth_response.download_url, url_suffix
43
+ end
44
+
40
45
  def create_url(url_suffix)
41
46
  check_authorized
42
47
  URI.join auth_response.api_url, url_suffix
@@ -1,3 +1,3 @@
1
1
  module Bkblz
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bkblz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erick Johnson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-26 00:00:00.000000000 Z
11
+ date: 2017-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor