Class: AMEE::Profile::ProfileList
- Inherits:
-
Array
- Object
- Array
- AMEE::Profile::ProfileList
- Includes:
- ParseHelper
- 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.
Methods included from ParseHelper
#load_xml_doc, #node_value, #xmlpathpreamble
Constructor Details
#initialize(connection, options = {}) ⇒ ProfileList
Returns a new instance of ProfileList.
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 47 48 49 50 51 52 |
# File 'lib/amee/profile.rb', line 9 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 = load_xml_doc(response) @pager = AMEE::Pager.from_xml(@doc.xpath('/Resources/ProfilesResource/Pager').first) @doc.xpath('/Resources/ProfilesResource/Profiles/Profile').each do |p| data = {} data[:uid] = x '@uid', :doc => p data[:created] = DateTime.parse(x "@created", :doc => p) data[:modified] = DateTime.parse(x "@modified", :doc => p) data[:name] = x('Name', :doc => p) data[:name] = data[:uid] if data[:name].blank? data[:path] = x('Path', :doc => p) data[:path] = "/#{data[:uid]}" if data[:path].blank? # 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.
54 55 56 |
# File 'lib/amee/profile.rb', line 54 def pager @pager end |