bkblz 0.1.0 → 0.1.2

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
  SHA1:
3
- metadata.gz: 7636a95e10db31242f5b3e666734c62e16f870da
4
- data.tar.gz: 54425688a09f9dcec3d598ad9b9fc312e1cb8c42
3
+ metadata.gz: 5e5b80d7bec5fcf808b83fea5b07e508dc215e84
4
+ data.tar.gz: 50eba053e7feb3bf6ab847519ecac06d6a224d3a
5
5
  SHA512:
6
- metadata.gz: 73aa799368884833b533d5ae3e8f23f7dd3b4c0a8aa0126c69509420520b290bb631721860b788a66ab0d2b13839b27fcb68e064ad07adb635285234ac932eca
7
- data.tar.gz: ba3359e74fc5b8e49da7f21ebd60a8f5e59d4ee421633a22dbd0d71428455120f16b294b72e7d012c467eac147832dddc1cbefca3e4287e9024f25fad22e5c54
6
+ metadata.gz: 586eb75671ece61435dd0bbfa3f28ff01e18b74286e9549dd9692dc7409c7e26e49ee51bbab579e7a75a94dc268abc04871f1322af4af77426bf854af5c1316c
7
+ data.tar.gz: 7d992fc8b24164ad07da989f0c5cf36c9c8beba3135f339b7ea9833cfe13674039a4d57bbf136a9135ff5a69147195e2bad400202b0285cf388dd85912032f41
data/README.rb CHANGED
@@ -1,19 +1,23 @@
1
+ # Run `ruby README.rb` for a working demo, but first add your
2
+ # application key and account id in the slots below.
3
+
4
+ # Or `gem install bkblz` to begin. After install try `bkblz -h` to use
5
+ # the CLI
6
+
1
7
  $: << 'lib'
2
- require 'all'
8
+ require 'bkblz'
3
9
 
4
- # Run `ruby README.rb` for a working demo, but first add your
5
- # applicatoin key and account id in the slots below.
6
10
  Bkblz.configure do |config_map|
7
11
  config_map.merge!(
8
- :application_key => "!!! APP KEY !!!",
12
+ :application_key => "!!! API KEY !!!",
9
13
  :account_id => "!!! ACCOUNT ID !!!",
10
14
  :debug_http => false,
11
15
  :log_level => :info # change this to :debug for more info
12
16
  )
13
17
  end
14
18
 
15
- Bkblz.log.info do <<EOS
16
- # Step 1, the block above configures some defaults (including the
19
+ Bkblz.log.info do <<-EOS
20
+ # The block above configures some defaults (including the
17
21
  # logger, which is why this is after the configure block), see
18
22
  # Bkblz::Config for details. This is where to set the account_id
19
23
  # and application_key.
@@ -25,8 +29,8 @@ if Bkblz.config.account_id.match /!!!/
25
29
  exit 1
26
30
  end
27
31
 
28
- Bkblz.log.info do <<EOS
29
- # Step 2, using the config above, create an authorized session. All
32
+ Bkblz.log.info do <<-EOS
33
+ # Using the config above, create an authorized session. All
30
34
  # requests will run in the context of this session. See
31
35
  # +Bkblz::V1::Session#authorize+.
32
36
  EOS
@@ -34,20 +38,20 @@ end
34
38
  Bkblz::V1::Session.authorize Bkblz.config do |api_session|
35
39
  Bkblz.log.info "API session => #{api_session}"
36
40
 
37
- Bkblz.log.info do <<EOS
38
- # Step 3, first try to find an existing bucket named my-test-bucket,
39
- # we'll use that if it exists. All requests in a session are sent
40
- # through the session so that the request object gets access to the
41
- # auth credentials.
42
- EOS
41
+ Bkblz.log.info do <<-EOS
42
+ # First try to find an existing bucket named my-test-bucket,
43
+ # we'll use that if it exists. All requests in a session are sent
44
+ # through the session so that the request object gets access to the
45
+ # auth credentials.
46
+ EOS
43
47
  end
44
48
  buckets = api_session.send(Bkblz::V1::ListBucketsRequest.new).buckets
