iT邦幫忙

2021 iThome 鐵人賽

DAY 25
0
IT管理

「Google Apps Script」 學習筆記系列 第 25

【Day 25】Google Apps Script - API Blueprint 篇 - 執行專案取得 .apib 檔

執行 Google Docs 轉換 API Blueprint 格式專案程式,最後來看看轉換後的 .apib 檔內容吧。


今日要點:
》執行 Google Apps Script 專案
》查看轉換後的 .apib 檔內容


執行 Google Apps Script 專案

前二天我們把專案的程式碼都簡單介紹了一下,接下來就來執行看看囉。在上面的功能列,選擇我們主要的入口函式 goGet(e),再點選執行。

執行完後會在雲端硬碟的指定目錄裡產生一個 .apib 檔,如下圖所示:


轉換後的 apib 檔內容

轉換後的 apib 檔內容分為幾個部份,可以參考【Day 22】Google Apps Script - API Blueprint 篇 - API Blueprint 格式範例

Metadata

HOST: https://script.google.com
FORMAT: 1A

API Name & Description

# 鐵人賽 2021 
## Version
v1.0

Resource Groups (資源群組)

# Group API文件Demo

Resource (資源) / API Name

## 查詢Gmail資訊 [/macros/s/AKfycbyLOQLi_p2I2y0TQ4IrQ8vV53rtMSRdunWLqFJB5pBhHG9frBOf7rKB0Yunfl6x1twr/exec{?name,func}]

API Description

這裡的 API 描述主要是以表格呈現為主,Markdown 的也有表格的語法,但好像不能彈性的合併欄位,所以這裡還是轉成 html的語法。在這個示範專案,執行專案後,一共會匯出 4 個 API 描述段落表格至 .apib 檔裡。

API Description - 1

<table>
    <tr>
        <th>Docs Demo</th>
        <th>getGmailInfo</th>
        <th>查詢Gmail資訊</th>
    </tr>
    <tr>
        <td>說明</td>
        <td colspan=2> 使用 Google Apps Script 查詢 Gmail 資訊。</td>
    </tr>
</table>

API Description - 2

<table>
    <tr>
        <th colspan=3><b> Request Url Params </b></th>
    </tr>
    <tr>
        <th>鍵值</th>
        <th>型別</th>
        <th>說明</th>
    </tr>
    <tr>
        <td> name</td>
        <td> String</td>
        <td>查詢人的姓名</td>
    </tr>
    <tr>
        <td> func (必填)</td>
        <td> String</td>
        <td>要呼叫的功能名稱</td>
    </tr>
</table>

API Description - 3

<table>
    <tr>
        <th colspan=3><b> Response Body</b></th>
    </tr>
    <tr>
        <th>鍵值</th>
        <th>型別</th>
        <th>說明</th>
    </tr>
    <tr>
        <td> hello</td>
        <td> String</td>
        <td>對查詢人的問候語</td>
    </tr>
    <tr>
        <td> unreadCount</td>
        <td> Number</td>
        <td>收件夾中未讀信件的數量</td>
    </tr>
    <tr>
        <td> spamCount</td>
        <td> Number</td>
        <td>垃圾信件夾中的未讀數量</td>
    </tr>
    <tr>
        <td> messageSubject</td>
        <td> ArrayObject</td>
        <td>最新5筆信件的標題</td>
    </tr>
</table>

API Description - 4

<table>
    <tr>
        <th colspan=2><b> Sample</b></th>
    </tr>
    <tr>
        <th>Method</th>
        <th>GET</th>
    </tr>
    <tr>
        <td>URL</td>
        <td>https://script.google.com/macros/s/AKfycbyLOQLi_p2I2y0TQ4IrQ8vV53rtMSRdunWLqFJB5pBhHG9frBOf7rKB0Yunfl6x1twr/exec</td>
    </tr>
    <tr>
        <td>Request</td>
        <td>?name=Jason&func=getGmailInfo</td>
    </tr>
    <tr>
        <td>Response</td>
        <td>{<br>  "hello": "Jason 您好!",
             <br>  "unreadCount": 3,
             <br>  "spamCount": 1,
             <br>  "messageSubject": [
             <br>    "Important updates to our data protection terms",
             <br>    "決定了!就用「上海商銀台灣Pay」綁定數位振興五倍券!!",
             <br>    "【小編也不喜歡看人家臉色… ><】資金週轉自己來,中信信貸線上申辦!",
             <br>    "數位振興五倍券綁定臺灣銀行台灣Pay,最高加碼4500元!",
             <br>    "谷歌 正在招募:Technical Program Manager, Google Phone Software。"
             <br>  ]
             <br>}
             <br>
         </td>
    </tr>
</table>

MSON

MSON 是 Markdown Syntax for Object Notation 的縮寫,它是一種以人類可讀的純文本形式表示數據結構的方法。這邊就先不多做介紹,有興趣的話可以查看參考所附的連結。

Actions(動作)

### try:查詢Gmail資訊 [GET]

URI Parameters(參數)

+ Parameters
  + name: Jason (string, optional) -查詢人的姓名
  + func: getGmailInfo (string, required) - 要呼叫的功能名稱

+ Response 200 (application/json)

上述的 .apib 各段落對應畫面,如果用 apiary 的視覺化來展示,就如【Day 22】API Blueprint 格式範例所介紹的對應圖如下圖所示,可以再一起比對看一下:

以上就是 Google Docs 轉換 API Blueprint 格式後的 .apib 檔的內容介紹了,明天我們開始介紹 apiary。

參考


上一篇
【Day 24】Google Apps Script - API Blueprint 篇 - Google Docs 轉換 API Blueprint 格式(2)
下一篇
【Day 26】Google Apps Script - API Blueprint 篇 - Apiary 介面介紹
系列文
「Google Apps Script」 學習筆記30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言