Browse Source

Se agrega función PUT al webservice para modificar valores de repositorios externos.

Maximiliano Schvindt 8 years ago
parent
commit
8c7bcb625f
1 changed files with 36 additions and 0 deletions
  1. 36 0
      Services/Webservice.php

+ 36 - 0
Services/Webservice.php

@@ -98,4 +98,40 @@ class Webservice
         return array();
     }
 
+    /**
+     * @param string $webservice
+     * @param array $filters
+     * @param array $order_by
+     * @param integer $limit
+     * @param integer $offset
+     * @return array
+     */
+    public function putData($webservice, $id, $data)
+    {
+        if ($this->serviceContainer->hasParameter($webservice)) {
+            $url = str_replace(".json", "/{$id}", $this->serviceContainer->getParameter($webservice));
+            $data_string = json_encode($data);
+
+            $ch = curl_init($url);
+            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");     
+            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
+            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: '.strlen($data_string))); 
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+
+            try {
+                $return = curl_exec($ch);
+            } catch (\Exception $ex) {
+                return array("error"=>"Connection Error.");
+            }
+
+            if($return) {
+                return json_decode($return, true);
+            } else {
+                return array("error"=>"Transaction Error.");
+            }
+        }
+
+        return array("error"=>"Webservice({$webservice}) not found.");
+    }
+
 }