Class: Eloqua::Api::Service
- Inherits:
-
Object
- Object
- Eloqua::Api::Service
- Defined in:
- lib/eloqua/api/service.rb
Constant Summary collapse
- @@group_methods =
[:key_with_object, :object_method, :list_types, :describe_type]
- @@type_methods =
[]
- @@group_type_methods =
[:create_object, :update_object, :delete_object, :find_object, :describe]
Class Method Summary collapse
- .add_group_member(asset_type, asset_id, entity_type, entity_id) ⇒ Object
-
.create_object(group, type, attributes) ⇒ Object
Delegate, Group, Type.
-
.delete_object(group, type, id) ⇒ Object
Delegate Group, Type.
-
.describe(group, type) ⇒ Object
Delegate Group, Type.
-
.describe_type(group, type_name) ⇒ Object
Delegate Group, Type.
- .entity_asset_operation(request_method, asset_type, asset_id, entity, entity_id) ⇒ Object
- .entity_association_xml(asset_type, asset_id, entity, entity_id) ⇒ Object
-
.find_object(group, type, id) ⇒ Object
Delegate Group, Type.
- .handle_exception(response) ⇒ Object
-
.key_with_object(group, name) ⇒ Object
Delegate Group.
-
.list_memberships(entity_type, entity_id) ⇒ Object
Delegate Type.
-
.list_types(group) ⇒ Object
Delegate Group.
-
.object_method(group, method) ⇒ Object
Delegate Group.
- .remove_group_member(asset_type, asset_id, entity_type, entity_id) ⇒ Object
- .request(*args) ⇒ Object
-
.update_object(group, type, entity_id, attributes) ⇒ Object
Delegate Group, Type.
Class Method Details
.add_group_member(asset_type, asset_id, entity_type, entity_id) ⇒ Object
167 168 169 |
# File 'lib/eloqua/api/service.rb', line 167 def add_group_member(asset_type, asset_id, entity_type, entity_id) entity_asset_operation(:add_group_member, asset_type, asset_id, entity_type, entity_id) end |
.create_object(group, type, attributes) ⇒ Object
Delegate, Group, Type
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/eloqua/api/service.rb', line 51 def create_object(group, type, attributes) xml_query = builder do |xml| xml.object_collection!(group) do xml.dynamic_object!(group) do xml.template!(:dynamic, group, type, nil, attributes) end end end result = request(object_method(group, :create), xml_query) result = result[key_with_object(group, :create_result)] if (result[:errors].nil? && result[:id]) {:id => result[:id].to_i} else handle_exception(result) end end |
.delete_object(group, type, id) ⇒ Object
Delegate Group, Type
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/eloqua/api/service.rb', line 91 def delete_object(group, type, id) xml_query = builder do |xml| xml.object_type_lower!(group) do xml.template!(:object_type, type) end xml.ids do xml.template!(:int_array, [id]) end end result = request(object_method(group, :delete), xml_query) result = result[key_with_object(group, :delete_result)] if (result[:success] && result[:id].to_s == id.to_s) [result[:id]] else handle_exception(result) end end |
.describe(group, type) ⇒ Object
Delegate Group, Type
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/eloqua/api/service.rb', line 185 def describe(group, type) xml_query = builder do |xml| xml.object_type_lower!(group) do xml.template!(:object_type, type) end end remote_method = "describe_#{group}".to_sym result = request(remote_method, xml_query) if (result) field_describe_key = "dynamic_#{group}_field_definition".to_sym fields = result[:fields] if (fields.is_a?(Hash) && fields.has_key?(field_describe_key)) result[:fields] = fields[field_describe_key] end end result end |
.describe_type(group, type_name) ⇒ Object
Delegate Group, Type
204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/eloqua/api/service.rb', line 204 def describe_type(group, type_name) key_type = "#{group}_type".to_sym key_types = "#{key_type}s".to_sym if(group == :entity) type_name_key = :global_entity_type else type_name_key = key_type end result = request("describe_#{group}_type".to_sym, type_name_key => type_name) Eloqua.format_results_for_array(result, key_types, key_type) end |
.entity_asset_operation(request_method, asset_type, asset_id, entity, entity_id) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/eloqua/api/service.rb', line 155 def entity_asset_operation(request_method, asset_type, asset_id, entity, entity_id) xml_query = entity_association_xml(asset_type, asset_id, entity, entity_id) result = request(request_method.to_sym, xml_query) if (result[:success]) true elsif (result[:errors]) handle_exception(result) else false end end |
.entity_association_xml(asset_type, asset_id, entity, entity_id) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/eloqua/api/service.rb', line 20 def entity_association_xml(asset_type, asset_id, entity, entity_id) xml_query = builder do |xml| xml.template!(:object, :entity, entity, entity_id) xml.template!(:object, :asset, asset_type, asset_id) end end |
.find_object(group, type, id) ⇒ Object
Delegate Group, Type
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/eloqua/api/service.rb', line 112 def find_object(group, type, id) xml_query = builder do |xml| xml.object_type_lower!(group) do xml.template!(:object_type, type) end xml.ids do xml.template!(:int_array, [id]) end end result = request(object_method(group, :retrieve), xml_query) field_key = "#{group}_fields".to_sym dynamic_key = "dynamic_#{group}".to_sym if (result[dynamic_key] && result[dynamic_key][:field_value_collection]) attribute_list = result[dynamic_key][:field_value_collection][field_key] attributes = {:id => result[dynamic_key][:id].to_i} attribute_list.each do |map| attributes[map[:internal_name].to_sym] = map[:value] end attributes else false end end |
.handle_exception(response) ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/eloqua/api/service.rb', line 217 def handle_exception(response) exception = response[:errors][:error] error_code = exception[:error_code] = exception[:message] = sprintf("Eloqua Error: Code (%s) | Message: %s", error_code, ) if (error_code =~ /Duplicate/) raise(Eloqua::DuplicateRecordError, ) else raise(Eloqua::RemoteError, ) end false end |
.key_with_object(group, name) ⇒ Object
Delegate Group
28 29 30 31 32 33 34 35 |
# File 'lib/eloqua/api/service.rb', line 28 def key_with_object(group, name) if (group == :entity) name.to_sym else parts = name.to_s.split('_') "#{parts[0]}_#{group}_#{parts[1]}".to_sym end end |
.list_memberships(entity_type, entity_id) ⇒ Object
Delegate Type
141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/eloqua/api/service.rb', line 141 def list_memberships(entity_type, entity_id) xml_query = builder do |xml| xml.template!(:object, :entity, entity_type, entity_id) end results = request(:list_group_membership, xml_query) if(results.has_key?(:dynamic_asset)) results = Eloqua.format_results_for_array(results, :dynamic_asset) results.inject([]) do |map, object| map << object[:asset_type] map end end end |
.list_types(group) ⇒ Object
Delegate Group
176 177 178 179 180 181 182 |
# File 'lib/eloqua/api/service.rb', line 176 def list_types(group) types = "#{group}_types".to_sym result = request("list_#{types}".to_sym) if (result && result[types]) result[types][:string] end end |
.object_method(group, method) ⇒ Object
Delegate Group
38 39 40 41 42 43 44 |
# File 'lib/eloqua/api/service.rb', line 38 def object_method(group, method) if (group == :entity) method.to_sym else "#{method}_#{group}".to_sym end end |
.remove_group_member(asset_type, asset_id, entity_type, entity_id) ⇒ Object
171 172 173 |
# File 'lib/eloqua/api/service.rb', line 171 def remove_group_member(asset_type, asset_id, entity_type, entity_id) entity_asset_operation(:remove_group_member, asset_type, asset_id, entity_type, entity_id) end |
.request(*args) ⇒ Object
46 47 48 |
# File 'lib/eloqua/api/service.rb', line 46 def request(*args) Eloqua::Api.request(:service, *args) end |
.update_object(group, type, entity_id, attributes) ⇒ Object
Delegate Group, Type
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/eloqua/api/service.rb', line 71 def update_object(group, type, entity_id, attributes) xml_query = builder do |xml| xml.object_collection!(group) do xml.dynamic_object!(group) do xml.template!(:dynamic, group, type, entity_id, attributes) end end end result = request(object_method(group, :update), xml_query) result = result[key_with_object(group, :update_result)] if (result[:success] && result[:id].to_s == entity_id.to_s) true else handle_exception(result) end end |