"""
pass
+# These actions require POST http requests instead of GET
+_POST_ACTIONS = [
+ "create", "update", "destroy", "new", "follow", "leave",
+ ]
+
class TwitterCall(object):
- def __init__(self, username, password, format, domain, uri=""):
+ def __init__(
+ self, username, password, format, domain, uri="",
+ agent="Python Twitter Tools"
+ ):
self.username = username
self.password = password
self.format = format
except AttributeError:
return TwitterCall(
self.username, self.password, self.format, self.domain,
- self.uri + "/" + k)
+ self.uri + "/" + k, self.agent
+ )
def __call__(self, **kwargs):
+ uri = self.uri
method = "GET"
- if (self.uri.endswith('new')
- or self.uri.endswith('update')
- or self.uri.endswith('create')
- or self.uri.endswith('destroy')):
- method = "POST"
+ for action in _POST_ACTIONS:
+ if self.uri.endswith(action):
+ method = "POST"
+ break
+ if (self.agent):
+ kwargs["source"] = self.agent
+ id = kwargs.pop('id', None)
+ if id:
+ uri += "/%s" %(id)
+
encoded_kwargs = urlencode(kwargs.items())
argStr = ""
if kwargs and (method == "GET"):