Esempio n. 1
0
 def cancel(cls, id, api_key=None, request_id=None, **params):
     base = cls.class_url()
     extn = quote_plus(id)
     url = "%s/%s/cancel" % (base, extn)
     instance = cls(id, api_key, **params)
     headers = util.populate_headers(request_id=request_id)
     return instance.request("post", url, headers=headers)
Esempio n. 2
0
 def custom_method_request(cls, sid, **params):
     url = "%s/%s/%s" % (
         cls.class_url(),
         quote_plus(util.utf8(sid)),
         http_path,
     )
     return cls._static_request(http_verb, url, **params)
Esempio n. 3
0
    def class_url(cls, engine=None):
        # Namespaces are separated in object names with periods (.) and in URLs
        # with forward slashes (/), so replace the former with the latter.
        base = cls.OBJECT_NAME.replace(".", "/")
        if engine is None:
            return "/%s/%ss" % (cls.api_prefix, base)

        engine = util.utf8(engine)
        extn = quote_plus(engine)
        return "/%s/engines/%s/%ss" % (cls.api_prefix, extn, base)
Esempio n. 4
0
    def instance_url(self):
        id = self.get("id")

        if not isinstance(id, six.string_types):
            raise error.InvalidRequestError(
                "Could not determine which URL to request: %s instance "
                "has invalid ID: %r, %s. ID should be of type `str` (or"
                " `unicode`)" % (type(self).__name__, id, type(id)),
                "id",
            )

        id = util.utf8(id)
        base = self.class_url(self.engine)
        extn = quote_plus(id)
        url = "%s/%s" % (base, extn)

        timeout = self.get("timeout")
        if timeout is not None:
            timeout = quote_plus(str(timeout))
            url += "?timeout={}".format(timeout)
        return url
Esempio n. 5
0
 def retrieve(self,
              id,
              api_key=None,
              openai_version=None,
              openai_account=None,
              **params):
     url = "%s/%s" % (self.get("url"), quote_plus(util.utf8(id)))
     return self._request("get",
                          url,
                          api_key=api_key,
                          openai_version=openai_version,
                          openai_account=openai_account,
                          **params)
Esempio n. 6
0
    def instance_url(self):
        id = self.get("id")

        if not isinstance(id, six.string_types):
            raise error.InvalidRequestError(
                "Could not determine which URL to request: %s instance "
                "has invalid ID: %r, %s. ID should be of type `str` (or"
                " `unicode`)" % (type(self).__name__, id, type(id)),
                "id",
            )

        id = util.utf8(id)
        base = self.class_url()
        extn = quote_plus(id)
        return "%s/%s" % (base, extn)
 def nested_resource_url(cls, id, nested_id=None):
     url = "%s/%s/%s" % (cls.class_url(), quote_plus(id), quote_plus(path))
     if nested_id is not None:
         url += "/%s" % quote_plus(nested_id)
     return url
Esempio n. 8
0
 def class_url(cls, engine):
     assert engine is not None
     engine = util.utf8(engine)
     extn = quote_plus(engine)
     return "/%s/engines/%s/branches" % (cls.api_prefix, extn)
Esempio n. 9
0
 def _cls_delete(cls, sid, **params):
     url = "%s/%s" % (cls.class_url(), quote_plus(util.utf8(sid)))
     return cls._static_request("delete", url, **params)
Esempio n. 10
0
 def modify(cls, sid, **params):
     url = "%s/%s" % (cls.class_url(), quote_plus(util.utf8(sid)))
     return cls._static_request("post", url, **params)