Topics

Exponent As A Service

The Exponent As A Service (EAAS) module allows external programs such as Android or iOS apps to retrieve data from the web site as JSON.  

  • To use the service, you must first 'Add a module' to any page, select Exponent as a Service as the module with an action of 'Install Service API', and 'Default' for the view. 
    • You may want to make the page/module private on do this on a standalone page to prevent display of the API key.  This will be corrected in the future.
  • You must then configure the EAAS service (module)
    • Each available data type is on its own tab.  You must select which existing modules will be used to provide data for the service request.
    • You may optionally assign an image and/or HTML text to the data type.
    • The 'aboutus' data type can be used by the requesting application to provide information for an 'about' dialog.
    • A module configuration must be saved for the service to work correctly.
  • The API key for the request, is listed on the page where the module was added.

The type of data and other parameters are sent by the requesting application.  This is typically performed by a JSONP request.It's essentially the same as straight JSON, but allows for calls outside your domain.  Here are the available parameters:

  • 'apikey' - the valid API key listed on the web site
  • 'get' - the service requested
    • 'aboutus'
    • 'news'
    • 'event'
    • 'blog'
    • 'photo'
    • 'media'
    • 'filedownload'
  • 'limit' - (optional) number of records to return
    • default is ALL records
  • 'order' - (optional) sort order to use for selecting records
    • default for news, blog is 'publish DESC'
    • default for media, filedownload is 'created_at ASC'
    • default for photo is 'rank'
    • default for event is 'created_at'
  • 'id' - (optional) pull a single record based on the record ID#
  • 'groupbydate' - (optional), if true for an 'event' request will aggregate/group events by date.

With any JSON call, Exponent will always return 3 top-level properties: replyCode, replyText, and data. In most cases unless the call fails, we'll receive 200 and 'ok' for the reply code and text. We'll always receive our data inside the 'data' property. There will be three (3) objects inside our data object: 'banner', 'html', and 'records'. the banner object will only show if an image has been configured through the tab on the site. The html object will contain the service description. The records is the results of grabbing any records which match the configuration on the site.The returned JSON data for a single news item would look like:

