Sha256: fcf4209d48afc27ed5f37a112723075b5a6b0e2cd893c6fd82cf75d752ab6567

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

module AMEE
  class Profile < AMEE::Object
    
    def self.list(connection)
      # Load data from path
      response = connection.get('/profiles')      
      # Parse data from response
      profiles = []
      if response.slice(0,1) == '{'
        # Read JSON
        doc = JSON.parse(response)
        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 = AMEE::Profile.new(data)
          # Store connection in object for future use
          profile.connection = connection
          # Store in array
          profiles << profile
        end
      else
        # Read XML
        doc = REXML::Document.new(response)
        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 = AMEE::Profile.new(data)
          # Store connection in object for future use
          profile.connection = connection
          # Store in array
          profiles << profile
        end
      end
      # Done
      return profiles
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
Floppy-amee-0.1.5 lib/amee/profile.rb