From cdefad69fd257b7acc9bbcb754afd7ae9c7d5729 Mon Sep 17 00:00:00 2001 From: David Boothe Date: Mon, 2 Nov 2015 16:27:25 -0600 Subject: [PATCH 1/2] add upsert to SOAP wrapper --- lib/fuelsdk/objects.rb | 4 ++++ lib/fuelsdk/soap.rb | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/fuelsdk/objects.rb b/lib/fuelsdk/objects.rb index 9407bfd..ece4032 100644 --- a/lib/fuelsdk/objects.rb +++ b/lib/fuelsdk/objects.rb @@ -17,6 +17,10 @@ def post client.soap_post id, Array.wrap(properties) end + def upsert + client.soap_upsert id, Array.wrap(properties) + end + def patch client.soap_patch id, Array.wrap(properties) end diff --git a/lib/fuelsdk/soap.rb b/lib/fuelsdk/soap.rb index c19edb1..6a22379 100644 --- a/lib/fuelsdk/soap.rb +++ b/lib/fuelsdk/soap.rb @@ -291,6 +291,11 @@ def soap_post object_type, properties soap_cud :create, object_type, properties end + def soap_upsert object_type, properties + options = {'SaveOptions' => [{'SaveOption' => {'PropertyName'=> "*", 'SaveAction' => "UpdateAdd"}}]} + soap_cud :create, object_type, properties, options + end + def soap_put object_type, properties soap_cud :update, object_type, properties end @@ -386,9 +391,10 @@ def normalize_properties_for_cud object_type, properties private - def soap_cud action, object_type, properties + def soap_cud action, object_type, properties, options = {} properties = normalize_properties_for_cud object_type, properties message = create_objects_message object_type, properties + message['Options'] = options soap_request action, message end From c6b75d213a8910363789774280f99e94fa44118d Mon Sep 17 00:00:00 2001 From: David Boothe Date: Wed, 11 Nov 2015 10:46:51 -0600 Subject: [PATCH 2/2] add functionality to upsert --- .gitignore | 1 + lib/fuelsdk/objects.rb | 5 +++++ lib/fuelsdk/soap.rb | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d3ffc31..d103b8e 100755 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ config.yaml /objsamples/config.yaml /objsamples/AllTest.bat .DS_STORE +.idea \ No newline at end of file diff --git a/lib/fuelsdk/objects.rb b/lib/fuelsdk/objects.rb index ece4032..119834c 100644 --- a/lib/fuelsdk/objects.rb +++ b/lib/fuelsdk/objects.rb @@ -207,6 +207,11 @@ def post super end + def upsert + add_customer_key self.properties + super + end + def patch add_customer_key self.properties super diff --git a/lib/fuelsdk/soap.rb b/lib/fuelsdk/soap.rb index 6a22379..075d8ea 100644 --- a/lib/fuelsdk/soap.rb +++ b/lib/fuelsdk/soap.rb @@ -293,7 +293,7 @@ def soap_post object_type, properties def soap_upsert object_type, properties options = {'SaveOptions' => [{'SaveOption' => {'PropertyName'=> "*", 'SaveAction' => "UpdateAdd"}}]} - soap_cud :create, object_type, properties, options + soap_cud :update, object_type, properties, options end def soap_put object_type, properties