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

#expire_cache, #initialize

Methods included from ParseHelper

#load_xml_doc, #node_value, #xmlpathpreamble

Constructor Details

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

Class Method Details

.create(connection) ⇒ Object



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
97
98
99
100
101
102
103
104
# File 'lib/amee/profile.rb', line 66

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 = load_xml_doc(response)
    data = {}
    data[:uid] = x '@uid'
    data[:created] = DateTime.parse(x '@created')
    data[:modified] = DateTime.parse(x '@modified')
    data[:name] = x 'Name'
    data[:name] = data[:uid] if data[:name].blank?
    data[:path] = x 'Path'
    data[:path] = "/#{data[:uid]}" if data[:path].blank?
    # 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



106
107
108
109
110
111
112
# File 'lib/amee/profile.rb', line 106

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



58
59
60
# File 'lib/amee/profile.rb', line 58

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

.xmlpathpreambleObject



62
63
64
# File 'lib/amee/profile.rb', line 62

def self.xmlpathpreamble
  '/Resources/ProfilesResource/Profile/'
end