{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","results":{"codes":[]},"settings":"","params":[]},"next":{"description":"","pages":[]},"title":"Libraries - plug 'n play implementations","type":"basic","slug":"libraries-plug-n-play-templates","excerpt":"","body":"To facilitate communication with the Spigo API the employed programming language must be able to create an HTTPS connection as well as encode/decode messages in the JSON data format.\n\nTo ease integration this page provides an example you can use.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Java Spring Implementation\"\n}\n[/block]\nThis implementation is based on the popular open source [Spring Framework](https://en.wikipedia.org/wiki/Spring_Framework) and includes an implementation of the mandatory callback api.\n\nThe callback controller accepts HTTP posts sent to a callback url. Upon reception the controller checks for the presence and validitiy of the Spigo partner token. No communication without the correct token is accepted. After ensuring the token is correct the body of the message is JSON parsed and based on the \"event\" property a different branch of logic is invoked.\n\nA reduced complexity version of the implementation can be seen below. The full Java source file may be acquired [here](https://1271a4943ad1678623f8-7c85a57aea530056b9164b3fc8635a9d.ssl.cf3.rackcdn.com/libraries/java/SpigoGamesCallbackController.java).\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \" HttpServletResponse response,\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t   :::at:::RequestHeader(value = \\\"X-Spigo-Token\\\", required = false) String token, \\n\\t\\t\\t\\t\\t\\t\\t\\t\\t   @RequestBody String requestBody) throws UnauthorizedException, ParseException\\n{\\n\\t\\t// Check token presence and validity\\n\\t\\tif (!apiToken.equals(token)) {\\n\\t\\t\\tLOG.warn(\\\"API token not specified or expectected\\\");\\n\\t\\t\\tthrow new UnauthorizedException(\\\"Please provide a valid X-Spigo-Token value.\\\");\\n\\t\\t}\\n\\t\\t\\n     // Parse JSON body\\n        final JSONParser parser = SpixxUtilities.getJSONParser();\\n        final JSONObject json = (JSONObject)parser.parse(requestBody);\\n        \\n    switch (event) {\\n            case \\\"getPlayerBalance\\\": {\\n                LOG.debug(\\\"Retrieving current player balance ...\\\");\\n                \\n                break;\\n            }\\n            case \\\"gameRequestBuy\\\": {\\n\\n                LOG.debug(\\\"Requesting to buy a game ...\\\");          \\n                break;\\n            }\\n            case \\\"checkValidRequest\\\": {\\n\\n                    LOG.debug(\\\"Checking if a game transaction exists with the given transactionId ...\\\");\\n                break;\\n        \\t\\t}\\n            case \\\"requestRefund\\\": {\\n\\n            \\t\\t\\tLOG.debug(\\\"Refund request received for a particular game. Processing ...\\\");\\n                break;\\n            }\\n            case \\\"gameSessionStart\\\": {\\n            \\t\\t\\tLOG.debug(\\\"Game start notification request received.\\\");\\n                break;\\n            }\\n            case \\\"gameSessionEnd\\\": {\\n                    LOG.debug(\\\"Game end notification request received.\\\");\\n                break;\\n            }\\t\\n            case \\\"gameSessionRefund\\\": {\\n                    LOG.debug(\\\"Request to refund game received. Processing ...\\\");\\n                break;\\n            }\\n            case \\\"jackpotPayout\\\": {\\n                \\t\\tLOG.debug(\\\"Received request to pay out the jackpot. Processing ...\\\");\\n                break;\\n            }\\n            case \\\"isPlayerLoggedIn\\\": {\\n                    LOG.debug(\\\"'Is user logged in?' request received.\\\");\\n                break;\\n            }\\n            case \\\"gameSessionRequestBuy\\\": {\\n                    LOG.debug(\\\"Request to buy game session received. Processing ...\\\");\\n                break;\\n            }\\n            case \\\"gameSessionDeposit\\\": {\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\tLOG.debug(\\\"Request to deposit from game session received. Processing ...\\\");\\n                break;\\n            }\\n            case \\\"gameSessionRequestReservation\\\":\\n            case \\\"gameSessionBuyRefund\\\":\\n                    // no implementation -- intentional\\n                    LOG.debug(\\\"Recognized request received but it does not have logic implemented by design\\\");\\n        \\t\\tbreak;\\n            default:\\n                    throw new IllegalStateException(String.format(\\\"Attribute event value (%s) was not recognized as a valid event value name.\\\", event));\\n        }     \\n        return result;\\n\\t}\",\n      \"language\": \"java\",\n      \"name\": \"Java Spring Callback Controller\"\n    }\n  ]\n}\n[/block]","updates":[],"order":3,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"5a55b149f85c3a0032f10e61","category":{"sync":{"isSync":false,"url":""},"pages":[],"title":"Documentation","slug":"documentation","order":0,"from_sync":false,"reference":false,"_id":"5a55b149f85c3a0032f10e56","version":"5a55b149f85c3a0032f10e55","project":"550dd1756c0b4c0d00fd436e","createdAt":"2015-03-21T20:15:50.122Z","__v":0},"parentDoc":null,"project":"550dd1756c0b4c0d00fd436e","user":"5514315e67d97f2500b774ed","version":{"version":"1.5","version_clean":"1.5.0","codename":"","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["5a55b149f85c3a0032f10e56","5a55b149f85c3a0032f10e57","5a55b149f85c3a0032f10e58","5a55b149f85c3a0032f10e59","5a55b149f85c3a0032f10e5a","5a55b149f85c3a0032f10e5b","5a55b149f85c3a0032f10e5c","5a55b149f85c3a0032f10e5d","5d1da68fa911a50226595581"],"_id":"5a55b149f85c3a0032f10e55","project":"550dd1756c0b4c0d00fd436e","createdAt":"2018-01-10T06:23:05.406Z","releaseDate":"2018-01-10T06:23:05.406Z","__v":2},"createdAt":"2016-05-10T12:20:52.717Z","githubsync":"","__v":0}

Libraries - plug 'n play implementations


To facilitate communication with the Spigo API the employed programming language must be able to create an HTTPS connection as well as encode/decode messages in the JSON data format. To ease integration this page provides an example you can use. [block:api-header] { "type": "basic", "title": "Java Spring Implementation" } [/block] This implementation is based on the popular open source [Spring Framework](https://en.wikipedia.org/wiki/Spring_Framework) and includes an implementation of the mandatory callback api. The callback controller accepts HTTP posts sent to a callback url. Upon reception the controller checks for the presence and validitiy of the Spigo partner token. No communication without the correct token is accepted. After ensuring the token is correct the body of the message is JSON parsed and based on the "event" property a different branch of logic is invoked. A reduced complexity version of the implementation can be seen below. The full Java source file may be acquired [here](https://1271a4943ad1678623f8-7c85a57aea530056b9164b3fc8635a9d.ssl.cf3.rackcdn.com/libraries/java/SpigoGamesCallbackController.java). [block:code] { "codes": [ { "code": " HttpServletResponse response,\n\t\t\t\t\t\t\t\t\t @RequestHeader(value = \"X-Spigo-Token\", required = false) String token, \n\t\t\t\t\t\t\t\t\t @RequestBody String requestBody) throws UnauthorizedException, ParseException\n{\n\t\t// Check token presence and validity\n\t\tif (!apiToken.equals(token)) {\n\t\t\tLOG.warn(\"API token not specified or expectected\");\n\t\t\tthrow new UnauthorizedException(\"Please provide a valid X-Spigo-Token value.\");\n\t\t}\n\t\t\n // Parse JSON body\n final JSONParser parser = SpixxUtilities.getJSONParser();\n final JSONObject json = (JSONObject)parser.parse(requestBody);\n \n switch (event) {\n case \"getPlayerBalance\": {\n LOG.debug(\"Retrieving current player balance ...\");\n \n break;\n }\n case \"gameRequestBuy\": {\n\n LOG.debug(\"Requesting to buy a game ...\"); \n break;\n }\n case \"checkValidRequest\": {\n\n LOG.debug(\"Checking if a game transaction exists with the given transactionId ...\");\n break;\n \t\t}\n case \"requestRefund\": {\n\n \t\t\tLOG.debug(\"Refund request received for a particular game. Processing ...\");\n break;\n }\n case \"gameSessionStart\": {\n \t\t\tLOG.debug(\"Game start notification request received.\");\n break;\n }\n case \"gameSessionEnd\": {\n LOG.debug(\"Game end notification request received.\");\n break;\n }\t\n case \"gameSessionRefund\": {\n LOG.debug(\"Request to refund game received. Processing ...\");\n break;\n }\n case \"jackpotPayout\": {\n \t\tLOG.debug(\"Received request to pay out the jackpot. Processing ...\");\n break;\n }\n case \"isPlayerLoggedIn\": {\n LOG.debug(\"'Is user logged in?' request received.\");\n break;\n }\n case \"gameSessionRequestBuy\": {\n LOG.debug(\"Request to buy game session received. Processing ...\");\n break;\n }\n case \"gameSessionDeposit\": {\n\t\t\t\t\t\t\t\t\t\tLOG.debug(\"Request to deposit from game session received. Processing ...\");\n break;\n }\n case \"gameSessionRequestReservation\":\n case \"gameSessionBuyRefund\":\n // no implementation -- intentional\n LOG.debug(\"Recognized request received but it does not have logic implemented by design\");\n \t\tbreak;\n default:\n throw new IllegalStateException(String.format(\"Attribute event value (%s) was not recognized as a valid event value name.\", event));\n } \n return result;\n\t}", "language": "java", "name": "Java Spring Callback Controller" } ] } [/block]