45
49
  bucket = buckets.select { |b| b.bucket_name == "my-test-bucket" }.first
46
50
  Bkblz.log.info "bucket list => #{buckets}"
47
51
 
48
- Bkblz.log.info do <<EOS
49
- # Step 4, otherwise create a new my-test-bucket
50
- EOS
52
+ Bkblz.log.info do <<-EOS
53
+ # Otherwise create a new my-test-bucket
54
+ EOS
51
55
  end
52
56
  unless bucket
53
57
  bucket = Bkblz::V1::Model::Bucket.new \
@@ -55,13 +59,13 @@ EOS
55
59
  :bucket_type => "allPrivate",
56
60
  :account_id => api_session.account_id
57
61
 
58
- Bkblz.log.info do <<EOS
59
- # Step 5, pass a model to the CreateBucketRequest,
60
- # models are just named wrappers with dynamic methods
61
- # around the JSON responses provided back from the Bkblz
62
- # API. See lib/bkblz/v1/models.rb for a list of defined API
63
- # objects. See Bkblz::V1::Model::Base for how it work.
64
- EOS
62
+ Bkblz.log.info do <<-EOS
63
+ # Pass a model to the CreateBucketRequest,
64
+ # models are just named wrappers with dynamic methods
65
+ # around the JSON responses provided back from the Bkblz
66
+ # API. See lib/bkblz/v1/models.rb for a list of defined API
67
+ # objects. See Bkblz::V1::Model::Base for how it work.
68
+ EOS
65
69
  end
66
70
  request = Bkblz::V1::CreateBucketRequest.new bucket
67
71
  Bkblz.log.info "bucket model => #{bucket}"
@@ -73,19 +77,19 @@ EOS
73
77
  Bkblz.log.info "created bucket => #{bucket.bucket_name}/#{bucket.bucket_id}"
74
78
  end
75
79
 
76
- Bkblz.log.info do <<EOS
77
- # Step 6, uploading a file begins with getting a dynamic URL from the API.
78
- EOS
80
+ Bkblz.log.info do <<-EOS
81
+ # Uploading a file begins with getting a dynamic URL from the API.
82
+ EOS
79
83
  end
80
84
  upload_auth = api_session.send(
81
85
  Bkblz::V1::GetUploadUrlRequest.new bucket.bucket_id).to_model
82
86
  Bkblz.log.info "upload file URL => #{upload_auth.upload_url}"
83
87
 
84
88
 
85
- Bkblz.log.info do <<EOS
86
- # Step 7, use the upload_auth model (a
87
- # Bkblz::V1::Model::UploadAuth) to upload some files.
88
- EOS
89
+ Bkblz.log.info do <<-EOS
90
+ # Use the upload_auth model (a
91
+ # Bkblz::V1::Model::UploadAuth) to upload some files.
92
+ EOS
89
93
  end
90
94
  5.times do |i|
91
95
  body = "some text #{i}"
@@ -98,21 +102,21 @@ EOS
98
102
  Bkblz.log.info "uploaded file => #{upload_file_info.file_name}"
99
103
  end
100
104
 
101
- Bkblz.log.info do <<EOS
102
- # Step 8, we uploaded 5 files above, here we'll read back out
103
- # metadata from the first 2 files in the bucket.
104
- EOS
105
+ Bkblz.log.info do <<-EOS
106
+ # We uploaded 5 files above, here we'll read back out
107
+ # metadata from the first 2 files in the bucket.
108
+ EOS
105
109
  end
106
110
  list_files_response = api_session.send(
107
111
  Bkblz::V1::ListFileVersionsRequest.new bucket, 2)
108
112
  bucket_files_info = list_files_response.files
109
113
  Bkblz.log.info "first 2 files => #{bucket_files_info.map(&:file_name).join "\n"}"
110
114
 
111
- Bkblz.log.info do <<EOS
112
- # Step 9, the response object returned object is a
113
- # Bkblz::Api::PaginatedResponse. Use its +has_more?+ and
114
- # +next_request+ methods to page through more results.
115
- EOS
115
+ Bkblz.log.info do <<-EOS
116
+ # The response object returned object is a
117
+ # Bkblz::Api::PaginatedResponse. Use its +has_more?+ and
118
+ # +next_request+ methods to page through more results.
119
+ EOS
116
120
  end
