forforf-aws-sdb 0.5.0 → 0.5.1

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.
@@ -72,29 +72,31 @@ module AwsSdb
72
72
 
73
73
  @logger.debug { "SELECT EXPRESSION BEFORE CALL: #{query.inspect}" } if @logger.debug?
74
74
  doc = call(:get, params)
75
- item_doc = REXML::XPath.match(doc, '//Item')
75
+
76
76
  items = {}
77
77
  attributes = {}
78
-
78
+
79
79
  #build the result hash
80
- REXML::XPath.each(item_doc, '//Item/Name') do |item_name_doc|
81
- item_name = item_name_doc.text
82
- REXML::XPath.each(item_doc, '//Attribute') do |attrib_doc|
83
- attrib_name = nil
84
- attrib_value = nil
85
- attrib_doc.elements.each('Name') do |name|
86
- attrib_name = CGI.unescape(name.text)
87
- end
88
- attrib_doc.elements.each('Value') do |value|
89
- attrib_value = CGI.unescape(value.text)
90
- end
80
+ REXML::XPath.each(doc, '//Item') do |item_doc|
81
+ item_name = item_doc.elements["Name"].text
82
+
83
+ item_doc.each do |attrib_doc|
84
+ att_name = attrib_doc.elements["Name"]
85
+ att_value = attrib_doc.elements["Value"]
86
+
87
+ next unless (att_name && att_value)
88
+
89
+ attrib_name = CGI.unescape(att_name.text)
90
+ attrib_value = CGI.unescape(att_value.text)
91
+
91
92
  add_value(attributes, attrib_name, attrib_value)
92
93
  end
93
94
  items[item_name] = attributes
95
+ #reset attributes so we don't clobber next item
96
+ attributes = {}
97
+ items
94
98
  end
95
- attr_names = REXML::XPath.match(item_doc, '//Attribute/Name/text()')
96
99
  results = items
97
-
98
100
  return results, REXML::XPath.first(doc, '//NextToken/text()').to_s
99
101
  end
100
102
 
@@ -174,12 +176,9 @@ module AwsSdb
174
176
  'Timestamp' => Time.now.gmtime.iso8601
175
177
  }
176
178
  )
177
-
178
179
  @logger.debug { "CALL: #{method} with #{params.inspect}" } if @logger.debug?
179
180
 
180
-
181
181
  canonical_querystring = build_canonical_query_string(params)
182
-
183
182
  @logger.debug { "CANONICAL: #{canonical_querystring.inspect}" } if @logger.debug?
184
183
 
185
184
  string_to_sign= "GET\n#{URI.parse(@base_url).host}\n/\n#{canonical_querystring}"
@@ -8,7 +8,7 @@ require 'rubygems'
8
8
  require 'uuidtools'
9
9
 
10
10
  include AwsSdb
11
-
11
+ =begin
12
12
  describe Service, "when creating a new domain" do
13
13
  include UUIDTools
14
14
 
@@ -126,7 +126,7 @@ describe Service, "when deleting domains" do
126
126
  }.should_not raise_error
127
127
  end
128
128
  end
129
-
129
+ =end
130
130
  describe Service, "when managing items" do
131
131
  include UUIDTools
132
132
 
@@ -143,10 +143,6 @@ describe Service, "when managing items" do
143
143
  :answer => [ true, 'testing123', 4.2, 42, 420 ]
144
144
  }
145
145
  end
146
-
147
- before(:each) do
148
- #sleep 0.2
149
- end
150
146
 
151
147
  after(:all) do
152
148
  @service.delete_domain(@domain)
@@ -172,16 +168,26 @@ describe Service, "when managing items" do
172
168
  end
173
169
 
174
170
  it "should be able to select all from domain" do
171
+ #add another set of data
172
+ item2 = "test-#{UUID.random_create.to_s}"
173
+ attributes2 = {
174
+ :question => "What are your favorite colors?",
175
+ :favorite_colors => ['red', 'green', 'blue'],
176
+ :answer => 'blue'
177
+ }
178
+
179
+ @service.put_attributes(@domain, item2, attributes2)
180
+
175
181
  query_str = "select * from `#{@domain}`"
176
182
  result = nil
177
- lambda {
183
+ #lambda {
178
184
  result = @service.select(query_str)
179
- }.should_not raise_error
185
+ #}.should_not raise_error
180
186
  result.should_not be_nil
181
187
  result.should_not be_empty
