Class: AMEE::Admin::ItemDefinitionList
- Inherits:
-
Array
- Object
- Array
- AMEE::Admin::ItemDefinitionList
- Defined in:
- lib/amee/item_definition.rb
Instance Attribute Summary collapse
-
#pager ⇒ Object
readonly
Returns the value of attribute pager.
Instance Method Summary collapse
-
#initialize(connection, options = {}) ⇒ ItemDefinitionList
constructor
A new instance of ItemDefinitionList.
Constructor Details
#initialize(connection, options = {}) ⇒ ItemDefinitionList
Returns a new instance of ItemDefinitionList.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/amee/item_definition.rb', line 6 def initialize(connection, = {}) # Load data from path response = connection.get('/definitions/itemDefinitions', ).body # Parse data from response if response.is_json? # Read JSON doc = JSON.parse(response) @pager = AMEE::Pager.from_json(doc['pager']) doc['itemDefinitions'].each do |p| data = {} data[:uid] = p['uid'] data[:name] = p['name'] # Create ItemDefinition item_definition = ItemDefinition.new(data) # Store in array self << item_definition end else # Read XML doc = REXML::Document.new(response) @pager = AMEE::Pager.from_xml(REXML::XPath.first(doc, '/Resources/ItemDefinitionsResource/Pager')) REXML::XPath.each(doc, '/Resources/ItemDefinitionsResource/ItemDefinitions/ItemDefinition') do |p| data = {} data[:uid] = p.attributes['uid'].to_s data[:name] = p.elements['Name'].text || data[:uid] # Create ItemDefinition item_definition = ItemDefinition.new(data) # Store connection in ItemDefinition object item_definition.connection = connection # Store in array self << item_definition end end rescue raise AMEE::BadData.new("Couldn't load ItemDefinition list.\n#{response}") end |
Instance Attribute Details
#pager ⇒ Object (readonly)
Returns the value of attribute pager.
43 44 45 |
# File 'lib/amee/item_definition.rb', line 43 def pager @pager end |