ask-compu / python-twitter

Automatically exported from code.google.com/p/python-twitter
Apache License 2.0
0 stars 0 forks source link

GetDirectMessages is not in sync with API #69

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The GetDirectMessages function is outdated and not in sync with API. It
still has 'since' parameter that is not used anymore, and doesn't have
since_id, max_id, count or page parameters.

Here you have the patched version:

#
#--------------------------
  def GetDirectMessages(self, since_id=None,  max_id=None, count=None,
page=None):
    '''Returns a list of the direct messages sent to the authenticating user.

    The twitter.Api instance must be authenticated.

    Args:
      since_id:
          Optional.  Returns only direct messages with an ID greater than
(that is, more recent than) the specifi$
      max_id:
          Optional.  .Returns only statuses with an ID less than (that is,
older than) or equal to the specified $
      count
          Optional.  Specifies the number of statuses to retrieve. May not
be greater than 200.
      page
          Optional.  Specifies the page of direct messages to retrieve

    Returns:
      A sequence of twitter.DirectMessage instances
    '''
    url = 'http://twitter.com/direct_messages.json'
    if not self._username:
      raise TwitterError("The twitter.Api instance must be authenticated.")
    parameters = {}
    if since_id:
      parameters['since_id'] = since_id
    if max_id:
      parameters['max_id'] = max_id
    if count:
      parameters['count'] = count
    if page:
      parameters['page'] = page
    json = self._FetchUrl(url, parameters=parameters)
    data = simplejson.loads(json)
    return [DirectMessage.NewFromJsonDict(x) for x in data]

Original issue reported on code.google.com by ambros on 3 May 2009 at 9:23