{
  "replyCode": 200,
  "replyText": "ok",
  "data": {
    "records": [
      {
        "validates": {
          "presence_of": {
            "title": {"message": "Title is a required field."},
            "body": {"message": "Body is a required field."}
          }
        },
        "supports_revisions": true,
        "classname": "news",
        "tablename": "news",
        "identifier": "id",
        "rank_by_field": "",
        "grouping_sql": "",
        "has_extended_fields": [],
        "has_one": [],
        "has_many": [],
        "has_many_self": [],
        "has_and_belongs_to_many": [],
        "has_and_belongs_to_self": [],
        "default_sort_field": "",
        "default_sort_direction": "",
        "get_assoc_for": [],
        "attachable_items_to_save": null,
        "get_attachable_for": [],
        "validate": [],
        "do_not_validate": [],
        "needs_approval": false,
        "id": "85",
        "title": "A News Item",
        "sef_url": "a-news-item",
        "canonical": "",
        "meta_title": "",
        "meta_keywords": "",
        "meta_description": "",
        "noindex": "0",
        "nofollow": "0",
        "body": "<p>This is a news item</p>",
        "poster": "1",
        "created_at": "1415705402",
        "editor": "1",
        "edited_at": "1415902383",
        "publish": "1415705400",
        "unpublish": "0",
        "location_data": "O:8:"stdClass":3:{s:3:"mod";s:4:"news";s:3:"src";s:20:"@random48e79c9faf65a";s:3:"int";s:0:"";}",
        "is_featured": "0",
        "rank": "34",
        "publish_date": "1415705400",
        "expFile": [
          {
            "table": "expFiles",
            "directory": "files/",
            "filename": "attached.png",
            "filesize": "142076",
            "mimetype": "image/png",
            "image_width": "590",
            "image_height": "424",
            "is_image": "1",
            "url": "http://localhost/exp2/files/attached.png",
            "path": "/UwAmp/www/exp2/files/attached.png",
            "path_relative": "/exp2/files/attached.png",
            "classname": "expFile",
            "tablename": "expFiles",
            "identifier": "id",
            "rank_by_field": "",
            "grouping_sql": "",
            "has_extended_fields": [],
            "has_one": [],
            "has_many": [],
            "has_many_self": [],
            "has_and_belongs_to_many": [],
            "has_and_belongs_to_self": [],
            "default_sort_field": "",
            "default_sort_direction": "",
            "get_assoc_for": [],
            "attachable_items_to_save": null,
            "get_attachable_for": [],
            "validate": [],
            "do_not_validate": [],
            "supports_revisions": false,
            "needs_approval": false,
            "id": "1416",
            "title": "",
            "shared": "0",
            "poster": "1",
            "posted": "1414262208",
            "accesscount": "0",
            "last_accessed": "1414262208",
            "alt": ""
          },
        ],
        "expTag": []
      }
    ],
    "banner": {
      "obj": {
        "table": "expFiles",
        "directory": "files/",
        "filename": "news.jpg",
        "filesize": "97654",
        "mimetype": "image/jpeg",
        "image_width": "648",
        "image_height": "382",
        "is_image": "1",
        "url": "http://localhost/exp2/files/news.jpg",
        "path": "/UwAmp/www/exp2/files/news.jpg",
        "path_relative": "/exp2/files/news.jpg",
        "classname": "expFile",
        "tablename": "expFiles",
        "identifier": "id",
        "rank_by_field": "",
        "grouping_sql": "",
        "has_extended_fields": [],
        "has_one": [],
        "has_many": [],
        "has_many_self": [],
        "has_and_belongs_to_many": [],
        "has_and_belongs_to_self": [],
        "default_sort_field": "",
        "default_sort_direction": "",
        "get_assoc_for": [],
        "attachable_items_to_save": null,
        "get_attachable_for": [],
        "validate": [],
        "do_not_validate": [],
        "supports_revisions": false,
        "needs_approval": false,
        "id": "1520",
        "title": "",
        "shared": "0",
        "poster": "1",
        "posted": "0",
        "accesscount": "0",
        "last_accessed": "0",
        "alt": "",
        "expCat": []
      },
      "md5": "eeb3fae53c5fba6122291775750e39f3"
    },
    "html": "<p>News module</p>"
  }
}

Here is an example .html file using Javascript to retreive data from EAAS, then printing it to the browser debug console.

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>EAAS Test</title>
    <script src="https://code.jquery.com/jquery-2.1.3.min.js" charset="utf-8"></script>
</head>
<body>
<script>
    var config = {
        // The API Key, which must get passed with every call to the service
        apikey:'Tzo4OiJzdGRDbGFzcyI6Mzp7czozOiJtb2QiO3M6NDoiZWFhcyI7czozOiJzcmMiO3M6MjA6IkByYW5kb201NGViNzFkZmRkYjhkIjtzOjM6ImludCI7czowOiIiO30=',
        // the type of data (tab) we'd like back. our options currently are aboutus, news, photo, event, blog, filedownload, and media.
        get: 'news',  // default is to simply return a connection message
        // limit the amount of records we get back
        limit: 5,  // default is all records
        // we can pass a string to define how we'd like the records ordered
        // default for news, blog is 'publish DESC'
        // default for media, filedownload is 'created_at ASC'
        // default for photo is 'rank'
        // default for event is 'created_at'
//        order: 'publish DESC',
        // passing 'id' will ignore limit and order, since we're requesting a single record based on the ID
//        id: 105,
        // to group/aggregate events by date
//        groupbydate: 1,
    };

    // the base URL
    var url = 'http://localhost/exp2/eaas/api/?callback=?';

    // jQuery's simple method for calling a remote server to return JSON
    // It take 3 arguements: a url, data, and a callback function.
    $.getJSON(url,config,function(response){
        // the JSON we want is the response object returned from the server
        console.log(response);
        // JSON Response
        //  data
        //  + banner (module image md5 & obj)
        //    + md5 (of image)
        //      obj (expFile record for image, use data->banner->obj->url to refernce image)
        //  + html (module description)
        //  + records (module item or array of items)
    });
</script>
</body>
</html>

 

Loading Help