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

version» Context lines:

pike.git/lib/modules/Web.pmod/Api.pmod/Api.pike:1: -  +    //! Base class for implementing a @tt{(RESTful) WebApi@} like Facebook's   //! Graph API, Instagram's API, Twitter's API and so on.   //!   //! @b{Note:@} This class is useless in it self, and is intended to be - //! inherited by classes implementing a given @tt{WebApi@}. + //! inherited by classes implementing a given @tt{Web.Api@}.   //! - //! Look at the code in @[WebApi.Github], @[WebApi.Instagram], - //! @[WebApi.Linkedin] etc to see some examples of implementations. + //! Look at the code in @[Web.Api.Github], @[Web.Api.Instagram], + //! @[Web.Api.Linkedin] etc to see some examples of implementations.      #if defined(SOCIAL_REQUEST_DEBUG) || defined(SOCIAL_REQUEST_DATA_DEBUG)   # define TRACE(X...) werror("%s:%d: %s",basename(__FILE__),__LINE__,sprintf(X))   #else   # define TRACE(X...) 0   #endif      //! The URI to the remote API   constant API_URI = 0;   
pike.git/lib/modules/Web.pmod/Api.pmod/Api.pike:27:   protected constant DECODE_UTF8 = 0;      //! If @expr{1@} @[Standards.JSON.decode_utf8()] will be used when JSON data   //! is decoded.   public int(0..1) utf8_decode = DECODE_UTF8;      //! Typedef for the async callback method signature.   typedef function(mapping,Protocols.HTTP.Query:void) Callback;      //! Typef for a parameter argument - typedef mapping|Auth.Params ParamsArg; + typedef mapping|Web.Auth.Params ParamsArg;      //! Authorization object.   //!   //! @seealso - //! @[Auth.OAuth2] - protected Auth.OAuth2.Client _auth; + //! @[Web.Auth.OAuth2] + protected Web.Auth.OAuth2.Client _auth;      //! Authentication class to use - protected constant AuthClass = Auth.OAuth2.Client; + protected constant AuthClass = Web.Auth.OAuth2.Client;      protected mapping(string:string) default_headers = ([    "user-agent" : .USER_AGENT   ]);      //! Creates a new Api instance   //!   //! @param client_id   //! The application ID   //!
pike.git/lib/modules/Web.pmod/Api.pmod/Api.pike:65:   //! Extended permissions to use for this authentication.   protected void create(string client_id, 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 @[Auth.OAuth2.Client]. + //! derived from @[Web.Auth.OAuth2.Client].   //!   //! @seealso - //! @[Auth.OAuth2.Client] or @[Auth.OAuth.Client] - Auth.OAuth2.Client `auth() + //! @[Web.Auth.OAuth2.Client] or @[Web.Auth.OWeb.Auth.Client] + Web.Auth.OAuth2.Client `auth()   {    return _auth;   }      //! This can be used to parse a link resource returned from a REST api.   //! Many API returns stuff like:   //!   //! @code - //! { - //! ... - //! "pagination" : { - //! "next" : "/api/v1/method/path?some=variables&page=2&per_page=20" - //! } - //! } + //! { + //! ... + //! "pagination" : { + //! "next" : "/api/v1/method/path?some=variables&page=2&per_page=20" + //! } + //! }   //! @endcode   //!   //! If @tt{pagination->next@} is passed to this method it will return a path   //! of @tt{/method/path@}, given that the base URI of the web api is   //! something along the line of @tt{https://some.url/api/v1@}, and a   //! mapping containing the query variables (which can be passed as a parameter   //! to any of the @tt{get, post, delete, put@} methods.   //!   //! @param url   //!
pike.git/lib/modules/Web.pmod/Api.pmod/Api.pike:221:   //! @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)   {    http_method = upper_case(http_method || "get"); -  Auth.Params p = Auth.Params(); +  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 += Auth.Param(ACCESS_TOKEN_PARAM_NAME, a); +  p += Web.Auth.Param(ACCESS_TOKEN_PARAM_NAME, a);    }    }       if (http_method == "POST") {    if (!data) data = (string) p;    params = 0;    }    else {    params = (mapping) p;    }
pike.git/lib/modules/Web.pmod/Api.pmod/Api.pike:387:    //!    //! @code    //! https://api.instagram.com/v1/media/search    //! ............................^^^^^^^    //! @endcode    protected constant METHOD_PATH = 0;       //! Hidden constructor. This class can not be instantiated directly    protected void create()    { -  if (this_program == WebApi.Api.Method) +  if (this_program == Web.Api.Api.Method)    error("This class can not be instantiated directly! ");    }       //! Internal convenience method    protected mixed _get(string s, void|ParamsArg p, void|Callback cb);       //! Internal convenience method    protected mixed _put(string s, void|ParamsArg p, void|Callback cb);       //! Internal convenience method    protected mixed _post(string s, void|ParamsArg p, void|string data,    void|Callback cb);       //! Internal convenience method    protected mixed _delete(string s, void|ParamsArg p, void|Callback cb);       //! Internal convenience method    protected mixed _patch(string s, void|ParamsArg p, void|Callback cb);   }