attsynaptic-synaptic4r 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +6 -0
- data/LICENSE +11 -0
- data/README.rdoc +79 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/bin/synrest +316 -0
- data/lib/synaptic4r.rb +15 -0
- data/lib/synaptic4r/client.rb +77 -0
- data/lib/synaptic4r/help.rb +605 -0
- data/lib/synaptic4r/request.rb +288 -0
- data/lib/synaptic4r/rest.rb +355 -0
- data/lib/synaptic4r/result.rb +345 -0
- data/synaptic4r.gemspec +54 -0
- metadata +87 -0
@@ -0,0 +1,345 @@
|
|
1
|
+
############################################################################################################
|
2
|
+
module Synaptic4r
|
3
|
+
|
4
|
+
##########################################################################################################
|
5
|
+
class Result
|
6
|
+
|
7
|
+
#.......................................................................................................
|
8
|
+
attr_reader :headers, :url, :http_request, :sign, :payload
|
9
|
+
|
10
|
+
#.......................................................................................................
|
11
|
+
def initialize(args)
|
12
|
+
@http_request = args[:http_request]
|
13
|
+
@headers = args[:headers]
|
14
|
+
@url = args[:url]
|
15
|
+
@sign = args[:sign]
|
16
|
+
@payload = args[:payload]
|
17
|
+
end
|
18
|
+
|
19
|
+
#.......................................................................................................
|
20
|
+
def print
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
|
25
|
+
#.......................................................................................................
|
26
|
+
def extract_header(args, header)
|
27
|
+
headers = args[:result].headers[header]
|
28
|
+
if headers
|
29
|
+
headers.split(/,\s+/).map{|a| a.strip}.inject({}) do |r,a|
|
30
|
+
v = a.split('=')
|
31
|
+
v << 'N/A' if v.length < 2
|
32
|
+
r.update(v.first => v.last)
|
33
|
+
end
|
34
|
+
else
|
35
|
+
{}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
#.......................................................................................................
|
40
|
+
def stringify_hash(h)
|
41
|
+
h.inject(""){|r,(u,a)| r += " #{u}=#{a}\n"}
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
#.......................................................................................................
|
46
|
+
def stringify_array(a)
|
47
|
+
a.split(/,\s+/).sort.inject(""){|s,t| s += "#{t}, "}.chomp(', ') if a
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
#Response
|
52
|
+
end
|
53
|
+
|
54
|
+
##########################################################################################################
|
55
|
+
class StorageObject < Result
|
56
|
+
|
57
|
+
#.......................................................................................................
|
58
|
+
def initialize(args)
|
59
|
+
super
|
60
|
+
if args[:result]
|
61
|
+
@location = args[:result].headers[:location]
|
62
|
+
@date = args[:result].headers[:date]
|
63
|
+
@size = args[:result].headers[:x_emc_delta]
|
64
|
+
@oid = /\/rest\/objects\/(.*)/.match(@location).captures.first
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
#.......................................................................................................
|
69
|
+
def print
|
70
|
+
(@oid.nil? ? '' : "OID: #{@oid}\n") +
|
71
|
+
(@size.nil? ? '' : "size: #{@size} bytes")
|
72
|
+
end
|
73
|
+
|
74
|
+
#Upload
|
75
|
+
end
|
76
|
+
|
77
|
+
##########################################################################################################
|
78
|
+
class UserMetadata < Result
|
79
|
+
|
80
|
+
#.......................................................................................................
|
81
|
+
def initialize(args)
|
82
|
+
super
|
83
|
+
if args[:result]
|
84
|
+
@metadata = extract_header(args, :x_emc_meta)
|
85
|
+
@listable_metadata = extract_header(args, :x_emc_listable_meta)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
#.......................................................................................................
|
90
|
+
def print
|
91
|
+
unless @metadata.empty? and @listable_metadata.empty?
|
92
|
+
(@metadata.empty? ? '' : "Not Listable Metadata\n#{stringify_hash(@metadata)}") +
|
93
|
+
(@listable_metadata.empty? ? '' : "Listable Metadata\n#{stringify_hash(@listable_metadata)}")
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
#UserMetadata
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
##########################################################################################################
|
102
|
+
class SystemMetadata < Result
|
103
|
+
|
104
|
+
#.......................................................................................................
|
105
|
+
def initialize(args)
|
106
|
+
super
|
107
|
+
if args[:result]
|
108
|
+
@metadata = extract_header(args, :x_emc_meta)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
#.......................................................................................................
|
113
|
+
def print
|
114
|
+
stringify_hash(@metadata)
|
115
|
+
end
|
116
|
+
|
117
|
+
#SystemMetadata
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
##########################################################################################################
|
122
|
+
class Tags < Result
|
123
|
+
|
124
|
+
#.......................................................................................................
|
125
|
+
def initialize(args)
|
126
|
+
super
|
127
|
+
if args[:result]
|
128
|
+
@listable_tags = args[:result].headers[:x_emc_listable_tags]
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
#.......................................................................................................
|
133
|
+
def print
|
134
|
+
stringify_array(@listable_tags)
|
135
|
+
end
|
136
|
+
|
137
|
+
#Metadata
|
138
|
+
end
|
139
|
+
|
140
|
+
##########################################################################################################
|
141
|
+
class Acl < Result
|
142
|
+
|
143
|
+
#.......................................................................................................
|
144
|
+
def initialize(args)
|
145
|
+
super
|
146
|
+
if args[:result]
|
147
|
+
@user_acl = extract_header(args, :x_emc_useracl)
|
148
|
+
@group_acl = extract_header(args, :x_emc_groupacl)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
#.......................................................................................................
|
153
|
+
def print
|
154
|
+
"User ACL\n#{stringify_hash(@user_acl)}Group ACL\n#{stringify_hash(@group_acl)}"
|
155
|
+
end
|
156
|
+
|
157
|
+
#Acl
|
158
|
+
end
|
159
|
+
|
160
|
+
##########################################################################################################
|
161
|
+
class Versions < Result
|
162
|
+
|
163
|
+
#.......................................................................................................
|
164
|
+
def initialize(args)
|
165
|
+
super
|
166
|
+
if args[:result]
|
167
|
+
@versions = REXML::Document.new(args[:result].net_http_res.body).root
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
#.......................................................................................................
|
172
|
+
def print
|
173
|
+
poids = oids
|
174
|
+
poids.inject("") {|r,o| r += " #{o}\n"} unless poids.empty?
|
175
|
+
end
|
176
|
+
|
177
|
+
private
|
178
|
+
|
179
|
+
#.......................................................................................................
|
180
|
+
def oids
|
181
|
+
@versions.elements.to_a('ObjectID').map{|o| o.text}
|
182
|
+
end
|
183
|
+
|
184
|
+
#Acl
|
185
|
+
end
|
186
|
+
|
187
|
+
|
188
|
+
##########################################################################################################
|
189
|
+
class StorageObjectList < Result
|
190
|
+
|
191
|
+
#.......................................................................................................
|
192
|
+
def initialize(args)
|
193
|
+
super
|
194
|
+
if args[:result]
|
195
|
+
@objs = REXML::Document.new(args[:result].net_http_res.body).root
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
#.......................................................................................................
|
200
|
+
def print
|
201
|
+
ols = objs
|
202
|
+
oid = oids(ols)
|
203
|
+
sys_meta = metadata(ols, 'SystemMetadataList')
|
204
|
+
user_meta = metadata(ols, 'UserMetadataList', true)
|
205
|
+
unless sys_meta.empty?
|
206
|
+
fmt = "%-40s %-10s %-s\n"
|
207
|
+
fmt % ['Metadata', 'Type', 'OID'] +
|
208
|
+
sys_meta.inject("") do |r,e|
|
209
|
+
t = e['type']
|
210
|
+
r += fmt % [user_meta.shift.keys.join(','), (t.eql?('regular') ? 'file' : t), e['objectid']]
|
211
|
+
end
|
212
|
+
else
|
213
|
+
"OID\n" + oid.join("\n").chomp unless oid.empty?
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
private
|
218
|
+
|
219
|
+
#.......................................................................................................
|
220
|
+
def oids(ols)
|
221
|
+
ols.map{|o| o.elements.to_a('ObjectID').first.text}
|
222
|
+
end
|
223
|
+
|
224
|
+
#.......................................................................................................
|
225
|
+
def metadata(ols, tag, is_listable=false)
|
226
|
+
meta = ols.map{|o| o.elements.to_a(tag)}
|
227
|
+
meta.map{|a| a.empty? ? nil : a.first.elements.to_a.inject({}) do |h,s|
|
228
|
+
a = extract_attrs(s, is_listable)
|
229
|
+
a.nil? ? h : h.update(a)
|
230
|
+
end}.compact
|
231
|
+
end
|
232
|
+
|
233
|
+
#.......................................................................................................
|
234
|
+
def extract_attrs(a,is_listable)
|
235
|
+
add_item = if is_listable
|
236
|
+
a.elements.to_a('Listable').first.text.eql?('true')
|
237
|
+
else; true; end
|
238
|
+
add_item ? {a.elements.to_a('Name').first.text => a.elements.to_a('Value').first.text} : nil
|
239
|
+
end
|
240
|
+
|
241
|
+
#.......................................................................................................
|
242
|
+
def objs
|
243
|
+
@objs.nil? ? [] : @objs.elements.to_a('Object')
|
244
|
+
end
|
245
|
+
|
246
|
+
#SorageObjectList
|
247
|
+
end
|
248
|
+
|
249
|
+
##########################################################################################################
|
250
|
+
class Download < Result
|
251
|
+
|
252
|
+
#.......................................................................................................
|
253
|
+
def initialize(args)
|
254
|
+
super
|
255
|
+
if args[:result]
|
256
|
+
@content_type = args[:result].headers[:content_type]
|
257
|
+
@body = args[:result].net_http_res.body
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
#.......................................................................................................
|
262
|
+
def print
|
263
|
+
if @content_type.eql?('text/xml')
|
264
|
+
print_directory_entries
|
265
|
+
else
|
266
|
+
@body
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
private
|
271
|
+
|
272
|
+
#.......................................................................................................
|
273
|
+
def directory_entries
|
274
|
+
REXML::Document.new(@body).root.elements.to_a.first.elements.to_a.map do |i|
|
275
|
+
i.elements.inject(nil, {}){|h,e| h.update(e.name => e.text)}
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
#.......................................................................................................
|
280
|
+
def print_directory_entries
|
281
|
+
dir_list = directory_entries
|
282
|
+
unless dir_list.empty?
|
283
|
+
fmt = "%-30s %-10s %-s\n"
|
284
|
+
fmt % ['Name', 'Type', 'OID'] +
|
285
|
+
dir_list.inject("") do |r,e|
|
286
|
+
t = e['FileType']
|
287
|
+
r += fmt % [e['Filename'], (t.eql?('regular') ? 'file' : t), e['ObjectID']]
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
#.......................................................................................................
|
293
|
+
def octet_stream
|
294
|
+
@body
|
295
|
+
end
|
296
|
+
|
297
|
+
#RetrievedFile
|
298
|
+
end
|
299
|
+
|
300
|
+
##########################################################################################################
|
301
|
+
class RequestError
|
302
|
+
|
303
|
+
#.......................................................................................................
|
304
|
+
def initialize(err)
|
305
|
+
@err = REXML::Document.new(err.response.body).root
|
306
|
+
end
|
307
|
+
|
308
|
+
#.......................................................................................................
|
309
|
+
def code
|
310
|
+
@err.elements.to_a('Code').first.text
|
311
|
+
end
|
312
|
+
|
313
|
+
#.......................................................................................................
|
314
|
+
def message
|
315
|
+
@err.elements.to_a('Message').first.text
|
316
|
+
end
|
317
|
+
|
318
|
+
#.......................................................................................................
|
319
|
+
def print
|
320
|
+
@err.nil? ? '' : "#{code}: #{message}"
|
321
|
+
end
|
322
|
+
|
323
|
+
#RequestError
|
324
|
+
end
|
325
|
+
|
326
|
+
|
327
|
+
##########################################################################################################
|
328
|
+
class ShareableUrl < Result
|
329
|
+
|
330
|
+
#.......................................................................................................
|
331
|
+
def initialize(args)
|
332
|
+
super
|
333
|
+
@url = args[:result]
|
334
|
+
end
|
335
|
+
|
336
|
+
#.......................................................................................................
|
337
|
+
def print
|
338
|
+
@url
|
339
|
+
end
|
340
|
+
|
341
|
+
#SystemMetadata
|
342
|
+
end
|
343
|
+
|
344
|
+
#Synaptic4r
|
345
|
+
end
|
data/synaptic4r.gemspec
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{synaptic4r}
|
5
|
+
s.version = "0.1.4"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["troystribling-att"]
|
9
|
+
s.date = %q{2009-08-24}
|
10
|
+
s.default_executable = %q{synrest}
|
11
|
+
s.email = %q{troy.stribling@usi.com}
|
12
|
+
s.executables = ["synrest"]
|
13
|
+
s.extra_rdoc_files = [
|
14
|
+
"LICENSE",
|
15
|
+
"README.rdoc"
|
16
|
+
]
|
17
|
+
s.files = [
|
18
|
+
".document",
|
19
|
+
".gitignore",
|
20
|
+
"LICENSE",
|
21
|
+
"README.rdoc",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"bin/synrest",
|
25
|
+
"lib/synaptic4r.rb",
|
26
|
+
"lib/synaptic4r/client.rb",
|
27
|
+
"lib/synaptic4r/help.rb",
|
28
|
+
"lib/synaptic4r/request.rb",
|
29
|
+
"lib/synaptic4r/rest.rb",
|
30
|
+
"lib/synaptic4r/result.rb",
|
31
|
+
"synaptic4r.gemspec"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/troystribling-att/synaptic4r}
|
34
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.3.4}
|
37
|
+
s.summary = %q{CLI and Ruby REST Client for ATT Synaptic Storage}
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
41
|
+
s.specification_version = 3
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
44
|
+
s.add_runtime_dependency(%q<rake>, [">= 0.8.3"])
|
45
|
+
s.add_runtime_dependency(%q<rest-client>, [">= 1.0.2"])
|
46
|
+
else
|
47
|
+
s.add_dependency(%q<rake>, [">= 0.8.3"])
|
48
|
+
s.add_dependency(%q<rest-client>, [">= 1.0.2"])
|
49
|
+
end
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<rake>, [">= 0.8.3"])
|
52
|
+
s.add_dependency(%q<rest-client>, [">= 1.0.2"])
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: attsynaptic-synaptic4r
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- troystribling-att
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-24 00:00:00 -07:00
|
13
|
+
default_executable: synrest
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rake
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.8.3
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rest-client
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.2
|
34
|
+
version:
|
35
|
+
description:
|
36
|
+
email: troy.stribling@usi.com
|
37
|
+
executables:
|
38
|
+
- synrest
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- .gitignore
|
47
|
+
- LICENSE
|
48
|
+
- README.rdoc
|
49
|
+
- Rakefile
|
50
|
+
- VERSION
|
51
|
+
- bin/synrest
|
52
|
+
- lib/synaptic4r.rb
|
53
|
+
- lib/synaptic4r/client.rb
|
54
|
+
- lib/synaptic4r/help.rb
|
55
|
+
- lib/synaptic4r/request.rb
|
56
|
+
- lib/synaptic4r/rest.rb
|
57
|
+
- lib/synaptic4r/result.rb
|
58
|
+
- synaptic4r.gemspec
|
59
|
+
has_rdoc: false
|
60
|
+
homepage: http://github.com/troystribling-att/synaptic4r
|
61
|
+
licenses:
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options:
|
64
|
+
- --charset=UTF-8
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
version:
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.3.5
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: CLI and Ruby REST Client for ATT Synaptic Storage
|
86
|
+
test_files: []
|
87
|
+
|