I am uploading a stand-alone module (votingapi_service) that provides Services support for the Voting API. This allows external applications to access and modify Voting API data for Drupal objects. For example, a Flash application could implement an interface for voting on nodes.

votingapi_service provides the following methods, which are primarily wrappers to the corresponding Voting API function:

-- setVote: set vote for specified content from a given user
-- unsetVote: remove vote for specified content from a given user
-- getUserVotes: get all votes for specified content from a given user
-- getContentVotes: get all votes for specified content
-- getVotingResults: get results (current average) for specified content

votingapi_service allows only users with permissions of 'access votes' or of 'edit votes' to use these methods.

The Services community prefers packaging services support for non-core modules with the module, rather than including it with Services. Is there interest to include this with future releases of Voting API?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

Nice work! I just tested this since I was so excited. No issues at all. THis is RTBC, though it would be nice if you fixed the minor issues below.

Some notes:
- i don't think we usually want license info in the README and .module files. Everything in the drupal.org repository is already GPL v2. See the top level license file. i would also remove the version info. the $Id automatically tracks that.
- 'package = Voting' is more consistent with votingapi itself and fivestar
- code looks small and clean. nice.

Minor: Maintainers generally prefer that you upload 3 attachments instead of one tarball. easier to click on and review within a browser. we also often have scripts that apply patches from URLs and those don't expect (gzipped) tarballs.

youngbuddha’s picture

Hi,

I am looking for exactly the same functionality, being able to change the ratings of a node using HTTP based method invocation. That way, remote clients can be given a URL for solely the voting submission.

I would really love to see this added to the default Voting API module as a standard feature!

Thanks,

eaton’s picture

This is unlikely to be added as part of VotingAPI module proper, but perhaps it can be rolled in as a secondary module included in the download. Would it make more sense, though, to included it in Services.module?

mitchell’s picture

Version: 5.x-1.x-dev » 6.x-2.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)
Issue tags: +services integration

Very cool issue!

@detour: Could you please port you patch?

@Eaton: After talking to the services module maintainers, they are only willing to include core and views related services. On the other hand, quicksketch indicated he's open to putting services integration in Flag, as per #182071: Expose Flag Service.

mitchell’s picture

Status: Patch (to be ported) » Needs work

Marked #182073: Expose Vote up Down Methods via Services as a duplicate of this issue.

cangeceiro’s picture

it may be worth noting, this module is not compatible with drupal 6.11

eaton’s picture

Yeah, I've taken a look and it appears to be a Drupal 5 module. I'd like to get it in for the upcoming 'final' release of VAPI 2, but I think i'll need to take another crack at it.

miruoss’s picture

Hi there

Im very interested in this feature. If there is no way this is included to the VotingAPI module, it would be great to have it as a separate drupal module. Detour, are you gonna make a module out of this?

Cheers,
Michael

lesleyfernandes’s picture

Is this working for Drupal 6.15 and Services 2.0? Thanks

beauz’s picture

Also wondering if this is working properly for drupal 6.16 and services 2.0
Thanks

Cyberwolf’s picture

Subscribing.

RasputinJones’s picture

FileSize
2.26 KB

Hacked this together for Drupal 6. This is not fully tested but should work with services 2.0. Derived most of the code from fivestar's api I kept the original posters API. Feedback is welcome.

gbernier’s picture

Hey Rasputin,

I was looking for this solution as well, if I have any feedback I will provide it to you. Just installing now.

Cheers,
Gene Bernier

gbernier’s picture

FileSize
2.11 KB

Hey Rasputin and all,

Found one issue with the service on the votingapi.getContentVotes, it's only returning one result. The issue is on line 243, the code is returning $votes[0] instead of $votes. Aside from that I've had no issues with this, great module you should post it as a contribute, if you do let me know and I'd love to write a recommendation on drupalmodules.com for it.

Attached is the changed module

gbernier’s picture

One further follow up, some people may want to make the same change on line 257 so you can get the full array back from getVotingResults, the element [0] provides the average value of all the votes cast and [1] returns how many votes have been casted.

Cheers,
Gene Bernier

RasputinJones’s picture

Thanks. I'll see if i can post some updates today. How do you set up a contribute?

gunslinger4hire’s picture

Always when i try to call the votingapi services functions i get an Access denied error. If i try it with the services admin page or with remote calls with amfphp... All the rights are properly configured... Any ideas where could be my fault or the error?

lesleyfernandes’s picture

permissions?

gunslinger4hire’s picture

