def __call__(self, r): """Implement the AWS authentication for request r""" date_string = formatdate() content_type = r.headers["Content-Type"] msg = "PUT\n\n%s\n%s\n%s" % (content_type, date_string, self.resource) signature = hash_msg(self.secret_key, msg) r.headers["Date"] = date_string r.headers["Authorization"] = "AWS %s:%s" % (self.access_key, signature) return r
def _send(method, url, endpoint, params, data=None): """Return response from server after making request with method to endpoint with params and, optionally, data""" url = urljoin(url, endpoint) version = settings.YIKYAK_VERSION + settings.YIKYAK_VERSION_LETTER params += [("version", version)] salt = str(int(time())) msg = urljoin("/api/", endpoint) + '?' + unquote(urlencode(params)) + salt hash_string = hash_msg(settings.YIKYAK_APIKEY, msg) params += [("salt", salt), ("hash", hash_string)] if method == "POST": data = sorted(data + params) user_agent = get_user_agent() headers = {"User-Agent": user_agent, "Accept-Encoding": "gzip"} return REQUEST(method, url, params=params, data=data, headers=headers)