117
121
  while list_files_response.has_more?
118
122
  list_files_response = api_session.send list_files_response.next_request 100
@@ -120,10 +124,19 @@ EOS
120
124
  Bkblz.log.info "next N files => #{list_files_response.files.map(&:file_name).join "\n"}"
121
125
  end
122
126
 
123
- Bkblz.log.info do <<EOS
124
- # Step 10, delete all the files in the bucket that we added. This is
125
- # a service requirement to deleting a bucket.
126
- EOS
127
+ Bkblz.log.info do <<-EOS
128
+ # Files can also be listed by name.
129
+ EOS
130
+ end
131
+ list_files_response = api_session.send(
132
+ Bkblz::V1::ListFileNamesRequest.new bucket, 10)
133
+ bucket_files_info = list_files_response.files
134
+ Bkblz.log.info "files by name => #{bucket_files_info.map(&:file_name).join "\n"}"
135
+
136
+ Bkblz.log.info do <<-EOS
137
+ # Delete all the files in the bucket that we added. This is
138
+ # a service requirement to deleting a bucket.
139
+ EOS
127
140
  end
128
141
  bucket_files_info.each do |file_info|
129
142
  request = Bkblz::V1::DeleteFileVersionRequest.new file_info
@@ -131,9 +144,9 @@ EOS
131
144
  Bkblz.log.info "deleted file => #{delete_file_version_response.to_model.file_name}"
132
145
  end
133
146
 
134
- Bkblz.log.info do <<EOS
135
- # Step 11, delete the bucket.
136
- EOS
147
+ Bkblz.log.info do <<-EOS
148
+ # Finally, delete the bucket.
149
+ EOS
137
150
  end
138
151
  request = Bkblz::V1::DeleteBucketRequest.new bucket
139
152
  delete_bucket_response = api_session.send request