nope, unfortunately not... on my develop machine i granted all roles all permissions, even when i delete the permissions in the source code of the voting api service module, it wont work.

i suspect the voting api module itself right now... but without a hint whre to look...

sphism’s picture

^^^ you might need to set access on the service key, in drupal 6 they are here > admin/build/services/keys

Mac_Weber’s picture

Anything for services 3?

dereckd’s picture

Really need something like this for services 3, as well

mwsam’s picture

I have take the code from here and made a D7 version module out of it, which is compatible with services 3.x. The project page is here http://drupal.org/sandbox/mwsam/1427714.

dereckd’s picture

Thanks for your work! @mwsam when I check out the repo I'm informed that it's empty tried via smart git and command line

mwsam’s picture

From this page http://drupal.org/project/1427714/git-instructions you can check out 7.x-1.x branch using this instruction:

git clone --branch 7.x-1.x mwsam@git.drupal.org:sandbox/mwsam/1427714.git voting_api_services

Or alternatively you can also download the latest snapshot from here http://drupalcode.org/sandbox/mwsam/1427714.git/shortlog/refs/heads/7.x-1.x

galis007’s picture

Is it possible to get the services 3 version backported for drupal 6 also ive been trying to figure out an example of the url to set a vote eg http://.....endpoint/votingapi/setvote/?

mwsam’s picture

It is possible to backport into 6.x. I started the services 2.x to 3.x upgrade for 7.x branch out of a bounty posted in paid services forum, but I haven't received any payment and have since hear nothing from the bounty issuer despite several contact attempts. So somebody may needs to take it from here.

bhavin.ahya’s picture

I just created a module to support voting api with services 3.x in drupal 6.x and it's working fine. It will be great if someone can help me to post this module.

tpainton’s picture

Awesome.. Will give it a shot. Found it http://git.drupal.org/sandbox/mwsam/1427714.git voting_api_services

dereckd’s picture

how would one format a REST request for the voting API

tpainton’s picture

The module creates voting actions. Simply direct to endpoint and action votingapi/setVote to set a vote then supply the correct JSON as required by the module. I don't have PHP to show as example, as I am using Android Java to do the task. The way you figure out how to craft the JSON is by looking at the modules votingapi_service_services_resources method..

<?php
function votingapi_service_services_resources() {
  return array(
    'votingapi' => array(
      'actions' => array(
        'setVote' => array(
          'callback' => 'votingapi_service_set_vote',
          'access arguments' => array('edit votes'),
          'args' => array(
            array(
              'name' => 'content_id',
              'type' => 'int',
              'description' => t('Content ID.'),
              'source' => array('data' => 'content_id'),
            ),
            array(
              'name' => 'vote',
              'type' => 'int',
              'description' => t('Vote value in percentage.'),
              'source' => array('data' => 'vote'),
            ),
            array(
              'name' => 'content_type',
              'type' => 'string',
              'description' => t('Content type.'),
              'source' => array('data' => 'content_type'),
              'optional' => TRUE,
              'default value' => 'node',
            ),
            array(
              'name' => 'tag',
              'type' => 'string',
              'description' => t('Vote tag. Used for multi-criteria voting.'),
              'source' => array('data' => 'tag'),
              'optional' => TRUE,
              'default value' => 'vote',
            ),
          ),
?>

The name of each args element is the key for each JSON value.. so the above setVote JSON would look like..
{"content_id":"232", "vote":"4", "content_type":"song", "tag":"dance"}

So one would direct then connection to www.mysite.com/votingapi/setvote and then post the JSON as above to vote 4 stars for Node 232 that is a Song content type under the voting criteria (tag) of dance. The other options you have can be found in the same way by looking at the rest of the code.

hawkeye.twolf’s picture

FileSize
1.94 KB

Drupal 6.x Services 3.x version attached. A few notes re:changes from the 7.x version

  • Changed 'unsetVote' action to plural form (to more accurately describe the action)
  • Added 'since' parameter (integer timestamp, optional) to filter the following actions: unsetVotes, getUserVotes, getContentVotes.
  • Added 'replace' parameter (bool, default TRUE) to the 'setVotes' action, to allow multiple user votes per content. Set to 0/FALSE to keep VotingAPI from wiping existing user votes for the specified content and tag before saving the new vote. Leave TRUE for default behavior (wipe all user's existing votes for the content + tag).
legolasbo’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

Drupal 6 is no longer supported. Closing old issues to clean up the issue queue.

Please reopen and update this issue if this is still an issue in the D7 or D8 version.