At the moment, the twitter module uses a hardcoded variable for defining the twitter host, making impossible to use a different service, for example for testing purposes. I will attach a patch for using a Drupal variable.

Comments

David Hernández’s picture

Assigned: David Hernández » Unassigned
Status: Active » Needs review
StatusFileSize
new2.48 KB

Patch attached

AlessMascherpa’s picture

Status: Needs review » Reviewed & tested by the community

Tests passed ;)

sjovanig’s picture

Title: Change hardcoded host to use a drupal variable » Backported to D6
Version: 7.x-3.x-dev » 6.x-3.x-dev
Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.98 KB

Backported to D6

jjcarrion’s picture

Status: Needs review » Reviewed & tested by the community

test passed

jonhattan’s picture

Title: Backported to D6 » Change hardcoded host to use a drupal variable
juampynr’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev
Status: Reviewed & tested by the community » Needs review
StatusFileSize
new821 bytes

The patch given at http://drupal.org/node/1346790#comment-5266844 caused that a user was unable to add a Twitter account using OAuth. The attached patch fixes this issue.

juampynr’s picture

Status: Needs review » Needs work
Issue tags: +needs backport to 6.x
jose reyero’s picture

Priority: Normal » Major
StatusFileSize
new401 bytes

This introduced a bug, now TwitterOauth can't find the server because the constructor for this class is missing a call to the parent's contructor

sjovanig’s picture

Status: Needs work » Needs review
StatusFileSize
new2.51 KB

I think introducing variable_set() and variable_get() inside Twitter class is not a good idea.

For abstraction questions the best solution is to use setters and getters to configure host or another class variable.

The patch I attach does:

  1. Provides default value for $host variable. This avoid to call parent::__construct() in each extender class.
  2. Removes calls to variable_set() and variable_get(). e.g. in tests you can set host easily through $instance->set_host()
  3. Introduces a new variable: $protocol. I think this is required, not always will be 'http' and now it can be set with set_protocol() and get_protocol()
juampynr’s picture

Status: Needs review » Fixed

Finally did a mix of all suggestions. Now there is a TwitterConf class which implements the Singleton pattern. This allows us to change the host to a fake one during, for example, automated tests. Each test suite would have at the top the following code:

  $conf = TwitterConf::instance();
  $conf->set('api', 'twitter.localhost');
  // From now on, calls to the Twitter API will be made to the new host set

Commit for the Drupal 6 version.

Commit for the Drupal 7 version.

Please reopen if there is anything missing regarding the issue title.

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