myCRED_Remote

Description

This is the main myCRED API class allowing your site to award / deduct points based on requests from other websites. Just like everything else in myCRED, this class is pluggable and can be replaced / altered. There are also several actions and filters associated with this class allowing further customizations / expansion.

Requires myCRED 1.3 or higher.

Supported Actions

  • CREDIT
    Add points to a specific user.
  • DEBIT
    Deduct points from a specific user.
  • GET
    Get the current balance of a specific user.
  • PAY
    Deduct points from one user and credit the amount deducted to another user.

Supported Methods

  • JSON
  • _GET
  • _POST

If you are looking to create call scripts to interact with this class, please consider using the wp_remote_get or wp_remote_post WordPress functions.

Properties

  • $method (string)
    The method used for the incoming API call.
  • $uri (array)
    The $_SERVER[‘REQUEST_URI’] value in an array format.
  • $request (array)
    The API call request array.
  • $host (string)
    The remote callers IP address.
  • $format (string)
    The format of the API call.
  • $user (object)
    The requested user object.
  • $recipient (object)
    The requested recipient user object. Only used for transfers.
  • $reply (string)
    The reply sent back once the call has been processed. Defaults to ‘PROCESSING’. See the error list for a complete list of possible replies.
  • $core (object)
    The myCRED_Settings object.
  • $key (string)
    The API Key.

Methods

  1. myCRED_Remote( $key )Handles magic quotes, populates $method, $uri, $format, $host and $core. Requires the API key.

    Action: mycred_remote (ref array)

  2. handle_magic()Handles magic quotes for $_GET, $_POST, $_COOKIE and $_REQUEST.

    Action: mycred_remote_magic(ref array)

  3. set_headers()Sets the API reply headers.

    Action: mycred_remote_headers (ref array)

  4. parse_call()Parses the API call to determine how the API call is made. Supports JSON or HTML. Populates $request and $format.

    Action: mycred_remote_parse (ref array)

  5. get_host_IP()Retreaves the IP address of the caller.

    Action: mycred_remote_host_IP (ref array)

  6. validate_call()Validates the API call. This method either returns an error message or true if the call passes validation.

    Action: mycred_remote_validate (ref array)
    Returns: True (bool) or an error code (string).

  7. process()The main API processor. Processes the API request and returns a string reply. Possible values:

    Filter: mycred_transfer_acc_limit
    Action: mycred_remote_process (ref array)
    Action: mycred_remote_process_{$action} (ref array)
    Returns: The process result (string).

    • COMPLETEDThe request has been successfully completed.
    • FAILEDThe request failed.
    • DUPLICATEThe request is deemed to be a duplicate and was rejected.
    • DECLINEDThe request was declined due to insufficient funds.
    • UNKNOWNUnknown / unsupported request.

Error Messages

Important! The following error messages is only available if you have enabled “Debug Mode”. It is very important to disable “Debug Mode” once you are done testing / developing to prevent mischievous calls from learning about your setup!

  1. 0 – 100 Plugin related issues.

    • ERROR: 99 The API Key has not been set or is empty.
  2. 100 – 199 API Call related issues.

    • ERROR: 101 The request is empty.
    • ERROR: 102 The required “action” key is missing or empty in the request.
    • ERROR: 103 The required “account” key is missing or empty in the request.
    • ERROR: 104 The required “token” key is missing or empty in the request.
    • ERROR: 105 The required “host” key is missing or empty in the request.
  3. 200 – 299 User related issues.

    • ERROR: 201 The user count not be found. Remember that the API only supports users identified via an email address.
    • ERROR: 202 The user is excluded from using myCRED.
  4. 300 – 399 Request specific issues regardless of what action is requested.

    • ERROR: 301 Invalid security token.
    • ERROR: 302 Unknown / Unsupported Action request.
  5. 400 – 499 CREDIT & DEBIT related issues.

    • ERROR: 401 The required “ref” key is missing or empty in the request.
    • ERROR: 402 The required “entry” key is missing or empty in the request.
    • ERROR: 403 The required “amount” key is missing or empty in the request.
  6. 500 – 599 GET related issues.

    • none
  7. 600 – 699 PAY related issues.

    • ERROR: 501 The required “ref” key is missing or empty in the request.
    • ERROR: 502 The required “entry” key is missing or empty in the request.
    • ERROR: 503 The required “amount” key is missing or empty in the request.
    • ERROR: 504 The required “to” key is missing or empty in the request.
    • ERROR: 505 The required “data” key is missing or empty in the request.
    • ERROR: 506 The recipient user could not be found.
    • ERROR: 507 The recipient user ID is the same as the sender.
    • ERROR: 508 The recipient user has been excluded from using myCRED.