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

version» Context lines:

pike.git/lib/modules/Web.pmod/Api.pmod/Api.pike:31:      //! If @expr{1@} @[Standards.JSON.decode_utf8()] will be used when JSON data   //! is decoded.   public int(0..1) utf8_decode = DECODE_UTF8;      //! Request timeout in seconds. Only affects async queries.   public int(0..) http_request_timeout = 0;      #if constant (Protocols.HTTP.Promise)   //! Typedef for the async callback method signature. - typedef function(mixed,Protocols.HTTP.Query|Protocols.HTTP.Promise.Result:void) Callback; + typedef function(mixed,Protocols.HTTP.Query|Protocols.HTTP.Promise.Result, +  mixed...:void) Callback;   #else   //! Typedef for the async callback method signature. - typedef function(mixed,Protocols.HTTP.Query:void) Callback; + typedef function(mixed,Protocols.HTTP.Query, mixed...:void) Callback;   #endif      //! Typedef for a parameter argument   typedef mapping|Web.Auth.Params ParamsArg;      //! Authorization object.   //!   //! @seealso   //! @[Web.Auth.OAuth2]   protected Web.Auth.OAuth2.Client _auth;
pike.git/lib/modules/Web.pmod/Api.pmod/Api.pike:152:    return ([ "path" : path, "params" : params ]);   }      //! Invokes a call with a GET method   //!   //! @param api_method   //! The remote API method to call   //! @param params   //! @param cb   //! Callback function to get into in async mode - mixed get(string api_method, void|ParamsArg params, void|Callback cb) + mixed get(string api_method, void|ParamsArg params, +  void|Callback cb, mixed...rest)   { -  return call(api_method, params, "GET", 0, cb); +  return call(api_method, params, "GET", 0, cb, @rest);   }      //! Invokes a call with a POST method   //!   //! @param api_method   //! The remote API method to call   //! @param params   //! @param data   //! Eventual inline data to send   //! @param cb   //! Callback function to get into in async mode   mixed post(string api_method, void|ParamsArg params, void|string data, -  void|Callback cb) +  void|Callback cb, mixed...rest)   { -  return call(api_method, params, "POST", data, cb); +  return call(api_method, params, "POST", data, cb, @rest);   }      //! Invokes a call with a DELETE method   //!   //! @param api_method   //! The remote API method to call   //! @param params   //! @param cb   //! Callback function to get into in async mode - mixed delete(string api_method, void|ParamsArg params, void|Callback cb) + mixed delete(string api_method, void|ParamsArg params, +  void|Callback cb, mixed...rest)   { -  return call(api_method, params, "DELETE", 0, cb); +  return call(api_method, params, "DELETE", 0, cb, @rest);   }      //! Invokes a call with a PUT method   //!   //! @param api_method   //! The remote API method to call   //! @param params   //! @param cb   //! Callback function to get into in async mode - mixed put(string api_method, void|ParamsArg params, void|Callback cb) + mixed put(string api_method, void|ParamsArg params, +  void|Callback cb, mixed...rest)   { -  return call(api_method, params, "PUT", 0, cb); +  return call(api_method, params, "PUT", 0, cb, @rest);   }      //! Invokes a call with a PATCH method   //!   //! @param api_method   //! The remote API method to call   //! @param params   //! @param cb   //! Callback function to get into in async mode - mixed patch(string api_method, void|ParamsArg params, void|Callback cb) + mixed patch(string api_method, void|ParamsArg params, +  void|Callback cb, mixed...rest)   { -  return call(api_method, params, "PATCH", 0, cb); +  return call(api_method, params, "PATCH", 0, cb, @rest);   }      //! Calls a remote API method.   //!   //! @throws   //! An exception is thrown if the response status code is other than   //! @expr{200@}, @expr{301@} or @expr{302@}.   //!   //! @param api_method   //! The remote API method to call!
pike.git/lib/modules/Web.pmod/Api.pmod/Api.pike:237:   //! @param cb   //! Callback function to get into in async mode   //!   //! @returns   //! If JSON is available the JSON response from servie will be decoded   //! and returned. If not, the raw response (e.g a JSON string) will be   //! returned. The exception to this is if the status code in the response is a   //! @expr{30x@} (a redirect), then the response headers mapping will be   //! returned.   mixed call(string api_method, void|ParamsArg params, -  void|string http_method, void|string data, void|Callback cb) +  void|string http_method, void|string data, +  void|Callback cb, mixed...rest)   {    http_method = upper_case(http_method || "get");    Web.Auth.Params p = Web.Auth.Params();    p->add_mapping(default_params());       if (params) p += params;       if (_auth && !_auth->is_expired()) {    if (string a = _auth->access_token) {    p += Web.Auth.Param(ACCESS_TOKEN_PARAM_NAME, a);
pike.git/lib/modules/Web.pmod/Api.pmod/Api.pike:282:    "data" : data    ]));       Concurrent.Future fut;    fut = Protocols.HTTP.Promise.do_method(http_method, api_method, args);       fut->on_success(lambda (Protocols.HTTP.Promise.Result res) {    mixed r = handle_response(res);       if (res->status >= 200 && res->status < 400) { -  if (cb) cb(r, res); +  if (cb) cb(r, res, @rest);    else retval = r;    }    else { -  cb && cb(0, res); +  cb && cb(0, res, @rest);    }       if (queue) {    queue->write("@");    }    });    fut->on_failure(lambda (Protocols.HTTP.Promise.Result res) { -  cb && cb(0, res); +  cb && cb(0, res, @rest);    if (queue) {    queue->write("@");    }    });       if (!cb) {    queue = Thread.Queue();    queue->read();    return retval;    }
pike.git/lib/modules/Web.pmod/Api.pmod/Api.pike:336: Inside #if defined(SOCIAL_REQUEST_DEBUG)
   TRACE("> data: %s\n", data[0..100]);    }    else {    TRACE("> data: %s\n", data);    }    }   #endif       if (cb) {    int myid = ++_call_id; -  _query_objects[myid] = ({ req, cb }); +  _query_objects[myid] = ({ req, cb }) + rest;       req->set_callbacks(    lambda (Protocols.HTTP.Query qq, int cid) {    if (qq->status == 200) {    qq->timed_async_fetch(    lambda (Protocols.HTTP.Query qa) { -  cb(handle_response(qa), qa); +  cb(handle_response(qa), qa, @rest);    m_delete(_query_objects, cid);    },    lambda (Protocols.HTTP.Query qa) { -  cb(0, qa); +  cb(0, qa, @rest);    m_delete(_query_objects, cid);    });    }    else if ((< 301, 302 >)[qq->status]) { -  cb(qq->headers, qq); +  cb(qq->headers, qq, @rest);    m_delete(_query_objects, cid);    }    else { -  cb(0, qq); +  cb(0, qq, @rest);    m_delete(_query_objects, cid);    }    },    lambda (Protocols.HTTP.Query qq, int cid) { -  cb(0, qq); +  cb(0, qq, @rest);    m_delete(_query_objects, cid);    },    myid);       Protocols.HTTP.do_async_method(http_method, api_method, params,    request_headers, req, data);       return 0;    }   
pike.git/lib/modules/Web.pmod/Api.pmod/Api.pike:459:    foreach (values(_query_objects), array m) {    catch {    Protocols.HTTP.Query q = m[0];       if (q && q->con && q->con->is_open()) {    TRACE("Forecefully closing open connection: %O\n", q);       q->close();       if (m[1]) { -  m[1](0, 0); +  m[1](0, 0, @m[2..]);    }    }    destruct(q);    };    }       _query_objects = ([]);   }      protected mixed handle_response(Protocols.HTTP.Query|Protocols.HTTP.Promise.Result req)