﻿<?xml version="1.0" encoding="utf-8"?>
<EXOconfigData format="Rwav" version="2019.4.100.249">
  <Object type="View">
    <Attribute name="Name">OnlineQuotes</Attribute>
    <Attribute name="Width">374</Attribute>
    <Attribute name="Height">172</Attribute>
    <Attribute name="Zoom">100%</Attribute>
    <Attribute name="ScaleValue">1</Attribute>
    <Attribute name="OnOpen"></Attribute>
    <Attribute name="ServerSideFunctionRPC">accounts.%account%.services.ssf.execute</Attribute>
    <Attribute name="ServerSideJS">return {
    getQuote: async (args, callInfo) =&gt; {
        console.log('In getQuote');

        // This is where we get out data
        const url = 'https://type.fit/api/quotes';
        
        // Use the 'fetch' object in 'context' to get or post http data
        const response = await callInfo.context.fetch(url);
        
        // Convert/parse the response from json to an object (list)
        const quotes = await response.json();
        
        // Get a random quote from the converted list and return it
        const quote = quotes[Math.floor(Math.random() * quotes.length)];
        return quote;
    }
}</Attribute>
    <Object type="ArgumentsFolder">
      <Attribute name="Name">Arguments</Attribute>
      <Attribute name="Comment">This folder contains all arguments for the view. The arguments can be sent to the view when it is used in run-time.</Attribute>
    </Object>
    <Object type="ElementsFolder">
      <Attribute name="Name">Elements</Attribute>
      <Attribute name="Comment">This folder contains all visual elements for the view.</Attribute>
      <Object type="Text">
        <Attribute name="Name">Quote</Attribute>
        <Attribute name="ShowTitle">No</Attribute>
        <Attribute name="Multiline">Yes</Attribute>
        <Attribute name="Left">10</Attribute>
        <Attribute name="Top">10</Attribute>
        <Attribute name="Width">355</Attribute>
        <Attribute name="Height">110</Attribute>
      </Object>
      <Object type="Button">
        <Attribute name="Name">GetQuote</Attribute>
        <Attribute name="Left">120</Attribute>
        <Attribute name="Top">135</Attribute>
        <Attribute name="Width">120</Attribute>
        <Attribute name="OnManeuver">this.view.call('.getQuote', { }).then((result) =&gt; {
  // Get the result (quote object) or default to an error text if the result was null.
  const quote = result || '[Quote could not be fetched...]';

  console.log("Got a new quote:", quote);

  // Surround the quote with quotation marks.
  // Add two blank (new) lines.
  // Add the author surrounded by hyphens.
  this.view.Quote.value(`"${quote.text}"\n\n-${quote.author}-`);
});</Attribute>
      </Object>
    </Object>
  </Object>
</EXOconfigData>