data/bin/bkblz ADDED
@@ -0,0 +1,138 @@
1
+ #!/usr/bin/env ruby
2
+ $: << "lib"
3
+ require "bkblz"
4
+ require "thor"
5
+ require "yaml"
6
+
7
+ module Bkblz
8
+
9
+ module Helper
10
+ def parse_opts
11
+ if options[:config]
12
+ f = options[:config]
13
+ raise "unreadable config file #{f}" unless ::File.readable? f
14
+ Bkblz.configure do |map|
15
+ map.merge YAML.load(::File.read f)
16
+ end
17
+ end
18
+ end
19
+
20
+ def run_task(&block)
21
+ begin
22
+ yield
23
+ rescue Bkblz::Task::MissingBucketError => e
24
+ STDERR.puts "Unknown bucket: #{e.message}"
25
+ exit 1
26
+ rescue Bkblz::V1::UnauthorizedRequestError => e
27
+ msg = if options[:config]
28
+ "bad account id or application key, check your auth credentials"
29
+ else
30
+ "use '-c path/to/config.yml' to supply credentials"
31
+ end
32
+ STDERR.puts "Unauthorized request: #{msg}"
33
+ exit 1
34
+ end
35
+ end
36
+
37
+ def print_header(header)
38
+ puts ""
39
+ puts "*** #{header} ***"
40
+ puts ""
41
+ end
42
+
43
+ def print_model(model)
44
+ puts model.to_yaml
45
+ end
46
+ end
47
+
48
+ class Bucket < Thor
49
+ include Helper
50
+
51
+ desc "bucket list", "lists all of your buckets"
52
+ def list
53
+ parse_opts
54
+
55
+ buckets = run_task do
56
+ Bkblz::Task::ListBuckets.run Bkblz.config
57
+ end
58
+
59
+ print_header "Buckets"
60
+ buckets.each do |bucket|
61
+ puts bucket.bucket_name
62
+ end
63
+ end
64
+
65
+ desc "bucket create <bucket_name>", "creates a new bucket"
66
+ def create(bucket_name)
67
+ parse_opts
68
+
69
+ bucket = run_task do
70
+ Bkblz::Task::CreateBucket.run Bkblz.config, :bucket_name => bucket_name
71
+ end
72
+ print_header "New Bucket"
73
+ print_model bucket
74
+ end
75
+ end
76
+
77
+ class File < Thor
78
+ include Helper
79
+
80
+ desc "file upload <bucket_name> <local_file_path>", "upload a local file to B2"
81
+ def upload(bucket_name, local_file_path)
82
+ parse_opts
83
+
84
+ file_info = run_task do
85
+ Bkblz::Task::UploadFile.run Bkblz.config, {
86
+ :bucket_handle => bucket_name,
87
+ :handle_type => :bucket_name,
88
+ :file_path => local_file_path
89
+ }
90
+ end
91
+
92
+ print_header "File Info"
93
+ print_model file_info
94
+ end
95
+
96
+ desc "file list <bucket_name>", "lists files in a bucket"
97
+ option :start_at, :desc => "file name to start listing from"
98
+ option :limit, {
99
+ :desc => "limit of files to list per request",
100
+ :default => 100,
101
+ :type => :numeric
102
+ }
103
+ option :all, :desc => "lists all file versions, cannot be used with --start-at"
104
+ def list(bucket_name)
105
+ parse_opts
106
+
107
+ task = Bkblz::Task::ListFiles.new Bkblz.config
108
+ run_task do
109
+
110
+ paged_response = task.run({
111
+ :start_at => options[:start_at],
112
+ :limit => options[:limit],
113
+ :all_versions => options[:all],
114
+ :bucket_name => bucket_name
115
+ })
116
+
117
+ print_header "Files"
118
+ paged_response.files.each do |f|
119
+ puts f.file_name
120
+ end
121
+ end
122
+ end
123
+ end
124
+
125
+ class Cli < Thor
126
+ include Helper
127
+
128
+ class_option :config, :desc => "path to a yml config file", :aliases => ["-c"]
129
+
130
+ desc "bucket SUBCOMMAND ...ARGS", "manage backblaze buckets"
131
+ subcommand "bucket", Bucket
132
+
133
+ desc "file SUBCOMMAND ...ARGS", "manage backblaze files"
134
+ subcommand "file", File
135
+ end
136
+ end
137
+
138
+ Bkblz::Cli.start ARGV
data/bkblz.gemspec CHANGED
@@ -3,23 +3,26 @@ lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'bkblz/version'
5
5
 
6
- Gem::Specification.new do |spec|
7
- spec.name = "bkblz"
8
- spec.version = Bkblz::VERSION
9
- spec.authors = ["Erick Johnson"]
10
- spec.email = ["erick@vos.io"]
6
+ Gem::Specification.new do |s|
7
+ s.name = "bkblz"
8
+ s.version = Bkblz::VERSION
9
+ s.authors = ["Erick Johnson"]
10
+ s.email = ["erick@vos.io"]
11
11
 
12
- spec.summary = "Bkblz GEM for the Backblaze B2 API. https://www.backblaze.com/b2/docs/"
13
- spec.description = spec.description
14
- spec.homepage = "https://github.com/erickj/bkblz"
15
- spec.license = "MIT"
12
+ s.summary = "Bkblz GEM for the Backblaze B2 API. https://www.backblaze.com/b2/docs/"
13
+ s.description = s.description
14
+ s.homepage = "https://github.com/erickj/bkblz"
15
+ s.license = "MIT"
16
16
 
17
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ s.files = `git ls-files -z`.split("\x0").reject do |f|
18
18
  f.match(%r{^(test|spec|features)/})
19
19
  end
20
- spec.require_paths = ["lib"]
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
21
22
 
22
- spec.add_development_dependency "bundler", "~> 1.13"
23
- spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_development_dependency "rspec", "~> 3.0"
23
+ s.add_dependency "thor", "~> 0.19"
24
+
25
+ s.add_development_dependency "bundler", "~> 1.13"
26
+ s.add_development_dependency "rake", "~> 10.0"
27
+ s.add_development_dependency "rspec", "~> 3.0"
25
28
  end
