dsander-reve 0.0.134 → 0.0.135

Sign up to get free protection for your applications and to get access to all the features.
data/lib/reve.rb CHANGED
@@ -614,15 +614,7 @@ module Reve
614
614
  h = compute_hash(args.merge(:url => @@personal_assets_url))
615
615
  return h if h
616
616
  xml = process_query(nil,opts[:url] || @@personal_assets_url,true,args)
617
- assets = []
618
- xml.search("/eveapi/result/rowset[@name='assets']/row").each do |container|
619
- asset_container = Reve::Classes::AssetContainer.new(container)
620
- container.search("rowset[@name='contents']/row").each do |asset|
621
- asset_container.assets << Reve::Classes::Asset.new(asset)
622
- end
623
- assets << asset_container
624
- end
625
- assets
617
+ self.recur_through_assets(xml.search("/eveapi/result/rowset[@name='assets']/row"))
626
618
  end
627
619
 
628
620
  # Get a list of the Corporate Assets. Pass the characterid of the Corporate member See also assets_list method
@@ -631,17 +623,24 @@ module Reve
631
623
  h = compute_hash(args.merge(:url => @@corporate_assets_url))
632
624
  return h if h
633
625
  xml = process_query(nil,opts[:url] || @@corporate_assets_url,true,args)
626
+ self.recur_through_assets(xml.search("/eveapi/result/rowset[@name='assets']/row"))
627
+ end
628
+
629
+ # Helper method to handle nested assets
630
+ def recur_through_assets(rows)
634
631
  assets = []
635
- xml.search("/eveapi/result/rowset/row").each do |container|
636
- asset_container = Reve::Classes::AssetContainer.new(container)
637
- container.search("rowset[@name='contents']/row").each do |asset|
638
- asset_container.assets << Reve::Classes::Asset.new(asset)
632
+ rows.each do |container|
633
+ unless container.empty?
634
+ asset_container = Reve::Classes::AssetContainer.new(container)
635
+ asset_container.assets = self.recur_through_assets(container.search("/rowset/row"))
636
+ assets << asset_container
637
+ else
638
+ assets << Reve::Classes::Asset.new(container)
639
639
  end
640
- assets << asset_container
641
- end
640
+ end
642
641
  assets
643
642
  end
644
-
643
+
645
644
  # Returns a Character list for the associated key and userid from
646
645
  # http://api.eve-online.com/account/Characters.xml.aspx
647
646
  # See also: Reve::Classes::Character
data/test/test_reve.rb CHANGED
@@ -474,21 +474,22 @@ class TestReve < Test::Unit::TestCase
474
474
  assert_nothing_raised do
475
475
  assets = @api.personal_assets_list
476
476
  end
477
- assert_equal 18, assets.size # 18 single and 1 container
478
- contained_assets = assets.inject([]) { |ass,container| ass << container.assets }.flatten
477
+ assert_equal 19, assets.size # 18 single and 1 container
478
+ contained_assets = assets.select { |ass| ass.instance_of? Reve::Classes::AssetContainer}
479
+
479
480
  assert_equal(1, contained_assets.size) # We have a container it happens to have 1 asset in it
480
481
  contained_assets.each do |asset|
481
- assert_instance_of(Reve::Classes::Asset, asset)
482
+ assert_instance_of(Reve::Classes::AssetContainer, asset)
482
483
  assert_not_nil(asset.item_id)
484
+ assert_not_nil(asset.location_id)
483
485
  assert_not_nil(asset.type_id)
484
486
  assert_not_nil(asset.quantity)
485
487
  assert_not_nil(asset.flag)
486
488
  assert_not_nil(asset.singleton)
487
489
  end
488
- assets.each do |asset|
489
- assert_instance_of(Reve::Classes::AssetContainer, asset)
490
+ assets.select { |ass| ass.instance_of? Reve::Classes::Asset}.each do |asset|
491
+ assert_instance_of(Reve::Classes::Asset, asset)
490
492
  assert_not_nil(asset.item_id)
491
- assert_not_nil(asset.location_id)
492
493
  assert_not_nil(asset.type_id)
