Class: AMEE::Profile::ProfileList
- Inherits:
-
Array
- Object
- Array
- AMEE::Profile::ProfileList
- Defined in:
- lib/amee/profile.rb
Instance Attribute Summary collapse
-
#pager ⇒ Object
readonly
Returns the value of attribute pager.
Instance Method Summary collapse
-
#initialize(connection, options = {}) ⇒ ProfileList
constructor
A new instance of ProfileList.
Constructor Details
#initialize(connection, options = {}) ⇒ ProfileList
Returns a new instance of ProfileList.
5 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 42 43 44 45 46 |
# File 'lib/amee/profile.rb', line 5 def initialize(connection, = {}) # Load data from path response = connection.get('/profiles', ).body # Parse data from response if response.is_json? # Read JSON doc = JSON.parse(response) @pager = AMEE::Pager.from_json(doc['pager']) doc['profiles'].each do |p| data = {} data[:uid] = p['uid'] data[:created] = DateTime.parse(p['created']) data[:modified] = DateTime.parse(p['modified']) data[:name] = p['name'] data[:path] = "/#{p['path']}" # Create profile profile = Profile.new(data) # Store in array self << profile end else # Read XML doc = REXML::Document.new(response) @pager = AMEE::Pager.from_xml(REXML::XPath.first(doc, '/Resources/ProfilesResource/Pager')) REXML::XPath.each(doc, '/Resources/ProfilesResource/Profiles/Profile') do |p| data = {} data[:uid] = p.attributes['uid'].to_s data[:created] = DateTime.parse(p.attributes['created'].to_s) data[:modified] = DateTime.parse(p.attributes['modified'].to_s) data[:name] = p.elements['Name'].text || data[:uid] data[:path] = "/#{p.elements['Path'].text || data[:uid]}" # Create profile profile = Profile.new(data) # Store connection in profile object profile.connection = connection # Store in array self << profile end end rescue raise AMEE::BadData.new("Couldn't load Profile list.\n#{response}") end |
Instance Attribute Details
#pager ⇒ Object (readonly)
Returns the value of attribute pager.
48 49 50 |
# File 'lib/amee/profile.rb', line 48 def pager @pager end |