data/lib/bkblz.rb CHANGED
@@ -1,5 +1,5 @@
1
- require "bkblz/config"
2
- require "bkblz/logger"
1
+ require_relative "bkblz/config"
2
+ require_relative "bkblz/logger"
3
3
 
4
4
  module Bkblz
5
5
 
@@ -33,3 +33,5 @@ module Bkblz
33
33
  end
34
34
  end
35
35
  end
36
+
37
+ require "bkblz/all"
data/lib/bkblz/all.rb ADDED
@@ -0,0 +1,7 @@
1
+ require_relative "version"
2
+
3
+ require_relative "core_ext"
4
+ require_relative "map_key_formatter"
5
+
6
+ require_relative "v1/all"
7
+ require_relative "task/all"
data/lib/bkblz/config.rb CHANGED
@@ -26,7 +26,7 @@ module Bkblz
26
26
  class << self
27
27
  def configure(config=nil, &block)
28
28
  map = config ? config.config_map : CONFIG_VARS.dup
29
- yield map if block_given?
29
+ map = yield map if block_given?
30
30
  Config.new map
31
31
  end
32
32
  end
@@ -0,0 +1,7 @@
1
+ require_relative "task_helpers"
2
+ require_relative "task"
3
+
4
+ require_relative "list_buckets"
5
+ require_relative "create_bucket"
6
+ require_relative "list_files"
7
+ require_relative "upload_file"
@@ -0,0 +1,22 @@
1
+ module Bkblz
2
+ module Task
3
+ class CreateBucket < BaseTask
4
+
5
+ DuplicateBucketError = Class.new Bkblz::BaseError
6
+
7
+ task_param :bucket_name, :required => true
8
+ task_param :bucket_type
9
+
10
+ def run_internal(session, params)
11
+ bucket_fields = {
12
+ :account_id => session.account_id,
13
+ :bucket_type => "allPrivate"
14
+ }.merge params
15
+ bucket = Bkblz::V1::Model::Bucket.new bucket_fields
16
+
17
+ session.send(Bkblz::V1::CreateBucketRequest.new bucket).to_model
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ module Bkblz
2
+ module Task
3
+ class ListBuckets < BaseTask
4
+
5
+ def run_internal(session, params)
6
+ session.send(Bkblz::V1::ListBucketsRequest.new).buckets
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ module Bkblz
2
+ module Task
3
+ class ListFiles < BaseTask
4
+
5
+ task_param :start_at
6
+ task_param :limit, :default => 100
7
+ task_param :all_versions
8
+ task_param :bucket_name, :required => true
9
+
10
+ def run_internal(session, params)
11
+ bucket = find_bucket_by_name session, params[:bucket_name]
12
+
13
+ if params[:all_versions]
14
+ session.send Bkblz::V1::ListFileVersionsRequest.new bucket, params[:limit]
15
+ else
16
+ session.send Bkblz::V1::ListFileNamesRequest.new(
17
+ bucket, params[:limit], params[:start_at])
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,82 @@
1
+ module Bkblz
2
+ module Task
3
+
4
+ TaskParamError = Class.new Bkblz::BaseError
5
+
6
+ module ClassMethods
7
+ PARAM_SPEC = {
8
+ :name => nil,
9
+ :required => false,
10
+ :default => nil,
11
+ :one_of => nil
12
+ }.freeze
13
+
14
+ def run(config, **params)
15
+ task = self.new config
16
+ task.run **params
17
+ end
18
+
19
+ def task_param(name, **param_spec)
20
+ if param_spec[:one_of] && !param_spec[:one_of].is_a?(Enumerable)
21
+ raise TaskParamError, "#{name}: :one_of must be enumerable"
22
+ end
23
+ task_params << PARAM_SPEC.merge(param_spec.merge :name => name)
24
+ end
25
+
26
+ def task_params
27
+ @task_params ||= []
28
+ end
29
+
30
+ def check_params(params)
31
+ task_params.each do |spec|
32
+ name spec[:name]
33
+ value = params[name]
34
+
35
+ if spec[:default] && value.nil?
36
+ params[name] = spec[:default]
37
+ end
38
+
39
+ check_required name, value, spec
40
+ check_one_of name, value, spec
41
+ end
42
+ end
43
+
44
+ def check_required(name, value, spec)
45
+ raise TaskParamError, "[#{name}:required]" if spec[:required] && value.nil?
46
+ end
47
+
48
+ def check_one_of(name, value, spec)
49
+ return unless spec[:one_of]
50
+ unless spec[:one_of].include? value
51
+ raise TaskParamError, "[#{name}:one_of] invalid values: #{value}"
52
+ end
53
+ end
54
+ end
55
+
56
+ class BaseTask
57
+ extend ClassMethods
58
+ include TaskHelpers
59
+
60
+ attr_reader :config, :result
61
+
62
+ def initialize(config)
63
+ @config = config
64
+ @result = nil
65
+ end
66
+
67
+ def run(task_params)
68
+ BaseTask.check_params task_params
69
+
70
+ Bkblz::V1::Session.authorize config do |session|
71
+ @result = run_internal session, task_params
72
+ end
73
+ result
74
+ end
75
+
76
+ protected
77
+ def run_internal(session, task_params)
78
+ raise 'not implemented'
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,19 @@
1
+ module Bkblz
2
+ module Task
3
+
4
+ MissingBucketError = Class.new Bkblz::BaseError
5
+
6
+ module TaskHelpers
7
+
8
+ def find_bucket_by_name(session, bucket_name)
9
+ buckets = session.send(Bkblz::V1::ListBucketsRequest.new).buckets
10
+ bucket = buckets.find do |bucket|
11
+ bucket.bucket_name == bucket_name
12
+ end
13
+ raise MissingBucketError, bucket_name unless bucket
14
+ bucket
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ module Bkblz
2
+ module Task
3
+ class UploadFile < BaseTask
4
+
5
+ task_param :bucket_name, :required => true
6
+ task_param :file_path, :required => true
7
+
8
+ def run_internal(session, params)
9
+ f = ::File.new(params[:file_path], "r")
10
+
11
+ bucket = find_bucket_by_name session, params[:bucket_name]
12
+ upload_auth = session.send(
13
+ Bkblz::V1::GetUploadUrlRequest.new bucket.bucket_id).to_model
14
+
15
+ file_name = ::File.basename f.path
16
+ file_body = f.read
17
+ mtime_millis = f.mtime.to_i * 1000
18
+
19
+ upload_file_info = session.send(
20
+ Bkblz::V1::UploadFileRequest.new upload_auth, file_body, file_name,
21
+ nil, mtime_millis).to_model
22
+ end
23
+ end
24
+ end
25
+ end
data/lib/bkblz/v1/all.rb CHANGED
@@ -12,5 +12,6 @@ require_relative "create_bucket"
12
12
  require_relative "delete_bucket"