493
494
  assert_not_nil(asset.quantity)
494
495
  assert_not_nil(asset.flag)
@@ -739,7 +740,7 @@ class TestReve < Test::Unit::TestCase
739
740
  end
740
741
  end
741
742
  end
742
-
743
+
743
744
  def test_corporate_assets_list_clean
744
745
  assets = nil
745
746
  assert_nothing_raised do
@@ -748,7 +749,30 @@ class TestReve < Test::Unit::TestCase
748
749
  assert_equal 2, assets.size
749
750
  assert assets.all? { |a| a.kind_of?(Reve::Classes::AssetContainer) }
750
751
  end
751
-
752
+
753
+ def test_corporate_assets_list_nesting_clean
754
+ assets = nil
755
+ assert_nothing_raised do
756
+ assets = @api.corporate_assets_list :url => File.join(XML_BASE,'corporate_assets_list_nesting.xml')
757
+ end
758
+
759
+ assert_equal 3, assets.size
760
+ assert assets[0].kind_of?(Reve::Classes::Asset)
761
+ assert assets[1].kind_of?(Reve::Classes::AssetContainer)
762
+ assert assets[2].kind_of?(Reve::Classes::Asset)
763
+
764
+ first_container = assets[1]
765
+ assert_equal 2, first_container.type_id
766
+ assert_equal 2, first_container.assets.size
767
+
768
+ second_container = first_container.assets[0]
769
+ assert_equal 3, second_container.type_id
770
+ assert_equal 1, second_container.assets.size
771
+ assert second_container.assets[0].kind_of?(Reve::Classes::Asset)
772
+
773
+ nested_item = second_container.assets[0]
774
+ assert_equal 640, nested_item.type_id
775
+ end
752
776
  def test_map_jumps_clean
753
777
  Reve::API.map_jumps_url = XML_BASE + 'mapjumps.xml'
754
778
  mapjumps = nil
data/test/xml/assets.xml CHANGED
@@ -3,30 +3,30 @@
3
3
  <currentTime>2007-12-18 18:27:27</currentTime>
4
4
  <result>
5
5
  <rowset columns="itemID,locationID,typeID,quantity,flag,singleton" name="assets" key="itemID">
6
- <row typeid="222" itemid="427545405" singleton="0" quantity="100" flag="4" locationid="60004390">
7
- <row typeid="649" itemid="543447240" singleton="1" quantity="1" flag="4" locationid="60003913">
6
+ <row typeID="222" itemID="427545405" singleton="0" quantity="100" flag="4" locationID="60004390" />
7
+ <row typeID="649" itemID="543447240" singleton="1" quantity="1" flag="4" locationID="60003913">
8
8
  <rowset columns="itemID,typeID,quantity,flag,singleton" name="contents" key="itemID">
9
- <row typeid="11489" itemid="782544272" singleton="1" quantity="1" flag="5">
10
- </row></rowset>
9
+ <row typeID="11489" itemID="782544272" singleton="1" quantity="1" flag="5" />
10
+ </rowset>
11
11
  </row>
