blobs 0.2.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/blobs.gemspec +1 -1
- data/lib/blobs/version.rb +1 -1
- data/lib/blobs.rb +57 -10
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9f2cd95af697c75032b66c4b5f60e7103ada354
|
4
|
+
data.tar.gz: 6e21d7194171750e2c059c654ece609d7dcc32ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccbdbf0cc19719fb53305bcbc9019313e44066c07632373e72e85271be4250cd53f2451082372e43726749092c1ac9b01f61db746cf969080a30d5a19042c1fc
|
7
|
+
data.tar.gz: 1d0be765842755f575ec0619162adeab18c827d57c402f9e854f68ba8691030c657bab2f520e033bacb9be2e0ef16efbe5aedadfda4d16c1f81d63dc84071ae1
|
data/blobs.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.add_dependency "bundler", "~> 1.
|
24
|
+
spec.add_dependency "bundler", "~> 1.15"
|
25
25
|
spec.add_dependency "rake", "~> 10.0"
|
26
26
|
spec.add_dependency "httparty", "~> 0.13.7"
|
27
27
|
end
|
data/lib/blobs/version.rb
CHANGED
data/lib/blobs.rb
CHANGED
@@ -7,9 +7,6 @@ require 'cgi'
|
|
7
7
|
require 'yaml'
|
8
8
|
require 'securerandom'
|
9
9
|
|
10
|
-
# ENV['BLOB_STORE_API_BASE_URL'] = 'http://45.76.84.129'
|
11
|
-
# ENV['MASTER_KEY'] = '6CU3xfUOtvvVBRPPOe5ShlCOAZ0Ht5k9'
|
12
|
-
|
13
10
|
module Blobs
|
14
11
|
DEBUG = false
|
15
12
|
|
@@ -31,17 +28,28 @@ module Blobs
|
|
31
28
|
|
32
29
|
def login(email, password)
|
33
30
|
auth = { username: email, password: password }
|
34
|
-
response = HTTParty.post("#{base_url}/auth
|
31
|
+
response = HTTParty.post("#{base_url}/auth",
|
35
32
|
basic_auth: auth)
|
36
33
|
if response.code == 201 and response.parsed_response
|
37
34
|
log "#{response.parsed_response.inspect}"
|
38
35
|
self.current_user = response.parsed_response['user']
|
39
36
|
self.token = response.parsed_response['token']
|
40
37
|
encryption_key
|
41
|
-
self.token
|
42
|
-
|
43
|
-
|
38
|
+
return self.token
|
39
|
+
end
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_user(email, password)
|
44
|
+
raise "You need to set the master key to create users!" unless master_token
|
45
|
+
user = { email: email, password: password }
|
46
|
+
response = HTTParty.post("#{base_url}/users?access_token=#{master_token}",
|
47
|
+
body: user)
|
48
|
+
log "#{response.parsed_response.inspect}"
|
49
|
+
if response.code == 201 and response.parsed_response and response.parsed_response['email']
|
50
|
+
return response.parsed_response
|
44
51
|
end
|
52
|
+
nil
|
45
53
|
end
|
46
54
|
|
47
55
|
def all(key = nil)
|
@@ -55,7 +63,8 @@ module Blobs
|
|
55
63
|
id: blob['id'],
|
56
64
|
created_at: blob['createdAt'],
|
57
65
|
json: (blob['json'] ? (JSON.parse(decrypt(blob['json'])) rescue nil) : nil),
|
58
|
-
key: blob['key']
|
66
|
+
key: blob['key'],
|
67
|
+
file: blob['file'] ? blob['file'] : false
|
59
68
|
}
|
60
69
|
end
|
61
70
|
end
|
@@ -68,12 +77,12 @@ module Blobs
|
|
68
77
|
response.parsed_response ? JSON.parse(decrypt(response.parsed_response['json'])) : nil
|
69
78
|
end
|
70
79
|
|
71
|
-
def create(json, key = 'default')
|
80
|
+
def create(json, key = 'default', is_file = false)
|
72
81
|
raise 'No access token!' unless self.token
|
73
82
|
raise "No json hash!" unless json
|
74
83
|
raise "No key!" unless key
|
75
84
|
response = HTTParty.post("#{base_url}/blobs?access_token=#{self.token}",
|
76
|
-
{ body: { json: encrypt(json.to_json), key: sha256(key) } })
|
85
|
+
{ body: { json: encrypt(json.to_json), key: sha256(key), isFile: is_file } })
|
77
86
|
log "Blob created: #{response.parsed_response.inspect}"
|
78
87
|
response.parsed_response
|
79
88
|
end
|
@@ -106,6 +115,44 @@ module Blobs
|
|
106
115
|
export_file
|
107
116
|
end
|
108
117
|
|
118
|
+
def file_to_json(file_path)
|
119
|
+
encoded_string = Base64.encode64(File.open(file_path, 'rb').read)
|
120
|
+
{ file: encoded_string, file_name: file_path.split('/').last,
|
121
|
+
file_size: File.size(file_path) }
|
122
|
+
end
|
123
|
+
|
124
|
+
def file_from_json(file_json, path = '/tmp', blob_id = nil)
|
125
|
+
if file_json and file_json['file'] and file_json['file_name']
|
126
|
+
decoded_string = Base64.decode64(file_json['file'])
|
127
|
+
blob_file_path = "#{path}/#{blob_id ? "#{blob_id}-" : ''}#{file_json['file_name']}"
|
128
|
+
File.open(blob_file_path, 'wb') do |f|
|
129
|
+
f.write(decoded_string)
|
130
|
+
f.close
|
131
|
+
end
|
132
|
+
blob_file_path
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def add_file(file_path, key = 'default')
|
137
|
+
raise 'No file path given!' unless file_path
|
138
|
+
raise "File doesn't exist!" unless File.file?(file_path)
|
139
|
+
resp = create(file_to_json(file_path), key, true)
|
140
|
+
resp ? resp['id'] : nil
|
141
|
+
end
|
142
|
+
|
143
|
+
def update_file(blob_id, file_path, key = 'default')
|
144
|
+
raise 'No file path given!' unless file_path
|
145
|
+
raise "File doesn't exist!" unless File.file?(file_path)
|
146
|
+
update(blob_id, file_to_json(file_path), key)
|
147
|
+
end
|
148
|
+
|
149
|
+
def get_file(blob_id, path = '/tmp')
|
150
|
+
if (blob = find(blob_id))
|
151
|
+
return file_from_json(blob, path, blob_id) if blob['file'] and blob['file_name']
|
152
|
+
end
|
153
|
+
nil
|
154
|
+
end
|
155
|
+
|
109
156
|
private
|
110
157
|
def sha256(str)
|
111
158
|
Base64.encode64(Digest::SHA256.digest(str)).strip
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blobs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oliver Kiessler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.15'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.15'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|