Wednesday, November 09, 2016

Google Slides API may power my future Slide Applications

So now Google is publishing its Slides API for programmatic use. This opens up a whole new world of slide generation.



This is especially interesting because I have previously been building my own REST Services for a Slide Service that we use for our own SaaS products at SNP Schneider-Neureither & Partner AG - such as the SNP System Scan. Results may look like this and a fully generated using a home-grown REST Service API.



open fullscreen in new window

As far as the REST API is concerned it takes some slide definition in JSON fomat that looks something like this:


{
   "title":"Fun with auto generated Slide Show",
   "author":"Dominik Wittenbeck",
   "subtitle":"",
   "header":"SNP Slideshow",
   "footer":"
",
   "slides":[
      {
         "id":"005056BF5BE41EE6A9D91E8EC1102DD3",
         "title":"First Slide with some HTML",
         "topline":"SNP Slides Showcase",
         "html":[
            "..."
         ]
      },
      {
         "id":"005056BF5BE41EE6A9D91E8EC1104DD3",
         "title":"Second Slide with child slides",
         "topline":"SNP Slides Showcase",
         "items":[
            {
               "id":"005056BF5BE41EE6A9D91E8EC1106DD3",
               "title":"Second Slide with child slides",
               "topline":"SNP Slides Showcase",
               "html":[
                  "..."
               ]
            },
            {
               "id":"005056BF5BE41EE6A9D91E8EC1108DD3",
               "title":"Child Slide 2",
               "topline":"SNP Slides Showcase",
               "html":[
                  "..."
               ]
            }
         ]
      },
      {
         "id":"005056BF5BE41EE6A9D91E8EC110ADD3",
         "title":"Third Slide with a Chart",
         "topline":"SNP Slides Showcase",
         "layout":"vertical",
         "html":[
            "...",
            "..."
         ]
      }
   ]
}


Besides the REST API I have build additional higher level APIs, that can used e.g. directly in ABAP.

REPORT zdwi_generate_slides_test.
*"--- DATA DEFINITION -------------------------------------------------
TYPE-POOLSabap.

*"--- PROCESSING LOGIC ------------------------------------------------
START-OF-SELECTION.
  PERFORM main.

FORM main.
*"--- DATA DEFINITION -------------------------------------------------
  DATAlr_deck TYPE REF TO /snp/cn02_cl_slidedeck.
  DATAlr_slide TYPE REF TO /snp/cn02_cl_slide.
  DATAlr_sub_slide TYPE REF TO /snp/cn02_cl_slide.
  DATAlr_chart TYPE REF TO /snp/cn02_cl_slide_chart.
  DATAlv_id TYPE string.
  DATAlt_t000 TYPE TABLE OF t000.
  DATAlv_layout TYPE string.
  DATAlv_html TYPE string.
  DATAlv_url TYPE string.

*"--- PROCESSING LOGIC ------------------------------------------------
  lv_id /snp/cn00_cl_string_utils=>uuid).

  "Generate the slidedeck
  lr_deck /snp/cn02_cl_slidedeck=>create(
    iv_id lv_id
    iv_title 'Fun with auto generated Slide Show'
    iv_author 'Dominik Wittenbeck'
    iv_header 'SNP Slideshow'
    iv_footer '<br/>'
  ).

  "--- Add first slide with some HTML Content
  lr_slide /snp/cn02_cl_slide=>create(
    iv_title 'First Slide with some HTML'
    iv_topline 'SNP Slides Showcase'
  ).

  CONCATENATE
    '<h1>' 'Headline' '</h1>'
    '<p>'
      'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam'
      'nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam'
      'erat, sed diam voluptua. At vero eos et accusam et justo duo dolores'
      'et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est'
      'Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur'
      'sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore'
      'et dolore magna aliquyam erat, sed diam voluptua. At vero eos'
      'et accusam et justo duo dolores et ea rebum. Stet clita kasd'
      'gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.'
    '</p>'
  INTO lv_html SEPARATED BY space.
  lr_slide->add_htmllv_html ).
  lr_deck->add_slidelr_slide ).


  "--- Create a second Slide with child slides
  lr_slide /snp/cn02_cl_slide=>create(
    iv_title 'Second Slide with child slides'
    iv_topline 'SNP Slides Showcase'
  ).

  "...with one child slide...
  lr_sub_slide /snp/cn02_cl_slide=>create(
    iv_title 'Second Slide with child slides'
    iv_topline 'SNP Slides Showcase'
  ).

  CONCATENATE
    '<p>'
      'Check out the arrows on the lower right, this slide has another child slide'
    '</p>'
  INTO lv_html.

  lr_sub_slide->add_htmllv_html ).
  lr_slide->add_slidelr_sub_slide ).

  "...and a second child slide...
  lr_sub_slide /snp/cn02_cl_slide=>create(
    iv_title 'Child Slide 2'
    iv_topline 'SNP Slides Showcase'
  ).

  lr_sub_slide->add_html'Content of child slide 2' ).
  lr_slide->add_slidelr_sub_slide ).

  "...oh, and don't forget to add the main slide to the deck ;-)
  lr_deck->add_slidelr_slide ).


  "--- On the 3rd Slide letzt incorporate some data
  "Let's just fetch basic information about all clients...
  SELECT FROM t000 INTO TABLE lt_t000.

  "also split that slide into several parts using a layout
  lr_slide /snp/cn02_cl_slide=>create(
    iv_title 'Third Slide with a Chart'
    iv_topline 'SNP Slides Showcase'
    iv_layout 'vertical'
  ).

  "...and put that data in a bar chart in the
  " first part of the layout (=left side)
  lr_chart /snp/cn02_cl_slide_chart=>create_bar).
  lr_chart->set_data(
    it_data lt_t000
    iv_x_columns 'ORT01' "Show number of clients per location
  ).
  lr_slide->add_chartlr_chart ).

  "...and put some descriptive text to the second part of
  " the layout (=right side)
  CONCATENATE
    '<p>'
      'This is some descriptive text for the chart'
    '</p>'
    '<ul>'
      '<li>' 'and while' '</li>'
      '<li>' 'we''re at it, let''s' '</li>'
      '<li>' 'have a few bullet points' '</li>'
    '</ul>'
  INTO lv_html SEPARATED BY space.

  lr_slide->add_htmllv_html ).


  "...oh, and don't forget to add the main slide to the
  " deck... again  ;-)
  lr_deck->add_slidelr_slide ).

  "Publish the slide deck via the REST Service and Report
  " back the URL that would show it in a browser
  lv_url lr_deck->get_url).
  WRITE/ lv_url.

ENDFORM.

So with the newly published Google Slides API maybe I could take this one step further....

0 comments: