Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade TwitterAPI to 2.5.7 #19382

Merged
merged 1 commit into from
Dec 17, 2018
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
25 changes: 20 additions & 5 deletions homeassistant/components/notify/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_USERNAME
from homeassistant.helpers.event import async_track_point_in_time

REQUIREMENTS = ['TwitterAPI==2.5.4']
REQUIREMENTS = ['TwitterAPI==2.5.7']

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -78,10 +78,25 @@ def send_message(self, message="", **kwargs):
def send_message_callback(self, message, media_id=None):
"""Tweet a message, optionally with media."""
if self.user:
resp = self.api.request('direct_messages/new',
{'user': self.user,
'text': message,
'media_ids': media_id})
user_resp = self.api.request(
'users/lookup', {'screen_name': self.user})
user_id = user_resp.json()[0]['id']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this safe even if the response is not 200?

if user_resp.status_code != 200:
self.log_error_resp(user_resp)
else:
_LOGGER.debug("Message posted: %s", user_resp.json())

event = {
'event': {
'type': 'message_create',
'message_create': {
'target': {'recipient_id': user_id},
'message_data': {'text': message},
}
}
}
resp = self.api.request(
'direct_messages/events/new', json.dumps(event))
else:
resp = self.api.request('statuses/update',
{'status': message,
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ RtmAPI==0.7.0
TravisPy==0.3.5

# homeassistant.components.notify.twitter
TwitterAPI==2.5.4
TwitterAPI==2.5.7

# homeassistant.components.sensor.waze_travel_time
WazeRouteCalculator==0.6
Expand Down