Added set_description to twython API

This commit is contained in:
Manuel Cortez 2016-06-25 17:42:25 -05:00
parent 3bc92af55f
commit 48232a6cf8
2 changed files with 14 additions and 7 deletions

View File

@ -140,8 +140,11 @@ class Twython(EndpointsMixin, object):
params = params or {} params = params or {}
func = getattr(self.client, method) func = getattr(self.client, method)
if type(params) is dict:
params, files = _transparent_params(params) params, files = _transparent_params(params)
else:
params = params
files = list()
requests_args = {} requests_args = {}
for k, v in self.client_args.items(): for k, v in self.client_args.items():
# Maybe this should be set as a class variable and only done once? # Maybe this should be set as a class variable and only done once?
@ -199,8 +202,10 @@ class Twython(EndpointsMixin, object):
else: else:
content = response.json() content = response.json()
except ValueError: except ValueError:
raise TwythonError('Response was not valid JSON. \ # Send the response as is for working with /media/metadata/create.json.
Unable to decode.') content = response.content
# raise TwythonError('Response was not valid JSON. \
# Unable to decode.')
return content return content
@ -253,10 +258,8 @@ class Twython(EndpointsMixin, object):
url = endpoint url = endpoint
else: else:
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)
return content return content
def get(self, endpoint, params=None, version='1.1'): def get(self, endpoint, params=None, version='1.1'):

View File

@ -14,6 +14,7 @@ This map is organized the order functions are documented at:
https://dev.twitter.com/docs/api/1.1 https://dev.twitter.com/docs/api/1.1
""" """
import json
import os import os
import warnings import warnings
try: try:
@ -145,7 +146,10 @@ class EndpointsMixin(object):
return self.post('https://upload.twitter.com/1.1/media/upload.json', params=params) return self.post('https://upload.twitter.com/1.1/media/upload.json', params=params)
def set_description(self, **params): def set_description(self, **params):
return self.post('media/metadata/create', params=params) """ Adds a description to an image."""
# This method only accepts strings, no dictionaries.
params = json.dumps(params)
return self.post("media/metadata/create", params=params)
def upload_video(self, media, media_type, size=None): def upload_video(self, media, media_type, size=None):
"""Uploads video file to Twitter servers in chunks. The file will be available to be attached """Uploads video file to Twitter servers in chunks. The file will be available to be attached