52
53
54
55
56
57
58
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
97
98
99
100
101
102
103
|
# File 'lib/fuelsdk/objects.rb', line 52
def post
if self.respond_to?('folder_property') && !self.folder_id.nil?
properties[self.folder_property] = self.folder_id
elsif self.respond_to?('folder_property') && !self.folder_property.nil? && !client.package_name.nil? then
if client.package_folders.nil? then
getPackageFolder = ET_Folder.new
getPackageFolder.authStub = client
getPackageFolder.properties = ["ID", "ContentType"]
getPackageFolder.filter = {"Property" => "Name", "SimpleOperator" => "equals", "Value" => client.package_name}
resultPackageFolder = getPackageFolder.get
if resultPackageFolder.status then
client.package_folders = {}
resultPackageFolder.results.each do |value|
client.package_folders[value[:content_type]] = value[:id]
end
else
raise "Unable to retrieve folders from account due to: #{resultPackageFolder.message}"
end
end
if !client.package_folders.has_key?(self.folder_media_type) then
if client.parentFolders.nil? then
parentFolders = ET_Folder.new
parentFolders.authStub = client
parentFolders.properties = ["ID", "ContentType"]
parentFolders.filter = {"Property" => "ParentFolder.ID", "SimpleOperator" => "equals", "Value" => "0"}
resultParentFolders = parentFolders.get
if resultParentFolders.status then
client.parent_folders = {}
resultParentFolders.results.each do |value|
client.parent_folders[value[:content_type]] = value[:id]
end
else
raise "Unable to retrieve folders from account due to: #{resultParentFolders.message}"
end
end
newFolder = ET_Folder.new
newFolder.authStub = client
newFolder.properties = {"Name" => client.package_name, "Description" => client.package_name, "ContentType"=> self.folder_media_type, "IsEditable"=>"true", "ParentFolder" => {"ID" => client.parentFolders[self.folder_media_type]}}
folderResult = newFolder.post
if folderResult.status then
client.package_folders[self.folder_media_type] = folderResult.results[0][:new_id]
else
raise "Unable to create folder for Post due to: #{folderResult.message}"
end
end
properties[self.folder_property] = client.package_folders[self.folder_media_type]
end
client.soap_post id, properties
end
|