pike.git / lib / modules / Web.pmod / Api.pmod / Api.pike

version» Context lines:

pike.git/lib/modules/Web.pmod/Api.pmod/Api.pike:47:   //! Typedef for a parameter argument   typedef mapping|Web.Auth.Params ParamsArg;      //! Authorization object.   //!   //! @seealso   //! @[Web.Auth.OAuth2]   protected Web.Auth.OAuth2.Client _auth;      //! Authentication class to use - protected constant AuthClass = Web.Auth.OAuth2.Client; + constant AuthClass = Web.Auth.OAuth2.Client;      //! The HTTP query objects when running async.   protected mapping(int:array(Protocols.HTTP.Query|Callback))    _query_objects = ([]);      protected mapping(string:string) default_headers = ([    "user-agent" : .USER_AGENT   ]);      protected int _call_id = 0;
pike.git/lib/modules/Web.pmod/Api.pmod/Api.pike:75:   //!   //! @param client_secret   //! The application secret   //!   //! @param redirect_uri   //! Where the authorization page should redirect back to. This must be   //! fully qualified domain name.   //!   //! @param scope   //! Extended permissions to use for this authentication. - protected void create(string client_id, string client_secret, + protected void create(void|string client_id, void|string client_secret,    void|string redirect_uri,    void|string|array(string)|multiset(string) scope)   {    if (AuthClass)    _auth = AuthClass(client_id, client_secret, redirect_uri, scope);   }      //! Getter for the authentication object. Most likely this will be a class   //! derived from @[Web.Auth.OAuth2.Client].   //!
pike.git/lib/modules/Web.pmod/Api.pmod/Api.pike:254:       if (_auth && !_auth->is_expired()) {    if (string a = _auth->access_token) {    p += Web.Auth.Param(ACCESS_TOKEN_PARAM_NAME, a);    }    }       mapping request_headers = copy_value(default_headers);    params = (mapping) p;    -  if ((< "POST" >)[http_method]) { -  if (!data) { +  if (!data && (< "POST" >)[http_method]) {    data = (string) p;    params = 0;    } -  else { -  array(string) parts = make_multipart_message(params, data); -  request_headers["content-type"] = parts[0]; -  data = parts[1]; -  params = 0; -  } -  } -  else { -  params = (mapping) p; -  } +        // If running in a handler thread (like in Roxen) we do an async call    // but wait for the request to finish before returning. In this way we    // can abort the request if it takes to long so that the handler thread    // can be released.    if (cb || !IS_BACKEND_THREAD()) {    Thread.Queue queue;    mixed retval;       Protocols.HTTP.Promise.Arguments args;
pike.git/lib/modules/Web.pmod/Api.pmod/Api.pike:501:    d = req->data;    }    else {    d = req->data();    }       if (req->status != 200) {    TRACE("Bad resp[%d]: %s\n\n%O\n",    req->status, d, req->headers);    -  if (has_value(d, "error")) { +  if (has_value(d, "\"error\"")) {    mapping e;    mixed err = catch {    e = Standards.JSON.decode(d);    };       if (e) {    if (e->error)    error("Error %d: %s. ", e->error->code, e->error->message);    else if (e->meta && e->meta->code)    error("Error %d: %s. ", e->meta->code, e->meta->error_message);
pike.git/lib/modules/Web.pmod/Api.pmod/Api.pike:581:   {    return replace(s, "\\/", "/");   }      //! Return default params   protected mapping default_params()   {    return ([]);   }    - //! Internal class ment to be inherited by implementing Api's classes that + //! Internal class meant to be inherited by implementing Api's classes that   //! corresponds to a given API endpoint.   class Method   {    //! API method location within the API    //!    //! @code    //! https://api.instagram.com/v1/media/search    //! ............................^^^^^^^    //! @endcode    protected constant METHOD_PATH = 0;