raws 0.0.8 → 0.0.9
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.
- data/README.rdoc +12 -4
- data/Rakefile +3 -1
- data/VERSION +1 -1
- data/lib/raws/http/ht2p.rb +83 -0
- data/lib/raws/http/typhoeus.rb +92 -0
- data/lib/raws/http.rb +25 -0
- data/lib/raws/s3/adapter.rb +187 -75
- data/lib/raws/s3/model.rb +71 -0
- data/lib/raws/s3/s3object.rb +3 -0
- data/lib/raws/s3.rb +115 -5
- data/lib/raws/sdb/adapter.rb +78 -13
- data/lib/raws/sdb/model.rb +1 -1
- data/lib/raws/sdb.rb +6 -0
- data/lib/raws/sqs/adapter.rb +90 -28
- data/lib/raws/sqs.rb +6 -0
- data/lib/raws/xml/nokogiri.rb +48 -0
- data/lib/raws/xml.rb +28 -0
- data/lib/raws.rb +30 -131
- data/spec/raws/s3_spec.rb +212 -21
- data/spec/raws/sdb_spec.rb +1 -1
- data/spec/raws/sqs_spec.rb +16 -7
- data/spec/raws_spec.rb +13 -29
- data/spec/spec_helper.rb +15 -0
- metadata +22 -4
data/lib/raws/s3.rb
CHANGED
@@ -1,21 +1,131 @@
|
|
1
1
|
class RAWS::S3
|
2
|
+
autoload :S3Object, 'raws/s3/s3object'
|
2
3
|
autoload :Adapter, 'raws/s3/adapter'
|
4
|
+
autoload :Model, 'raws/s3/model'
|
3
5
|
|
4
6
|
class << self
|
5
|
-
|
7
|
+
include Enumerable
|
8
|
+
|
9
|
+
attr_writer :http
|
10
|
+
|
11
|
+
def http
|
12
|
+
@http ||= RAWS.http
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_bucket(bucket_name, location=nil, header={})
|
16
|
+
Adapter.put_bucket(bucket_name, location, header)
|
6
17
|
end
|
7
18
|
|
8
|
-
def delete_bucket(bucket_name)
|
19
|
+
def delete_bucket(bucket_name, force=nil)
|
20
|
+
filter(bucket_name).each do |val|
|
21
|
+
delete(bucket_name, val['Key'])
|
22
|
+
end if force == :force
|
23
|
+
|
24
|
+
Adapter.delete_bucket(bucket_name)
|
9
25
|
end
|
10
26
|
|
11
|
-
def
|
12
|
-
Adapter.get_service
|
27
|
+
def owner
|
28
|
+
@owner ||= Adapter.get_service.doc['ListAllMyBucketsResult']['Owner']
|
13
29
|
end
|
14
30
|
|
15
|
-
def
|
31
|
+
def buckets
|
32
|
+
begin
|
33
|
+
response = Adapter.get_service.doc['ListAllMyBucketsResult']
|
34
|
+
@owner ||= response['Owner']
|
35
|
+
response['Buckets']['Bucket'] || []
|
36
|
+
end.map do |val|
|
37
|
+
self[val['Name']]
|
38
|
+
end
|
16
39
|
end
|
17
40
|
|
18
41
|
def [](bucket_name)
|
42
|
+
@cache ||= {}
|
43
|
+
@cache[bucket_name] ||= self.new(bucket_name)
|
44
|
+
end
|
45
|
+
|
46
|
+
def location(bucket_name)
|
47
|
+
response = Adapter.get_bucket_location(bucket_name)
|
48
|
+
location = response.doc['LocationConstraint']
|
49
|
+
location.empty? ? 'US' : location
|
50
|
+
end
|
51
|
+
|
52
|
+
def filter(bucket_name, params={})
|
53
|
+
begin
|
54
|
+
response = Adapter.get_bucket(bucket_name, params)
|
55
|
+
response.doc['ListBucketResult']['Contents'] || []
|
56
|
+
end.map do |val|
|
57
|
+
val
|
58
|
+
end
|
59
|
+
end
|
60
|
+
alias :all :filter
|
61
|
+
|
62
|
+
def put(bucket_name, name, header, &block)
|
63
|
+
Adapter.put_object(bucket_name, name, header, &block)
|
19
64
|
end
|
65
|
+
|
66
|
+
def copy(src_bucket, src_name, dest_bucket, dest_name, header={})
|
67
|
+
Adapter.copy_object(src_bucket, src_name, dest_bucket, dest_name, header)
|
68
|
+
end
|
69
|
+
|
70
|
+
def get(bucket_name, name, params={}, &block)
|
71
|
+
Adapter.get_object(bucket_name, name, params, &block)
|
72
|
+
end
|
73
|
+
|
74
|
+
def head(bucket_name, name)
|
75
|
+
Adapter.head_object(bucket_name, name)
|
76
|
+
end
|
77
|
+
|
78
|
+
def delete(bucket_name, name)
|
79
|
+
Adapter.delete_object(bucket_name, name)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
attr_reader :bucket_name, :creation_date
|
84
|
+
alias :name :bucket_name
|
85
|
+
|
86
|
+
def initialize(bucket_name, creation_date=nil)
|
87
|
+
@bucket_name = bucket_name
|
88
|
+
@creation_date = Time.parse(creation_date) if creation_date
|
89
|
+
end
|
90
|
+
|
91
|
+
def create_bucket(location=nil)
|
92
|
+
self.class.create_bucket(@bucket_name, location)
|
93
|
+
end
|
94
|
+
|
95
|
+
def delete_bucket(force=nil)
|
96
|
+
self.class.delete_bucket(@bucket_name, force)
|
97
|
+
end
|
98
|
+
|
99
|
+
def location
|
100
|
+
self.class.location(@bucket_name)
|
101
|
+
end
|
102
|
+
|
103
|
+
def filter(params={})
|
104
|
+
self.class.filter(@bucket_name, params)
|
105
|
+
end
|
106
|
+
alias :all :filter
|
107
|
+
|
108
|
+
def put(name, header, &block)
|
109
|
+
self.class.put(@bucket_name, name, header, &block)
|
110
|
+
end
|
111
|
+
|
112
|
+
def copy(name, dest_bucket, dest_name)
|
113
|
+
self.class.copy(@bucket_name, name, dest_bucket, dest_name)
|
114
|
+
end
|
115
|
+
|
116
|
+
def get(name, header={}, &block)
|
117
|
+
self.class.get(@bucket_name, name, header, &block)
|
118
|
+
end
|
119
|
+
|
120
|
+
def head(name)
|
121
|
+
self.class.head(@bucket_name, name)
|
122
|
+
end
|
123
|
+
|
124
|
+
def delete(name)
|
125
|
+
self.class.delete(@bucket_name, name)
|
126
|
+
end
|
127
|
+
|
128
|
+
def <=>(a)
|
129
|
+
bucket_name <=> a.bucket_name
|
20
130
|
end
|
21
131
|
end
|
data/lib/raws/sdb/adapter.rb
CHANGED
@@ -2,16 +2,81 @@ class RAWS::SDB::Adapter
|
|
2
2
|
module Adapter20090415
|
3
3
|
URI = 'https://sdb.amazonaws.com/'
|
4
4
|
PARAMS = {'Version' => '2009-04-15'}
|
5
|
-
KEYWORDS = %w'
|
5
|
+
KEYWORDS = %w'
|
6
|
+
or and not from where select like null is order by asc desc in between
|
7
|
+
intersection limit every
|
8
|
+
'
|
6
9
|
REXP_NAME = /^[a-zA-Z_$]/
|
7
10
|
|
11
|
+
def pack_attrs(attrs, replaces=nil, prefix=nil)
|
12
|
+
params = {}
|
13
|
+
|
14
|
+
i = 1
|
15
|
+
attrs.each do |key, val|
|
16
|
+
if !replaces.nil? && replaces.include?(key)
|
17
|
+
params["#{prefix}Attribute.#{i}.Replace"] = 'true'
|
18
|
+
end
|
19
|
+
|
20
|
+
if val.is_a? Array
|
21
|
+
val.each do |v|
|
22
|
+
params["#{prefix}Attribute.#{i}.Name"] = key
|
23
|
+
params["#{prefix}Attribute.#{i}.Value"] = v
|
24
|
+
i += 1
|
25
|
+
end
|
26
|
+
else
|
27
|
+
params["#{prefix}Attribute.#{i}.Name"] = key
|
28
|
+
params["#{prefix}Attribute.#{i}.Value"] = val
|
29
|
+
i += 1
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
params
|
34
|
+
end
|
35
|
+
|
36
|
+
def sign(method, base_uri, params)
|
37
|
+
path = {
|
38
|
+
'AWSAccessKeyId' => RAWS.aws_access_key_id,
|
39
|
+
'SignatureMethod' => 'HmacSHA256',
|
40
|
+
'SignatureVersion' => '2',
|
41
|
+
'Timestamp' => Time.now.utc.iso8601
|
42
|
+
}.merge(params).map do |key, val|
|
43
|
+
"#{RAWS.escape(key)}=#{RAWS.escape(val)}"
|
44
|
+
end.sort.join('&')
|
45
|
+
|
46
|
+
uri = ::URI.parse(base_uri)
|
47
|
+
"#{path}&Signature=" << RAWS.escape(
|
48
|
+
[
|
49
|
+
::OpenSSL::HMAC.digest(
|
50
|
+
::OpenSSL::Digest::SHA256.new,
|
51
|
+
RAWS.aws_secret_access_key,
|
52
|
+
"#{method.upcase}\n#{uri.host.downcase}\n#{uri.path}\n#{path}"
|
53
|
+
)
|
54
|
+
].pack('m').strip
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
def connect(method, base_uri, params, parser={})
|
59
|
+
doc = nil
|
60
|
+
|
61
|
+
RAWS::SDB.http.connect(
|
62
|
+
"#{base_uri}?#{sign(method, base_uri, params)}"
|
63
|
+
) do |request|
|
64
|
+
request.method = method
|
65
|
+
response = request.send
|
66
|
+
doc = response.parse(parser)
|
67
|
+
response
|
68
|
+
end
|
69
|
+
|
70
|
+
doc
|
71
|
+
end
|
72
|
+
|
8
73
|
def create_domain(domain_name)
|
9
74
|
params = {
|
10
75
|
'Action' => 'CreateDomain',
|
11
76
|
'DomainName' => domain_name
|
12
77
|
}
|
13
78
|
|
14
|
-
|
79
|
+
connect('GET', URI, PARAMS.merge(params))
|
15
80
|
end
|
16
81
|
|
17
82
|
def delete_domain(domain_name)
|
@@ -20,7 +85,7 @@ class RAWS::SDB::Adapter
|
|
20
85
|
'DomainName' => domain_name
|
21
86
|
}
|
22
87
|
|
23
|
-
|
88
|
+
connect('GET', URI, PARAMS.merge(params))
|
24
89
|
end
|
25
90
|
|
26
91
|
def domain_metadata(domain_name)
|
@@ -29,7 +94,7 @@ class RAWS::SDB::Adapter
|
|
29
94
|
'DomainName' => domain_name
|
30
95
|
}
|
31
96
|
|
32
|
-
|
97
|
+
connect('GET', URI, PARAMS.merge(params))
|
33
98
|
end
|
34
99
|
|
35
100
|
def list_domains(next_token=nil, max_num=nil, &block)
|
@@ -37,7 +102,7 @@ class RAWS::SDB::Adapter
|
|
37
102
|
params['NextToken'] = next_token if next_token
|
38
103
|
params['MaxNumberOfDomains'] = max_num if max_num
|
39
104
|
|
40
|
-
|
105
|
+
connect('GET', URI, PARAMS.merge(params), :multiple => %w'DomainName')
|
41
106
|
end
|
42
107
|
|
43
108
|
def get_attributes(domain_name, item_name, *attrs)
|
@@ -53,7 +118,7 @@ class RAWS::SDB::Adapter
|
|
53
118
|
i += 1
|
54
119
|
end
|
55
120
|
|
56
|
-
|
121
|
+
connect(
|
57
122
|
'GET',
|
58
123
|
URI,
|
59
124
|
PARAMS.merge(params),
|
@@ -68,9 +133,9 @@ class RAWS::SDB::Adapter
|
|
68
133
|
'DomainName' => domain_name,
|
69
134
|
'ItemName' => item_name
|
70
135
|
}
|
71
|
-
params.merge!(
|
136
|
+
params.merge!(pack_attrs(attrs, replaces))
|
72
137
|
|
73
|
-
|
138
|
+
connect('GET', URI, PARAMS.merge(params))
|
74
139
|
end
|
75
140
|
|
76
141
|
def batch_put_attributes(domain_name, items={}, replaces={})
|
@@ -82,11 +147,11 @@ class RAWS::SDB::Adapter
|
|
82
147
|
i = 0
|
83
148
|
items.each do |key, attrs|
|
84
149
|
params["Item.#{i}.ItemName"] = key
|
85
|
-
params.merge!(
|
150
|
+
params.merge!(pack_attrs(attrs, replaces[key], "Item.#{i}."))
|
86
151
|
i += 1
|
87
152
|
end
|
88
153
|
|
89
|
-
|
154
|
+
connect('GET', URI, PARAMS.merge(params))
|
90
155
|
end
|
91
156
|
|
92
157
|
def delete_attributes(domain_name, item_name, attrs={})
|
@@ -95,9 +160,9 @@ class RAWS::SDB::Adapter
|
|
95
160
|
'DomainName' => domain_name,
|
96
161
|
'ItemName' => item_name
|
97
162
|
}
|
98
|
-
params.merge!(
|
163
|
+
params.merge!(pack_attrs(attrs))
|
99
164
|
|
100
|
-
|
165
|
+
connect('GET', URI, PARAMS.merge(params))
|
101
166
|
end
|
102
167
|
|
103
168
|
def quote(val)
|
@@ -125,7 +190,7 @@ class RAWS::SDB::Adapter
|
|
125
190
|
}
|
126
191
|
params['NextToken'] = next_token if next_token
|
127
192
|
|
128
|
-
|
193
|
+
connect(
|
129
194
|
'GET',
|
130
195
|
URI,
|
131
196
|
PARAMS.merge(params),
|
data/lib/raws/sdb/model.rb
CHANGED
data/lib/raws/sdb.rb
CHANGED
data/lib/raws/sqs/adapter.rb
CHANGED
@@ -3,6 +3,84 @@ class RAWS::SQS::Adapter
|
|
3
3
|
URI = 'https://queue.amazonaws.com/'
|
4
4
|
PARAMS = {'Version' => '2009-02-01'}
|
5
5
|
|
6
|
+
def pack_attrs(attrs)
|
7
|
+
params = {}
|
8
|
+
|
9
|
+
if(attrs.size == 1)
|
10
|
+
params["AttributeName"] = attrs.first
|
11
|
+
else
|
12
|
+
i = 1
|
13
|
+
attrs.each do |val|
|
14
|
+
params["AttributeName.#{i}"] = val
|
15
|
+
i += 1
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
params
|
20
|
+
end
|
21
|
+
|
22
|
+
def pack_nv_attrs(attrs, replaces=nil, prefix=nil)
|
23
|
+
params = {}
|
24
|
+
|
25
|
+
i = 1
|
26
|
+
attrs.each do |key, val|
|
27
|
+
if !replaces.nil? && replaces.include?(key)
|
28
|
+
params["#{prefix}Attribute.#{i}.Replace"] = 'true'
|
29
|
+
end
|
30
|
+
|
31
|
+
if val.is_a? Array
|
32
|
+
val.each do |v|
|
33
|
+
params["#{prefix}Attribute.#{i}.Name"] = key
|
34
|
+
params["#{prefix}Attribute.#{i}.Value"] = v
|
35
|
+
i += 1
|
36
|
+
end
|
37
|
+
else
|
38
|
+
params["#{prefix}Attribute.#{i}.Name"] = key
|
39
|
+
params["#{prefix}Attribute.#{i}.Value"] = val
|
40
|
+
i += 1
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
params
|
45
|
+
end
|
46
|
+
|
47
|
+
def sign(method, base_uri, params)
|
48
|
+
path = {
|
49
|
+
'AWSAccessKeyId' => RAWS.aws_access_key_id,
|
50
|
+
'SignatureMethod' => 'HmacSHA256',
|
51
|
+
'SignatureVersion' => '2',
|
52
|
+
'Timestamp' => Time.now.utc.iso8601
|
53
|
+
}.merge(params).map do |key, val|
|
54
|
+
"#{RAWS.escape(key)}=#{RAWS.escape(val)}"
|
55
|
+
end.sort.join('&')
|
56
|
+
|
57
|
+
uri = ::URI.parse(base_uri)
|
58
|
+
"#{path}&Signature=" << RAWS.escape(
|
59
|
+
[
|
60
|
+
::OpenSSL::HMAC.digest(
|
61
|
+
::OpenSSL::Digest::SHA256.new,
|
62
|
+
RAWS.aws_secret_access_key,
|
63
|
+
"#{method.upcase}\n#{uri.host.downcase}\n#{uri.path}\n#{path}"
|
64
|
+
)
|
65
|
+
].pack('m').strip
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
def connect(method, base_uri, params, parser={})
|
70
|
+
doc = nil
|
71
|
+
|
72
|
+
RAWS::SQS.http.connect(
|
73
|
+
"#{base_uri}?#{sign(method, base_uri, params)}"
|
74
|
+
) do |request|
|
75
|
+
request.method = method
|
76
|
+
response = request.send
|
77
|
+
doc = response.parse(parser)
|
78
|
+
response
|
79
|
+
end
|
80
|
+
|
81
|
+
doc
|
82
|
+
end
|
83
|
+
|
6
84
|
def create_queue(queue_name, timeout=nil)
|
7
85
|
params = {
|
8
86
|
'Action' => 'CreateQueue',
|
@@ -10,36 +88,20 @@ class RAWS::SQS::Adapter
|
|
10
88
|
}
|
11
89
|
params['DefaultVisibilityTimeout'] = timeout if timeout
|
12
90
|
|
13
|
-
|
91
|
+
connect('GET', URI, PARAMS.merge(params))
|
14
92
|
end
|
15
93
|
|
16
94
|
def delete_queue(queue_url)
|
17
95
|
params = {'Action' => 'DeleteQueue'}
|
18
96
|
|
19
|
-
|
97
|
+
connect('GET', queue_url, PARAMS.merge(params))
|
20
98
|
end
|
21
99
|
|
22
100
|
def list_queues(prefix=nil)
|
23
101
|
params = {'Action' => 'ListQueues'}
|
24
102
|
params['QueueNamePrefix'] = prefix if prefix
|
25
103
|
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
def pack_attrs(attrs)
|
30
|
-
params = {}
|
31
|
-
|
32
|
-
if(attrs.size == 1)
|
33
|
-
params["AttributeName"] = attrs.first
|
34
|
-
else
|
35
|
-
i = 1
|
36
|
-
attrs.each do |val|
|
37
|
-
params["AttributeName.#{i}"] = val
|
38
|
-
i += 1
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
params
|
104
|
+
connect('GET', URI, PARAMS.merge(params), 'QueueUrl')
|
43
105
|
end
|
44
106
|
|
45
107
|
def get_queue_attributes(queue_url, *attrs)
|
@@ -50,7 +112,7 @@ class RAWS::SQS::Adapter
|
|
50
112
|
params.merge!(pack_attrs(attrs))
|
51
113
|
end
|
52
114
|
|
53
|
-
|
115
|
+
connect(
|
54
116
|
'GET',
|
55
117
|
queue_url,
|
56
118
|
PARAMS.merge(params),
|
@@ -61,9 +123,9 @@ class RAWS::SQS::Adapter
|
|
61
123
|
|
62
124
|
def set_queue_attributes(queue_url, attrs={})
|
63
125
|
params = {'Action' => 'SetQueueAttributes'}
|
64
|
-
params.merge!(
|
126
|
+
params.merge!(pack_nv_attrs(attrs))
|
65
127
|
|
66
|
-
|
128
|
+
connect('GET', queue_url, PARAMS.merge(params))
|
67
129
|
end
|
68
130
|
|
69
131
|
def send_message(queue_url, msg)
|
@@ -72,7 +134,7 @@ class RAWS::SQS::Adapter
|
|
72
134
|
'MessageBody' => msg
|
73
135
|
}
|
74
136
|
|
75
|
-
|
137
|
+
connect('GET', queue_url, PARAMS.merge(params))
|
76
138
|
end
|
77
139
|
|
78
140
|
def receive_message(queue_url, limit=nil, timeout=nil, *attrs)
|
@@ -81,7 +143,7 @@ class RAWS::SQS::Adapter
|
|
81
143
|
params['VisibilityTimeout'] = timeout if timeout
|
82
144
|
params.merge!(pack_attrs(attrs))
|
83
145
|
|
84
|
-
|
146
|
+
connect(
|
85
147
|
'GET',
|
86
148
|
queue_url,
|
87
149
|
PARAMS.merge(params),
|
@@ -97,7 +159,7 @@ class RAWS::SQS::Adapter
|
|
97
159
|
'VisibilityTimeout' => timeout
|
98
160
|
}
|
99
161
|
|
100
|
-
|
162
|
+
connect('GET', queue_url, PARAMS.merge(params))
|
101
163
|
end
|
102
164
|
|
103
165
|
def delete_message(queue_url, receipt_handle)
|
@@ -106,7 +168,7 @@ class RAWS::SQS::Adapter
|
|
106
168
|
'ReceiptHandle' => receipt_handle
|
107
169
|
}
|
108
170
|
|
109
|
-
|
171
|
+
connect('GET', queue_url, PARAMS.merge(params))
|
110
172
|
end
|
111
173
|
|
112
174
|
def pack_permission(params)
|
@@ -131,7 +193,7 @@ class RAWS::SQS::Adapter
|
|
131
193
|
}
|
132
194
|
params.merge!(pack_permission(permission))
|
133
195
|
|
134
|
-
|
196
|
+
connect('GET', queue_url, PARAMS.merge(params))
|
135
197
|
end
|
136
198
|
|
137
199
|
def remove_permission(queue_url, label)
|
@@ -140,7 +202,7 @@ class RAWS::SQS::Adapter
|
|
140
202
|
'Label' => label
|
141
203
|
}
|
142
204
|
|
143
|
-
|
205
|
+
connect('GET', queue_url, PARAMS.merge(params))
|
144
206
|
end
|
145
207
|
end
|
146
208
|
|
data/lib/raws/sqs.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module RAWS
|
4
|
+
module XML
|
5
|
+
module Nokogiri
|
6
|
+
def self._parse(doc, params={}, ret={})
|
7
|
+
multiple = params[:multiple] || []
|
8
|
+
unpack = params[:unpack] || []
|
9
|
+
|
10
|
+
name = nil
|
11
|
+
doc.children.each do |tag|
|
12
|
+
name = tag.name
|
13
|
+
|
14
|
+
unless ret[name].is_a? Array
|
15
|
+
if ret.key?(name)
|
16
|
+
ret[name] = [ret[name]]
|
17
|
+
elsif multiple.include? name
|
18
|
+
ret[name] = []
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
if tag.child.is_a? ::Nokogiri::XML::Text
|
23
|
+
if ret.key? name
|
24
|
+
ret[name] << tag.content
|
25
|
+
else
|
26
|
+
ret[name] = tag.content
|
27
|
+
end
|
28
|
+
else
|
29
|
+
if ret.key? name
|
30
|
+
ret[name] << {}
|
31
|
+
_parse(tag, params, ret[name].last)
|
32
|
+
else
|
33
|
+
ret[name] = {}
|
34
|
+
_parse(tag, params, ret[name])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
ret[name] = RAWS::XML.unpack_attrs(ret[name]) if unpack.include?(name)
|
39
|
+
|
40
|
+
ret
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.parse(xml, params={})
|
44
|
+
_parse(::Nokogiri::XML.parse(xml), params)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/raws/xml.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module RAWS
|
4
|
+
module XML
|
5
|
+
def self.unpack_attrs(attrs)
|
6
|
+
ret = {}
|
7
|
+
|
8
|
+
if attrs.is_a? Array
|
9
|
+
attrs
|
10
|
+
else
|
11
|
+
[attrs]
|
12
|
+
end.map do |val|
|
13
|
+
name, value = val['Name'], val['Value']
|
14
|
+
|
15
|
+
if ret.key? name
|
16
|
+
ret[name] = [ret[name]] unless ret[name].is_a? Array
|
17
|
+
ret[name] << value
|
18
|
+
else
|
19
|
+
ret[name] = value
|
20
|
+
end
|
21
|
+
end if attrs
|
22
|
+
|
23
|
+
ret
|
24
|
+
end
|
25
|
+
|
26
|
+
autoload :Nokogiri, 'raws/xml/nokogiri'
|
27
|
+
end
|
28
|
+
end
|