13
13
  require_relative "get_upload_url"
14
14
  require_relative "upload_file"
15
+ require_relative "list_file_names"
15
16
  require_relative "list_file_versions"
16
17
  require_relative "delete_file_version"
@@ -0,0 +1,35 @@
1
+ module Bkblz
2
+ module V1
3
+
4
+ class ListFileNamesResponse < PaginatedResponse
5
+ response_accessor :files, Model::FileInfo
6
+ pagination_accessors :next_file_name
7
+
8
+ def build_next_request(limit)
9
+ bucket = original_request.bucket
10
+ limit ||= files.size
11
+ ListFileNamesRequest.new bucket, limit, next_file_name
12
+ end
13
+ end
14
+
15
+ class ListFileNamesRequest < Request
16
+
17
+ response_class ListFileNamesResponse
18
+ url_suffix "/b2api/v1/b2_list_file_names"
19
+
20
+ attr_reader :bucket
21
+
22
+ def initialize(bucket, max_file_count=1000, start_file_name=nil)
23
+ @bucket = bucket
24
+ @body = {}
25
+ @body[:bucket_id] = bucket.bucket_id
26
+ @body[:max_file_count] = max_file_count
27
+ @body[:start_file_name] = start_file_name if start_file_name
28
+ end
29
+
30
+ def build_request(session)
31
+ session.create_post url(session), @body
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,3 +1,5 @@
1
+ require "yaml"
2
+
1
3
  module Bkblz
