synaptic4r 0.1.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.
@@ -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/lib/synaptic4r.rb ADDED
@@ -0,0 +1,15 @@
1
+ ####-----------------------------------------------------------------------------------------------------
2
+ require 'base64'
3
+ require 'time'
4
+ require 'uri'
5
+ require 'openssl'
6
+ require 'rexml/document'
7
+
8
+ require 'rubygems'
9
+ require 'rest_client'
10
+
11
+ require 'synaptic4r/help'
12
+ require 'synaptic4r/result'
13
+ require 'synaptic4r/rest'
14
+ require 'synaptic4r/client'
15
+ require 'synaptic4r/request'
@@ -0,0 +1,51 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{synaptic4r}
5
+ s.version = "0.1.5"
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-26}
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/attsynaptic/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<rest-client>, [">= 1.0.2"])
45
+ else
46
+ s.add_dependency(%q<rest-client>, [">= 1.0.2"])
47
+ end
48
+ else
49
+ s.add_dependency(%q<rest-client>, [">= 1.0.2"])
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: synaptic4r
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ platform: ruby
6
+ authors:
7
+ - troystribling-att
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-26 00:00:00 -04:00
13
+ default_executable: synrest
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rest-client
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.2
24
+ version:
25
+ description:
26
+ email: troy.stribling@usi.com
27
+ executables:
28
+ - synrest
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - bin/synrest
42
+ - lib/synaptic4r.rb
43
+ - lib/synaptic4r/client.rb
44
+ - lib/synaptic4r/help.rb
45
+ - lib/synaptic4r/request.rb
46
+ - lib/synaptic4r/rest.rb
47
+ - lib/synaptic4r/result.rb
48
+ - synaptic4r.gemspec
49
+ has_rdoc: true
50
+ homepage: http://github.com/attsynaptic/synaptic4r
51
+ licenses: []
52
+
53
+ post_install_message:
54
+ rdoc_options:
55
+ - --charset=UTF-8
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ requirements: []
71
+
72
+ rubyforge_project:
73
+ rubygems_version: 1.3.4
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: CLI and Ruby REST Client for ATT Synaptic Storage
77
+ test_files: []
78
+