blobs 0.3.4 → 0.3.5

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: 202125725a1b15d0211b93ee75446eb51f513b82
4
- data.tar.gz: 84a8e7d05035ef1af3900dec3a0d13365e6df7b2
3
+ metadata.gz: 7a0547fdb6f1f10e38893fefeb4c22cda68f7af9
4
+ data.tar.gz: 0e463413c0e12530c667e2e6d9a0881dea725aa8
5
5
  SHA512:
6
- metadata.gz: 6fafd18699a63474acee5edeb3c7bb2bfd5ebacdb7bb7a6da606a82f5ea222aff51d4a67ccfcf0d9d53f215989c6f3d223ee95fdf12c0a576ff9601c60b23726
7
- data.tar.gz: c3ad17b428f4f33463d2da033e60513038501dd9d29934954cc710dd24e7d01a2ae6a52ded5d3db357bd9e6a4cf067fa1c4b986e16c651bb1319acfdd0f6a3d1
6
+ metadata.gz: 31b1ca894800bb07f0d652b6cd7a0ce0bae89e168bed56f8b1dc4c15d303cf08783b79642d20642e0019a01ebf6f6fbe7ab8164b632ee3807c19b3e72aaeaa48
7
+ data.tar.gz: f6926857bdfd68dd090d5b86b7001cf241e1da6008baef3c1ba0fc93facc3e9d8d88b5754cf33b3191dc997882011c1475a2878ee5435aa146542584ff6f9783
data/README.md CHANGED
@@ -31,6 +31,9 @@ Or install it yourself as:
31
31
  c.destroy(blob_id)
32
32
  c.all
33
33
 
34
+ c.add_dir("/Users/oliver/Downloads")
35
+ c.get_dir("/Users/oliver/Downloads")
36
+
34
37
  ## Development
35
38
 
36
39
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/lib/blobs.rb CHANGED
@@ -154,10 +154,21 @@ module Blobs
154
154
  end
155
155
  end
156
156
 
157
- def add_file(file_path, key = 'default')
157
+ def add_file(file_path, key = 'default', persist_locally = false)
158
158
  raise 'No file path given!' unless file_path
159
159
  raise "File doesn't exist!" unless File.file?(file_path)
160
- resp = create(file_to_json(file_path), key, true)
160
+ file_json = file_to_json(file_path)
161
+ resp = create(file_json, key, true)
162
+ if persist_locally
163
+ if resp['id']
164
+ File.open("#{file_path.gsub(file_json[:file_name], resp['id'])}.blob", 'wb') do |f|
165
+ f.write(Base64.encode64(file_json.to_json))
166
+ f.close
167
+ end
168
+ else
169
+ raise "No blob id for file: #{file_json[:file_name]}"
170
+ end
171
+ end
161
172
  resp ? resp['id'] : nil
162
173
  end
163
174
 
@@ -174,16 +185,18 @@ module Blobs
174
185
  nil
175
186
  end
176
187
 
177
- def add_dir(base_path, rm = false)
188
+ def add_dir(base_path, rm = false, persist_locally = false)
178
189
  raise 'No base path given!' unless base_path
179
190
  blob_ids = []
180
191
  Dir["#{base_path}/**/*.*"].each do |file|
181
192
  key = file.split('/')[0...-1].join('/')
182
193
  log("Adding file: #{file}")
183
194
  log("Key: #{key}")
184
- if (blob_id = add_file(file, key))
185
- blob_ids << blob_id
186
- File.delete(file) if rm
195
+ unless file.include?('.blob')
196
+ if (blob_id = add_file(file, key, persist_locally))
197
+ blob_ids << blob_id
198
+ File.delete(file) if rm
199
+ end
187
200
  end
188
201
  end
189
202
  blob_ids
@@ -205,6 +218,21 @@ module Blobs
205
218
  files
206
219
  end
207
220
 
221
+ def restore_local_dir(base_path, rm = false)
222
+ files = []
223
+ Dir["#{base_path}/**/*.*"].each do |file|
224
+ if file.include?('.blob')
225
+ decoded_string = Base64.decode64(File.open(file, 'rb').read)
226
+ file_json = JSON.parse(decoded_string)
227
+ dir = file.split('/')[0...-1].join('/')
228
+ file_from_json(file_json, dir)
229
+ files << "#{dir}/#{file_json['file_name']}"
230
+ File.delete(file) if rm
231
+ end
232
+ end
233
+ files
234
+ end
235
+
208
236
  private
209
237
  def headers(additional_headers = {})
210
238
  additional_headers.merge({
data/lib/blobs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Blobs
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blobs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Kiessler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-12 00:00:00.000000000 Z
11
+ date: 2017-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler