As talked with @indytechcook on IRC, he said services integration could be done as a submodule of bean in the same project.

I'm working on a patch for this.

Comments

recidive’s picture

Status: Active » Needs review
StatusFileSize
new9.92 KB

Here's a first crack at implementing this. Still needs to be tested. And needs a review on permissions implementation.

recidive’s picture

StatusFileSize
new9.8 KB

Another patch, improving service methods help and parameters descriptions. Making them translatable. And changing permission for accessing the 'index' method to 'administer beans'.

indytechcook’s picture

Status: Needs review » Needs work

This is awesome stuff. Since I've never used services I can't comment on if it works (but I know it does after talking to dave) but I'd still like someone else to review. Most of the stuff is great. Just a few small comments.

+++ b/bean_service/bean_service.incundefined
@@ -0,0 +1,157 @@
+ *   Unique identifier for this bean.
+ * @param $bean

It helps you add the object reference itself to the @param @param $bean Bean

This helps IDE's also do some fancy autocomplete and doxygen to do some awesome linkage.

+++ b/bean_service/bean_service.incundefined
@@ -0,0 +1,157 @@
+function bean_service_update($bid, $bean) {
+  $bean['bid'] = $bid;
+
+  $old_bean = bean_load($bid);
+  if (empty($old_bean)) {
+    return services_error(t('Bean @bid not found.', array('@bid' => $bid)), 404);
+  }
+
+  // Setup form_state.
+  $form_state = array();
+  $form_state['values'] = $bean;
+  $form_state['values']['op'] = t('Save');
+  $form_state['bean'] = $old_bean;
+
+  drupal_form_submit('bean_form', $form_state, $old_bean);
+
+  if ($errors = form_get_errors()) {
+    return services_error(implode(" ", $errors), 406, array('form_errors' => $errors));
+  }
+
+  return $bid;

Do we need both $bid and $bean passed in? You can get the bid from $bean->identifier()

+++ b/bean_service/bean_service.incundefined
@@ -0,0 +1,157 @@
+function bean_service_delete($bid) {
+  $bean = bean_load($bid);
+  if (empty($bean)) {
+    return services_error(t('There is no bean found with id @bid.', array('@bid' => $bid)), 404);
+  }
+
+  // Delete bean.
+  bean_delete($bean);
+
+  // Clear the cache so an anonymous user sees that his bean was deleted.
+  cache_clear_all();
+  return TRUE;

Use bean_reset() instead of cache_clear_all()

skwashd’s picture

Assigned: recidive » skwashd
Status: Needs work » Needs review
StatusFileSize
new9.54 KB

Updated version of the patch.

Changelog
* Move functionality into bean.module as there is little point in a sub module given this doesn't add any hard dependencies and it is only enabled if the user enables the specific resources in services
* Deal with the issues noted above
* Improve access controls
* Update to use new "view bean page" permission
* Rerolled so it applies cleanly against current 7.x-1.x HEAD
* Various bug fixes

The Bean argument is needed for bean_services_update as the REST call PUTs to the specific bean id - such as http://example.com/api/bean/123.json

indytechcook’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

indytechcook’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.