2
4
  module V1
3
5
  module Model
@@ -28,6 +30,10 @@ module Bkblz
28
30
  @map.dup
29
31
  end
30
32
 
33
+ def to_yaml
34
+ @map.to_yaml
35
+ end
36
+
31
37
  def to_s
32
38
  "#<%s:%d %s>" % [self.class.name, __id__, @map]
33
39
  end
@@ -6,11 +6,23 @@ module Bkblz
6
6
  TooManyRedirectError = Class.new Bkblz::BaseError
7
7
 
8
8
  class RequestError < Bkblz::BaseError
9
+
10
+ def self.create(error_response)
11
+ case error_response.to_model.status
12
+ when 401
13
+ UnauthorizedRequestError.new error_response
14
+ else
15
+ RequestError.new error_response
16
+ end
17
+ end
18
+
9
19
  def initialize(error_response)
10
20
  super error_response.message
11
21
  end
12
22
  end
13
23
 
24
+ UnauthorizedRequestError = Class.new RequestError
25
+
14
26
  class Request
15
27
 
16
28
  class << self
@@ -44,7 +56,7 @@ module Bkblz
44
56
  def build_response(response)
45
57
  unless response.kind_of? Net::HTTPSuccess
46
58
  error_response = ErrorResponse.new response, self
47
- raise RequestError.new error_response
59
+ raise RequestError.create error_response
48
60
  end
49
61
  Bkblz.log.debug { "#build_response => #{response}" }
50
62
 
data/lib/bkblz/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bkblz
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bkblz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erick Johnson
@@ -10,6 +10,20 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2016-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.19'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.19'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -55,7 +69,8 @@ dependencies:
55
69
  description: ''
56
70
  email:
57
71
  - erick@vos.io
58
- executables: []
72
+ executables:
73
+ - bkblz
59
74
  extensions: []
60
75
  extra_rdoc_files: []
61
76
  files:
@@ -66,13 +81,21 @@ files:
66
81
  - LICENSE.txt
67
82
  - README.rb
68
83
  - Rakefile
84
+ - bin/bkblz
69
85
  - bkblz.gemspec
70
- - lib/all.rb
71
86
  - lib/bkblz.rb
87
+ - lib/bkblz/all.rb
72
88
  - lib/bkblz/config.rb
73
89
  - lib/bkblz/core_ext.rb
74
90
  - lib/bkblz/logger.rb
75
91
  - lib/bkblz/map_key_formatter.rb
92
+ - lib/bkblz/task/all.rb
93
+ - lib/bkblz/task/create_bucket.rb
94
+ - lib/bkblz/task/list_buckets.rb
95
+ - lib/bkblz/task/list_files.rb
96
+ - lib/bkblz/task/task.rb
97
+ - lib/bkblz/task/task_helpers.rb
98
+ - lib/bkblz/task/upload_file.rb
76
99
  - lib/bkblz/v1/all.rb
77
100
  - lib/bkblz/v1/authorize_account.rb
78
101
  - lib/bkblz/v1/create_bucket.rb
@@ -81,6 +104,7 @@ files:
81
104
  - lib/bkblz/v1/error_response.rb
82
105
  - lib/bkblz/v1/get_upload_url.rb
83
106
  - lib/bkblz/v1/list_buckets.rb
107
+ - lib/bkblz/v1/list_file_names.rb
84
108
  - lib/bkblz/v1/list_file_versions.rb
85
109
  - lib/bkblz/v1/model_base.rb
86
110
  - lib/bkblz/v1/models.rb
data/lib/all.rb DELETED
@@ -1,6 +0,0 @@
1
- require "bkblz/core_ext"
2
- require "bkblz/map_key_formatter"
3
-
4
- require "bkblz"
5
- require "bkblz/v1/all"
6
- require "bkblz/version"