12
- </row><row typeid="222" itemid="550639494" singleton="0" quantity="100" flag="4" locationid="60004384">
13
- </row><row typeid="7447" itemid="591233762" singleton="0" quantity="1" flag="4" locationid="60003865">
14
- </row><row typeid="9668" itemid="591233776" singleton="0" quantity="1" flag="4" locationid="60003865">
15
- </row><row typeid="7409" itemid="591233791" singleton="0" quantity="1" flag="4" locationid="60003865">
16
- </row><row typeid="5441" itemid="591233797" singleton="0" quantity="1" flag="4" locationid="60003865">
17
- </row><row typeid="14280" itemid="591233811" singleton="0" quantity="1" flag="4" locationid="60003865">
18
- </row><row typeid="14358" itemid="591233816" singleton="0" quantity="50" flag="4" locationid="60003865">
19
- </row><row typeid="215" itemid="627545204" singleton="0" quantity="1" flag="4" locationid="60002296">
20
- </row><row typeid="530" itemid="673815728" singleton="0" quantity="3" flag="4" locationid="60003865">
21
- </row><row typeid="444" itemid="673815903" singleton="0" quantity="1" flag="4" locationid="60003865">
22
- </row><row typeid="533" itemid="681785163" singleton="0" quantity="1" flag="4" locationid="60003865">
23
- </row><row typeid="11740" itemid="781256936" singleton="0" quantity="1" flag="4" locationid="60003865">
24
- </row><row typeid="11489" itemid="782544130" singleton="1" quantity="1" flag="4" locationid="60003865">
25
- </row><row typeid="51" itemid="1125520018" singleton="1" quantity="1" flag="4" locationid="60014545">
26
- </row><row typeid="602" itemid="1943266444" singleton="0" quantity="1" flag="4" locationid="60003865">
27
- </row><row typeid="12865" itemid="1812312532" singleton="0" quantity="18" flag="4" locationid="60003865">
28
- </row><row typeid="25373" itemid="1711554909" singleton="0" quantity="30" flag="4" locationid="60003865">
29
- </row></rowset>
12
+ <row typeID="222" itemID="550639494" singleton="0" quantity="100" flag="4" locationID="60004384" />
13
+ <row typeID="7447" itemID="591233762" singleton="0" quantity="1" flag="4" locationID="60003865" />
14
+ <row typeID="9668" itemID="591233776" singleton="0" quantity="1" flag="4" locationID="60003865" />
15
+ <row typeID="7409" itemID="591233791" singleton="0" quantity="1" flag="4" locationID="60003865" />
16
+ <row typeID="5441" itemID="591233797" singleton="0" quantity="1" flag="4" locationID="60003865" />
17
+ <row typeID="14280" itemID="591233811" singleton="0" quantity="1" flag="4" locationID="60003865" />
18
+ <row typeID="14358" itemID="591233816" singleton="0" quantity="50" flag="4" locationID="60003865" />
19
+ <row typeID="215" itemID="627545204" singleton="0" quantity="1" flag="4" locationID="60002296" />
20
+ <row typeID="530" itemID="673815728" singleton="0" quantity="3" flag="4" locationID="60003865" />
21
+ <row typeID="444" itemID="673815903" singleton="0" quantity="1" flag="4" locationID="60003865" />
22
+ <row typeID="533" itemID="681785163" singleton="0" quantity="1" flag="4" locationID="60003865" />
23
+ <row typeID="11740" itemID="781256936" singleton="0" quantity="1" flag="4" locationID="60003865" />
24
+ <row typeID="11489" itemID="782544130" singleton="1" quantity="1" flag="4" locationID="60003865" />
25
+ <row typeID="51" itemID="1125520018" singleton="1" quantity="1" flag="4" locationID="60014545" />
26
+ <row typeID="602" itemID="1943266444" singleton="0" quantity="1" flag="4" locationID="60003865" />
27
+ <row typeID="12865" itemID="1812312532" singleton="0" quantity="18" flag="4" locationID="60003865" />
28
+ <row typeID="25373" itemID="1711554909" singleton="0" quantity="30" flag="4" locationID="60003865" />
29
+ </rowset>
30
30
  </result>
31
31
  <cacheduntil>2007-12-19 17:27:27</cacheduntil>
32
32
  </eveapi>
File without changes
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dsander-reve
3
3
  version: !ruby/object:Gem::Version
4
- hash: 275
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 0
9
- - 134
10
- version: 0.0.134
8
+ - 135
9
+ version: 0.0.135
11
10
  platform: ruby
12
11
  authors:
13
12
  - Lisa Seelye
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 7
30
28
  segments:
31
29
  - 0
32
30
  - 6
@@ -187,7 +185,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
187
185
  requirements:
188
186
  - - ">="
189
187
  - !ruby/object:Gem::Version
190
- hash: 3
191
188
  segments:
192
189
  - 0
193
190
  version: "0"
@@ -196,7 +193,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
193
  requirements:
197
194
  - - ">="
198
195
  - !ruby/object:Gem::Version
199
- hash: 3
200
196
  segments:
201
197
  - 0
202
198
  version: "0"