Skip to content
This repository was archived by the owner on Aug 7, 2024. It is now read-only.

Add User object to DMs per Issue #344 #384

Merged
merged 3 commits into from
Sep 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,41 @@ Changelog
Version 3.2
===========

What's New
----------

* :py:class:`twitter.models.User` now contains a ``following`` attribute, which describes whether the authenticated user is following the User. `PR #351 <https://github.com/bear/python-twitter/pull/351>`_

* :py:class:`twitter.models.DirectMessage` now contains a full :py:class:`twitter.models.User` object for both the ``DirectMessage.sender`` and ``DirectMessage.recipient`` properties. `PR #384 <https://github.com/bear/python-twitter/pull/384>`_.

* You can now upload Quicktime movies (``*.mov``). `PR #372 <https://github.com/bear/python-twitter/pull/372>`_.

* If you have a whitelisted app, you can now get the authenticated user's email address through a call to :py:func:`twitter.api.Api.VerifyCredentials()`. If your app isn't whitelisted, no error is returned. `PR #376 <https://github.com/bear/python-twitter/pull/376>`_.

* **Google App Engine support has been reintegrated into the library!** Check out `PR #383 <https://github.com/bear/python-twitter/pull/383>`_.

What's Changed
--------------

* :py:func:`twitter.models.Trend`'s `volume` attribute has been renamed `tweet_volume` in line with Twitter's naming convention. This change should allow users to access the number of tweets being tweeted for a given Trend.
* :py:class:`twitter.models.Trend`'s `volume` attribute has been renamed `tweet_volume` in line with Twitter's naming convention. This change should allow users to access the number of tweets being tweeted for a given Trend. `PR #375 <https://github.com/bear/python-twitter/pull/375>`_

* :py:class:`twitter.ratelimit.RateLimit` should behave better now and adds a 1-second padding to requests after sleeping.

* :py:class:`twitter.ratelimit.RateLimit` now keeps track of your rate limit status even if you don't have ``sleep_on_rate_limit`` set to ``True`` when instatiating the API. If you want to add different behavior on hitting a rate limit, you should be able to now by querying the rate limit object. See `PR #370 <https://github.com/bear/python-twitter/pull/370>`_ for the technical details of the change. There should be no difference in behavior for the defaults, but let us know.


Bugfixes
--------

* :py:class:`twitter.models.Media` again contains a ``sizes`` attribute, which was missed back in the Version 3.0 release. `PR #360 <https://github.com/bear/python-twitter/pull/360>`_

* The previously bloated :py:func:`twitter.api.Api.UploadMediaChunked()` function has been broken out into three related functions and fixes two an incompatibility with python 2.7. Behavior remains the same, but this should simplify matters. `PR #347 <https://github.com/bear/python-twitter/pull/347>`_

* Fix for :py:func:`twitter.api.Api.PostUpdate()` where a passing an integer to the ``media`` parameter would cause an iteration error to occur. `PR #347 <https://github.com/bear/python-twitter/pull/347>`_

* Fix for 401 errors that were occuring in the Streaming Endpoints. `PR #364 <https://github.com/bear/python-twitter/pull/364>`_



Version 3.1
==========
Expand Down
22 changes: 22 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@ def test_direct_message(self):
self.assertTrue(dm.AsJsonString())
self.assertTrue(dm.AsDict())

def test_direct_message_sender_is_user_model(self):
"""Test that each Direct Message object contains a fully hydrated
twitter.models.User object for both ``dm.sender`` & ``dm.recipient``."""
dm = twitter.DirectMessage.NewFromJsonDict(self.DIRECT_MESSAGE_SAMPLE_JSON)

self.assertTrue(isinstance(dm.sender, twitter.models.User))
self.assertEqual(dm.sender.id, 372018022)

# Let's make sure this doesn't break the construction of the DM object.
self.assertEqual(dm.id, 678629245946433539)

def test_direct_message_recipient_is_user_model(self):
"""Test that each Direct Message object contains a fully hydrated
twitter.models.User object for both ``dm.sender`` & ``dm.recipient``."""
dm = twitter.DirectMessage.NewFromJsonDict(self.DIRECT_MESSAGE_SAMPLE_JSON)

self.assertTrue(isinstance(dm.recipient, twitter.models.User))
self.assertEqual(dm.recipient.id, 4012966701)

# Same as above.
self.assertEqual(dm.id, 678629245946433539)

def test_hashtag(self):
""" Test twitter.Hashtag object """
ht = twitter.Hashtag.NewFromJsonDict(self.HASHTAG_SAMPLE_JSON)
Expand Down
6 changes: 6 additions & 0 deletions twitter/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,21 @@ def __init__(self, **kwargs):
self.param_defaults = {
'created_at': None,
'id': None,
'recipient': None,
'recipient_id': None,
'recipient_screen_name': None,
'sender': None,
'sender_id': None,
'sender_screen_name': None,
'text': None,
}

for (param, default) in self.param_defaults.items():
setattr(self, param, kwargs.get(param, default))
if 'sender' in kwargs:
self.sender = User.NewFromJsonDict(kwargs.get('sender', None))
if 'recipient' in kwargs:
self.recipient = User.NewFromJsonDict(kwargs.get('recipient', None))

def __repr__(self):
if self.text and len(self.text) > 140:
Expand Down