Now that twitter have switched off their old API, this module can't work without twitter module.

So a lot of code that was there for the transition period should be removed, as it does nothing other than complicate things:

- merge twitter_get_items() into get_items()
- remove the check for twitter module in hook_requirements()
- add twitter module as a dependency

CommentFileSizeAuthor
#4 twitter_pull_cleanup_1.diff15.31 KBkaosagnt
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim’s picture

Title: clean up twitter API 1 code » [meta] clean up twitter API 1 code

Handling this in sub-issues:

#2045547: added twitter as a module dependency done.

micheas’s picture

I am not sure where to add the following issue:

The hash tag urls need modified to not use https://search.twitter.com/ but rather https://twitter.com/

I'm just not sure where to report this bug.

joachim’s picture

Can you first search to see if that is already reported, and then create a new issue for it please?

kaosagnt’s picture

Issue summary: View changes
FileSize
15.31 KB

First attempt at cleaning up twitter_pull. Having timeouts and eventually WSOD when api.twitter.com is unavailable is the motivation.

1) Remove old fall back to API 1 when twitter module fails to connect.
2) Merge the twitter_get_items into get_items.
3) Handle not being able to pull tweets such that we return a obj instead of a string when no tweet data is available.

Lots more to do but this is round 1.

diff against last known public release from https://www.drupal.org/node/1925860

Last updated: October 19, 2013 - 13:06
Last packaged version: 7.x-2.0-alpha2+3-dev

joachim’s picture

Status: Active » Needs work

It's great to see someone doing clean-up on the code!

However, this patch covers too many different things, so it can't be committed as it stands.

Can you split it up and file different issues please? It's fine if each issue's patch depends on the previous one to apply cleanly, just make sure each issue says something like 'Applies on top of ISSUE URL'.

One way to split this up would be:
- apply the patch
- check out a new branch
- stage and commit the changes for one issue
- stash changes remaining
- do a diff to the previous branch
- repeat for each issue

Also, patches should always be rolled from the tip of a branch, not from a release, so you'd start this process with a diff to 7.x-2.x.

A few points I noticed in the patch below, will give you pointers about some of the issues that need to be split off.

  1. +++ b/twitter-pull-listing.tpl.php
    @@ -32,10 +32,11 @@
    -    
    +
    

    As much as I like cleaning up whitespace, that should be done in a separate issue.

  2. +++ b/twitter-pull-listing.tpl.php
    @@ -32,10 +32,11 @@
    +      <?php if (!isset($tweet->no_tweets)): ?>
    

    This looks like a new feature, or maybe a bugfix -- but a separate issue anyway.

  3. +++ b/twitter_pull.class.inc
    @@ -34,88 +34,28 @@ class twitter_puller {
    -    if ($num <= 0 || $num > 200) {
    -      throw new Exception(t('Number of Twitter items to pull must be a positive integer less than or equal to 200.'));
    +    if ($num <= 0 || $num > 100) {
    

    This looks like a bugfix.

  4. +++ b/twitter_pull.class.inc
    @@ -34,88 +34,28 @@ class twitter_puller {
         if (!module_exists('twitter')) {
    -      return FALSE;
    +      watchdog('Twitter Pull', 'Twitter module is not installed. Please install. No tweets can be pulled.');
    +      return(0);
    

    We can just remove the module_exists() check here -- twitter module is now a dependency.

  5. +++ b/twitter_pull.class.inc
    @@ -125,28 +65,28 @@ class twitter_puller {
    -    $rts = !empty($this->rts)?'1':'false';
    -    $exclude_replies = !empty($this->exclude_replies)?'true':'false';
    +    $rts = !empty($this->rts) ? '1' : 'false';
    +    $exclude_replies = !empty($this->exclude_replies) ? 'true' : 'false';
    

    This should go in the whitespace cleanup issue.

  6. +++ b/twitter_pull.class.inc
    @@ -154,41 +94,42 @@ class twitter_puller {
           watchdog('Twitter Pull', 'Twitter module is not properly configured and could not be used.');
    -      return FALSE;
    +      return(0);
    

    Is this a bugfix, or a change in function definition?

  7. +++ b/twitter_pull.install
    @@ -26,13 +26,13 @@ function twitter_pull_requirements($phase) {
             'twittter_pull_auth' => array(
               'title' => t('Twitter Pull Authentication'),
    -          'description' => t('Twitter Pull requires the !module to use the new Twitter API.  The twitter API you are currently using will cease to function in the near future.  See !link.', 
    +          'description' => t('Twitter Pull requires the !module to use the new Twitter API. See !link.', ¶
    

    It looks like we can remove all this too?

  8. +++ b/twitter_pull.module
    @@ -19,7 +19,17 @@ function twitter_pull_cache_length() {
    -  return variable_get('twitter_pull_empty_message', TWITTER_PULL_EMPTY_MESSAGE);
    +
    +  $obj = new stdClass();
    +  $obj->text = variable_get('twitter_pull_empty_message', TWITTER_PULL_EMPTY_MESSAGE);
    +  $obj->timestamp = time();
    +  $obj->no_tweets = 1;
    +  $obj->id = '';
    +  $obj->username = '';
    +
    +  $tweet[] = $obj;
    +
    +  return($tweet);
    

    This looks like another bugfix.

kaosagnt’s picture

The patch is against a release not tip, as I needed to resolve WSOD issue with our production sites using twitter_pull,
I'll endevour to regenerate all of these changes against 7.x-2.x tip shortly. I'll need to setup a test site for this work too.

2, 6 & 8 are related to the issue of not displaying the TWITTER_PULL_EMPTY_MESSAGE when there are no tweets to show.

8 introduces a dummy object as that is what is required by the underlying display logic not a string.

6 is a change in functionality as well to help facilitate the above.

3 is a bugfix.