I had a need to do something with the data coming back from a Ooyala ping request. There weren't any good hooks that I could implement, other than completely overriding the hook_menu() page callback for the ping URL with my own, and so I got to thinking that this sort of event-based processing was well-suited to rules.
So, I've put together an initial patch providing Rules integration with a couple of basic events, and some data types (see below). I haven't introduced a hard dependency on Rules, in that all of the rules_invoke_event_by_args()
calls are wrapped by a check that module_exists('rules')
. All the rules hooks are implemented in ooyala.rules.inc.
There are probably more events that it would be useful to have rules integration for, but these are the ones I had an immediate need for, so I thought I'd contribute them now.
Events
- After a ping request is processed for a video node.
- After an image is fetched for a video node.
- After a ping request is received with an embed code not used by any nodes.
Data types
Based on the data structure returned from the Ooyala Backlot API for an Ooyala asset.
- Ooyala asset
- Ooyala preview image
- Ooyala image size
- Ooyala time restriction
Actions
- Import from Backlot
I'll be attaching the patch shortly. Let me know if there are any issues with this patch. I'd love to get it committed.
Comment | File | Size | Author |
---|---|---|---|
#7 | rules-integration-2146009-5.patch | 12.13 KB | jamesharv |
#7 | interdiff-rules-integration-2146009-5.txt | 810 bytes | jamesharv |
#1 | rules-integration-2146009-1.patch | 8.88 KB | jamesharv |
Comments
Comment #1
jamesharv CreditAttribution: jamesharv commentedPatch attached.
Comment #2
jamesharv CreditAttribution: jamesharv commentedHere's an updated version of the patch, which converts the date fields in the Ooyala response to unix time stamps, so that they are more usable by Rules. I also corrected a few mistakes with the time_restrictions property.
Comment #3
jamesharv CreditAttribution: jamesharv commentedApologies, the last patch was missing some important code. Please use this one instead.
Comment #4
jamesharv CreditAttribution: jamesharv commentedI found another use case for Rules integration. Here's an updated patch which adds the event:
And it adds the action:
The use case would be: automatically import assets uploaded directly to Backlot.
Comment #5
jamesharv CreditAttribution: jamesharv commentedComment #6
jamesharv CreditAttribution: jamesharv commentedComment #7
jamesharv CreditAttribution: jamesharv commentedHere's another improvement.
The ooyala_import action now provides the node that it creates, and it also fetch's the node's preview image.
Comment #8
quicksketchHi @jamesharv, thanks for your contribution! Unfortunately I have a severe aversion to Rules. Considering the amount of complexity we already have to maintain in this module, I'd like to avoid additional integrations, especially ones that I wouldn't use or be willing to maintain. However, the popularity of Rules module is uncontested, so I'd encourage you to make an add-on module with its own namespace to share your code with others (i.e. an ooyala_rules module). If you haven't already gone through the process of Git application to make official projects on drupal.org, I'd be happy to help sponsor your application.
Comment #9
jamesharv CreditAttribution: jamesharv commentedHi @quicksketch, fair enough. I'd be interested in breaking this out into an ooyala_rules module, but there are some key places in the ooyala project codebase where the Rule's events need to be triggered. Would you be open to a separate patch, adding integration points for an ooyala_rules module?
These integration points could probably just be
module_invoke_all()
/drupal_alter()
calls to avoid any hard dependency.Comment #10
quicksketchThat sounds perfect! I'd be happy to add such hooks. Thanks for all your help on this module.
Comment #11
quicksketch@jamesharv If you ever got around to this, please let me know. I'm moving this to postponed in the mean time.