182
188
  result.should_not be_nil
183
189
  result[0].keys.include?(@item).should == true
184
- result[0].values.size.should == 1
190
+ result[0].values.size.should == 2
185
191
  #attribute names
186
192
  result[0].values[0].keys.sort.should == ['answer', 'question']
187
193
  #questions
@@ -190,6 +196,14 @@ describe Service, "when managing items" do
190
196
  result[0].values[0]['answer'].size == 5
191
197
  result[0].values[0]['answer'].include?("42").should == true
192
198
  result[0].values[0]['answer'].include?("testing123").should == true
199
+ #attribute names
200
+ result[0].values[1].keys.sort.should == ['answer', 'favorite_colors', 'question']
201
+ #questions
202
+ result[0].values[1]['question'].should == ['What are your favorite colors?']
203
+ #answers
204
+ result[0].values[1]['favorite_colors'].size == 3
205
+ result[0].values[1]['favorite_colors'].sort.should == ['blue', 'green', 'red']
206
+ result[0].values[1]['answer'].should == ['blue']
193
207
  end
194
208
 
195
209
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 0
9
- version: 0.5.0
8
+ - 1
9
+ version: 0.5.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Tim Dysinger
@@ -48,7 +48,6 @@ files:
48
48
  - lib/aws_sdb/error.rb
49
49
  - lib/aws_sdb/service.rb
50
50
  - spec/spec_helper.rb
51
- - spec/aws_sdb/aws_sdb.log
52
51
  - spec/aws_sdb/service_spec.rb
53
52
  has_rdoc: true
54
53
  homepage: http://github.com/forforf/aws-sdb
@@ -1,13 +0,0 @@
1
- # Logfile created on 2010-12-23 20:04:18 +0000 by logger.rb/25413
2
- D, [2010-12-23T20:04:18.454524 #25893] DEBUG -- : http://sdb.amazonaws.com?Action=DeleteDomain&AWSAccessKeyId=AKIAJZT2KIZFM36DNBVQ&DomainName=&SignatureVersion=1&Timestamp=2010-12-23T20%3A04%3A18Z&Version=2007-11-07&Signature=xCfsCVEy3dpskdJjmkwYfVIQudY%3D
3
- D, [2010-12-23T20:04:18.476771 #25893] DEBUG -- : 400
4
- <?xml version="1.0"?>
5
- <Response><Errors><Error><Code>InvalidParameterValue</Code><Message>Value () for parameter DomainName is invalid. </Message><BoxUsage>0.0055590278</BoxUsage></Error></Errors><RequestID>5ec30ba5-4b3c-f1f7-c1b2-0c65d16c57b9</RequestID></Response>
6
- D, [2010-12-23T20:04:18.479966 #25893] DEBUG -- : http://sdb.amazonaws.com?Action=DeleteDomain&AWSAccessKeyId=AKIAJZT2KIZFM36DNBVQ&DomainName=&SignatureVersion=1&Timestamp=2010-12-23T20%3A04%3A18Z&Version=2007-11-07&Signature=xCfsCVEy3dpskdJjmkwYfVIQudY%3D
7
- D, [2010-12-23T20:04:18.490482 #25893] DEBUG -- : 400
8
- <?xml version="1.0"?>
9
- <Response><Errors><Error><Code>InvalidParameterValue</Code><Message>Value () for parameter DomainName is invalid. </Message><BoxUsage>0.0055590278</BoxUsage></Error></Errors><RequestID>1ec92b8e-0053-2452-0140-015fdefa7f8c</RequestID></Response>
10
- D, [2010-12-23T20:04:18.493872 #25893] DEBUG -- : http://sdb.amazonaws.com?Action=DeleteDomain&AWSAccessKeyId=AKIAJZT2KIZFM36DNBVQ&DomainName=&SignatureVersion=1&Timestamp=2010-12-23T20%3A04%3A18Z&Version=2007-11-07&Signature=xCfsCVEy3dpskdJjmkwYfVIQudY%3D
11
- D, [2010-12-23T20:04:18.507715 #25893] DEBUG -- : 400
12
- <?xml version="1.0"?>
13
- <Response><Errors><Error><Code>InvalidParameterValue</Code><Message>Value () for parameter DomainName is invalid. </Message><BoxUsage>0.0055590278</BoxUsage></Error></Errors><RequestID>756ba7ca-e9f7-e73a-83ed-7d8396498550</RequestID></Response>