Class: AMEE::Profile::Profile
- Defined in:
- lib/amee/profile.rb
Instance Attribute Summary
Attributes inherited from Object
Attributes inherited from Object
#connection, #created, #modified, #name, #path, #uid
Class Method Summary collapse
- .create(connection) ⇒ Object
- .delete(connection, uid) ⇒ Object
-
.list(connection) ⇒ Object
backwards compatibility.
- .xmlpathpreamble ⇒ Object
Methods inherited from Object
Methods inherited from Object
#expire_cache, get_and_parse, #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
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 105 106 107 |
# File 'lib/amee/profile.rb', line 69 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
109 110 111 112 113 114 115 |
# File 'lib/amee/profile.rb', line 109 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
61 62 63 |
# File 'lib/amee/profile.rb', line 61 def self.list(connection) ProfileList.new(connection) end |
.xmlpathpreamble ⇒ Object
65 66 67 |
# File 'lib/amee/profile.rb', line 65 def self.xmlpathpreamble '/Resources/ProfilesResource/Profile/' end |