From 05c784bcf0c93076c6226b3b577c2d23e8391f37 Mon Sep 17 00:00:00 2001
From: PatchRanger <Staratel@1209848.no-reply.drupal.org>
Date: Wed, 21 Aug 2013 17:15:22 +0700
Subject: [PATCH] Issue #1344882 by ncellier, klausi, ezeedub, muffinzap,
 PatchRanger: Choose a http method for REST Web Services

---
 wsclient_rest/wsclient_rest.module |   20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/wsclient_rest/wsclient_rest.module b/wsclient_rest/wsclient_rest.module
index caa426d..bd54150 100644
--- a/wsclient_rest/wsclient_rest.module
+++ b/wsclient_rest/wsclient_rest.module
@@ -77,6 +77,11 @@ class WSClientRESTEndpoint extends WSClientEndpoint {
       $data = $arguments[$operation['data']];
       unset($arguments[$operation['data']]);
     }
+    // Services module compliance: post fields should be in the $data array
+    // instead of $arguments.
+    if ($type == 'POST') {
+      $data = array_merge((array) $data, $arguments);
+    }
     try {
       $response = $client->execute(new HttpClientRequest($this->service->url . $operation_url, array(
         'method' => $type,
@@ -93,7 +98,19 @@ class WSClientRESTEndpoint extends WSClientEndpoint {
   public function formAlter(&$form, &$form_state) {
     if ($form_state['form'] == 'operation') {
       $operation = $form_state['operation'];
-
+      $form['type'] = array(
+        '#type' => 'select',
+        '#title' => t('HTTP Method'),
+        '#default_value' => isset($operation['type']) ? $operation['type'] : 'GET',
+        '#description' => t('Specify the HTTP request method used for this operation.'),
+        '#options' => array(
+          'GET' => 'GET',
+          'POST' => 'POST',
+          'PUT' => 'PUT',
+          'DELETE' => 'DELETE',
+        ),
+        '#weight' => -5,
+      );
       $form['url'] = array(
         '#type' => 'textfield',
         '#title' => t('Path'),
@@ -111,5 +128,6 @@ class WSClientRESTEndpoint extends WSClientEndpoint {
  * Form submit callback for the operation form.
  */
 function wsclient_rest_operation_form_submit($form, &$form_state) {
+  $form_state['operation']['type'] = $form_state['values']['type'];
   $form_state['operation']['url'] = $form_state['values']['url'];
 }
-- 
1.7.9.5

