This repository has been archived by the owner on Mar 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtwitterapi.drush.inc
69 lines (58 loc) · 1.75 KB
/
twitterapi.drush.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* @file
* Drush commands for the Twitter API module.
*/
/**
* Implements hook_drush_command().
*/
function twitterapi_drush_command() {
$items = array();
$items['twitterapi-get'] = array(
'description' => "Send GET requests to Twitter's API",
'arguments' => array(
'resource' => 'Relative path to any resouce documented here: https://dev.twitter.com/docs/api/1.1',
),
'options' => array(
'callback' => 'Wrap JSON result in a JSONP callback defined here.',
'format' => '@todo provide options',
),
'examples' => array(
'drush twitterapi-get "statuses/user_timeline.json?screen_name=whitehouse&count=3&include_rts=1"' => '',
'drush tg "statuses/user_timeline.json?screen_name=whitehouse&count=1" --calback=myCallback' => '',
'drush tg "statuses/user_timeline.json?screen_name=whitehouse&count=1" --format=json' => '',
'drush tg "statuses/user_timeline.json?screen_name=whitehouse&count=1" --format=pretty' => '',
),
'aliases' => array('tg'),
);
return $items;
}
/**
* Implements hook_drush_help().
*/
function twitterapi_drush_help($section) {
// @todo
}
/**
* Implements drush_hook_COMMAND().
*
* @see twitterapi_drush_command()
*/
function drush_twitterapi_get($request) {
$twitter_api = new TwitterApi();
$response = $twitter_api->get($request);
$format = drush_get_option('format');
$callback = drush_get_option('callback');
if ($format == 'json' || $callback) {
// Return response as JSON.
$response = drupal_json_encode($response);
}
if ($callback) {
// Return JSONP.
$response = "{$callback}({$response})";
}
if ($format == 'pretty' || ($format != 'json' && !$callback)) {
$response = print_r($response);
}
drush_print($response);
}