Class: AMEE::Profile::Profile

Inherits:
Object show all
Defined in:
lib/amee/profile.rb

Instance Attribute Summary

Attributes inherited from Object

#profile_date, #profile_uid

Attributes inherited from Object

#connection, #created, #modified, #name, #path, #uid

Class Method Summary collapse

Methods inherited from Object

#full_path, #initialize

Methods inherited from Object

#initialize

Methods included from ParseHelper

#xmlpathpreamble

Constructor Details

This class inherits a constructor from AMEE::Profile::Object

Class Method Details

.create(connection) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/amee/profile.rb', line 59

def self.create(connection)
  # Create new profile
  response = connection.post('/profiles', :profile => true).body
  # Parse data from response
  if response.is_json?
    # Read JSON
    doc = JSON.parse(response)
    p = doc['profile']
    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)
    # Done
    return profile
  else
    # Read XML
    doc = REXML::Document.new(response)
    p = REXML::XPath.first(doc, '/Resources/ProfilesResource/Profile')
    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
    # Done
    return profile
  end
rescue
  raise AMEE::BadData.new("Couldn't create Profile.\n#{response}")
end

.delete(connection, uid) ⇒ Object



98
99
100
101
102
103
104
# File 'lib/amee/profile.rb', line 98

def self.delete(connection, uid)
  # Deleting profiles takes a while... up the timeout to 60 seconds temporarily
  t = connection.timeout
  connection.timeout = 60
  connection.delete("/profiles/#{uid}")
  connection.timeout = t
end

.list(connection) ⇒ Object

backwards compatibility



55
56
57
# File 'lib/amee/profile.rb', line 55

def self.list(connection)
  ProfileList.new(connection)
end