Skip to content

Tweet

send(package_id) ΒΆ

Posts the tweet given in the request body. The package ID is required for caching. Returns json data for displaying success/error messages.

Parameters:

Name Type Description Default
package_id

The package ID (for caching).

required

Returns:

Type Description

str

Source code in ckanext/twitter/routes/tweet.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
@blueprint.route('/dataset/<package_id>/tweet', methods=['POST'])
def send(package_id):
    """
    Posts the tweet given in the request body. The package ID is required for caching.
    Returns json data for displaying success/error messages.

    :param package_id: The package ID (for caching).
    :return: str
    """
    body = toolkit.request.values
    text = body.get('tweet_text', None)
    if text:
        posted, reason = twitter_api.post_tweet(text, package_id)
    else:
        posted = False
        reason = 'no tweet defined'
    return json.dumps(
        {
            'success': posted,
            'reason': reason,
            'tweet': text if text else 'tweet not defined',
        }
    )