mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2025-04-05 11:22:30 -04:00
Modified Twython for sending data as json and added direct_messages/events/new #215
This commit is contained in:
parent
232d876c8f
commit
931cadfffa
@ -134,13 +134,13 @@ class Twython(EndpointsMixin, object):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<Twython: %s>' % (self.app_key)
|
return '<Twython: %s>' % (self.app_key)
|
||||||
|
|
||||||
def _request(self, url, method='GET', params=None, api_call=None):
|
def _request(self, url, method='GET', params=None, api_call=None, encode_json=False):
|
||||||
"""Internal request method"""
|
"""Internal request method"""
|
||||||
method = method.lower()
|
method = method.lower()
|
||||||
params = params or {}
|
params = params or {}
|
||||||
|
|
||||||
func = getattr(self.client, method)
|
func = getattr(self.client, method)
|
||||||
if type(params) is dict:
|
if type(params) is dict and encode_json == False:
|
||||||
params, files = _transparent_params(params)
|
params, files = _transparent_params(params)
|
||||||
else:
|
else:
|
||||||
params = params
|
params = params
|
||||||
@ -155,9 +155,15 @@ class Twython(EndpointsMixin, object):
|
|||||||
if method == 'get':
|
if method == 'get':
|
||||||
requests_args['params'] = params
|
requests_args['params'] = params
|
||||||
else:
|
else:
|
||||||
requests_args.update({
|
|
||||||
'data': params,
|
if encode_json == False:
|
||||||
|
requests_args.update({
|
||||||
'files': files,
|
'files': files,
|
||||||
|
'data': params,
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
requests_args.update({
|
||||||
|
'json': params,
|
||||||
})
|
})
|
||||||
try:
|
try:
|
||||||
response = func(url, **requests_args)
|
response = func(url, **requests_args)
|
||||||
@ -229,7 +235,7 @@ class Twython(EndpointsMixin, object):
|
|||||||
|
|
||||||
return error_message
|
return error_message
|
||||||
|
|
||||||
def request(self, endpoint, method='GET', params=None, version='1.1'):
|
def request(self, endpoint, method='GET', params=None, version='1.1', encode_json=False):
|
||||||
"""Return dict of response received from Twitter's API
|
"""Return dict of response received from Twitter's API
|
||||||
|
|
||||||
:param endpoint: (required) Full url or Twitter API endpoint
|
:param endpoint: (required) Full url or Twitter API endpoint
|
||||||
@ -260,7 +266,7 @@ class Twython(EndpointsMixin, object):
|
|||||||
url = '%s/%s.json' % (self.api_url % version, endpoint)
|
url = '%s/%s.json' % (self.api_url % version, endpoint)
|
||||||
|
|
||||||
content = self._request(url, method=method, params=params,
|
content = self._request(url, method=method, params=params,
|
||||||
api_call=url)
|
api_call=url, encode_json=encode_json)
|
||||||
|
|
||||||
return content
|
return content
|
||||||
|
|
||||||
@ -268,9 +274,9 @@ class Twython(EndpointsMixin, object):
|
|||||||
"""Shortcut for GET requests via :class:`request`"""
|
"""Shortcut for GET requests via :class:`request`"""
|
||||||
return self.request(endpoint, params=params, version=version)
|
return self.request(endpoint, params=params, version=version)
|
||||||
|
|
||||||
def post(self, endpoint, params=None, version='1.1'):
|
def post(self, endpoint, params=None, version='1.1', encode_json=False):
|
||||||
"""Shortcut for POST requests via :class:`request`"""
|
"""Shortcut for POST requests via :class:`request`"""
|
||||||
return self.request(endpoint, 'POST', params=params, version=version)
|
return self.request(endpoint, 'POST', params=params, version=version, encode_json=encode_json)
|
||||||
|
|
||||||
def get_lastfunction_header(self, header, default_return_value=None):
|
def get_lastfunction_header(self, header, default_return_value=None):
|
||||||
"""Returns a specific header from the last API call
|
"""Returns a specific header from the last API call
|
||||||
|
@ -320,7 +320,7 @@ class EndpointsMixin(object):
|
|||||||
Docs: https://dev.twitter.com/docs/api/1.1/post/direct_messages/new
|
Docs: https://dev.twitter.com/docs/api/1.1/post/direct_messages/new
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return self.post('direct_messages/new', params=params)
|
return self.post('direct_messages/events/new', params=params, encode_json=True)
|
||||||
|
|
||||||
# Friends & Followers
|
# Friends & Followers
|
||||||
def get_user_ids_of_blocked_retweets(self, **params):
|
def get_user_ids_of_blocked_retweets(self, **params):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user