From fab7a9051014b393cbb057fd5fc85fe020ce58a7 Mon Sep 17 00:00:00 2001 From: Ryo ONODERA Date: Tue, 16 Apr 2019 08:59:52 +0900 Subject: [PATCH] Use sansan v2.3 API to query business cards information from sansan * Query with register date is deprecated, so remove register date from data range dialog box * Query with offset is deprecated, so use netxPageToken instead of offset * Bump version to 4 from 3 --- examples/sansan/js/common.js | 51 +++++++++++++---------- examples/sansan/js/desktop_lookup.js | 9 ++-- examples/sansan/js/desktop_postRecords.js | 24 +++++++---- examples/sansan/manifest.json | 2 +- 4 files changed, 49 insertions(+), 37 deletions(-) diff --git a/examples/sansan/js/common.js b/examples/sansan/js/common.js index 83652b0..ea4c898 100644 --- a/examples/sansan/js/common.js +++ b/examples/sansan/js/common.js @@ -213,51 +213,59 @@ jQuery.noConflict(); } // リクエスト用のURL生成 - function createSansanURL(type, value, limit, offset) { - var sansan_url = 'https://api.sansan.com/v1.1/bizCards'; + function createSansanURL(type, value, limit, nptoken) { + var sansan_url = 'https://api.sansan.com/v2.3/bizCards'; switch (type) { // 一括登録機能の条件指定検索の場合 case 'Postrecords_Condition': sansan_url += '/search' + '?range=all'; - if (value && $('#sansan_dropdown_code').val()) { - sansan_url += '&' + encodeURIComponent($('#sansan_dropdown_code').val()) + - '=' + encodeURIComponent(value); + if (nptoken == 0) { + if (value && $('#sansan_dropdown_code').val()) { + sansan_url += '&' + encodeURIComponent($('#sansan_dropdown_code').val()) + + '=' + encodeURIComponent(value); + } + } else { // nextPageTokenが渡された場合 + sansan_url += '&nextPageToken=' + encodeURIComponent(nptoken); } break; // ルックアップ機能の条件指定検索の場合 case 'Lookup_Condition': sansan_url += '/search' + '?range=all'; - if (value) { - sansan_url += '&' + encodeURIComponent(C_ORIGINALFIELD) + '=' + encodeURIComponent(value); + if (nptoken == 0) { + if (value) { + sansan_url += '&' + encodeURIComponent(C_ORIGINALFIELD) + '=' + encodeURIComponent(value); + } + } else { // nextPageTokenが渡された場合 + sansan_url += '&nextPageToken=' + encodeURIComponent(nptoken); } break; // タグ指定の場合 case 'Tag': sansan_url += '/search' + '?range=all'; - sansan_url += '&tagId=' + encodeURIComponent(value); - break; - - // 名刺登録日の期間指定の場合 - case 'Registered_Date': - sansan_url += '?range=all' + '®isteredFrom' + '=' + encodeURIComponent(value[0]) + - '®isteredTo' + '=' + encodeURIComponent(value[1]); + if (nptoken == 0) { + sansan_url += '&tagId=' + encodeURIComponent(value); + } else { // nextPageTokenが渡された場合 + sansan_url += '&nextPageToken=' + encodeURIComponent(nptoken); + } break; // 名刺更新日の期間指定の場合 case 'Updated_Date': - sansan_url += '?range=all' + '®isteredFrom' + '=' + encodeURIComponent('1900-01-01T00:00:00+09:00') + - '®isteredTo' + '=' + encodeURIComponent('3000-01-01T00:00:00+09:00'); - sansan_url += '&updatedFrom' + '=' + encodeURIComponent(value[0]) + - '&updatedTo' + '=' + encodeURIComponent(value[1]); + sansan_url += '?range=all'; + if (nptoken == 0) { + sansan_url += '&updatedFrom' + '=' + encodeURIComponent(value[0]) + + '&updatedTo' + '=' + encodeURIComponent(value[1]); + } else { // nextPageTokenが渡された場合 + sansan_url += '&nextPageToken=' + encodeURIComponent(nptoken); + } break; default: sansan_url += '/search' + '?range=all'; break; } sansan_url += '&limit=' + encodeURIComponent(limit); - sansan_url += '&offset=' + encodeURIComponent(offset); return sansan_url; } // ダイアログのHTML生成 @@ -389,10 +397,7 @@ jQuery.noConflict(); '' + '
' + '
' + '' + - '' + - '' + - '' + - '' + + '' + '
' + '
' + '' + '' + '' + '' + diff --git a/examples/sansan/js/desktop_lookup.js b/examples/sansan/js/desktop_lookup.js index 1a99f8e..0ee4498 100644 --- a/examples/sansan/js/desktop_lookup.js +++ b/examples/sansan/js/desktop_lookup.js @@ -92,12 +92,12 @@ jQuery.noConflict(); return false; }); }, - searchSansanData: function(type, value, opt_offset, opt_records) { + searchSansanData: function(type, value, opt_nptoken, opt_records) { // Sansanよりデータ取得 var limit = 300; - var offset = opt_offset || 0; + var nptoken = opt_nptoken || 0; var allrecords = opt_records || []; - var url = window.sansanLib.createSansanURL(type, value, limit, offset); + var url = window.sansanLib.createSansanURL(type, value, limit, nptoken); return kintone.plugin.app.proxy(PLUGIN_ID, url, 'GET', {}, {}).then(function(body) { allrecords = allrecords.concat(JSON.parse(body[0]).data); if (JSON.parse(body[1]) !== 200) { @@ -113,7 +113,8 @@ jQuery.noConflict(); return allrecords; } if (JSON.parse(body[0]).hasMore === true) { - return Sansanlookup.searchSansanData(type, value, offset + limit, allrecords); + nptoken = JSON.parse(body[0]).nextPageToken; + return Sansanlookup.searchSansanData(type, value, nptoken, allrecords); } return allrecords; }, function(error) { diff --git a/examples/sansan/js/desktop_postRecords.js b/examples/sansan/js/desktop_postRecords.js index 197f577..acee155 100644 --- a/examples/sansan/js/desktop_postRecords.js +++ b/examples/sansan/js/desktop_postRecords.js @@ -80,12 +80,12 @@ jQuery.noConflict(); return false; }); }, - searchSansanData: function(type, value, opt_offset, opt_records) { + searchSansanData: function(type, value, opt_nptoken, opt_records) { // Sansanよりデータ取得 var limit = 300; - var offset = opt_offset || 0; + var nptoken = opt_nptoken || 0; var allrecords = opt_records || []; - var url = window.sansanLib.createSansanURL(type, value, limit, offset); + var url = window.sansanLib.createSansanURL(type, value, limit, nptoken); return kintone.plugin.app.proxy(PLUGIN_ID, url, 'GET', {}, {}).then(function(body) { allrecords = allrecords.concat(JSON.parse(body[0]).data); if (JSON.parse(body[1]) !== 200) { @@ -100,7 +100,8 @@ jQuery.noConflict(); return allrecords; } if (JSON.parse(body[0]).hasMore === true) { - return SansanPostRecords.searchSansanData(type, value, offset + limit, allrecords); + nptoken = JSON.parse(body[0]).nextPageToken; + return SansanPostRecords.searchSansanData(type, value, nptoken, allrecords); } if (JSON.parse(body[0]).hasMore === false && allrecords[0] === null || allrecords.length === 0) { return kintone.Promise.reject(new Error('検索条件に一致する名刺データが見つかりませんでした。\n検索条件を変更してください。')); @@ -260,13 +261,17 @@ jQuery.noConflict(); SansanPostRecords.postRecordsMessage('post_success', msg); }, // タグ検索処理 - getSansanTag: function(opt_offset, opt_tags) { + getSansanTag: function(opt_nptoken, opt_tags) { // Sansanよりタグデータ取得 var limit = 300; - var offset = opt_offset || 0; + var nptoken = opt_nptoken || 0; var alltags = opt_tags || []; - var url = 'https://api.sansan.com/v1.1/tags?range=all' + '&type=shared';// 共有タグのみを取得 - url += '&offset=' + offset; + var url = 'https://api.sansan.com/v2.3/tags?range=all'; + if (nptoken == 0) { + url += '&type=shared';// 共有タグのみを取得 + } else { // nextPageTokenが渡された場合 + url += '&nextPageToken=' + nptoken; + } url += '&limit=' + limit; return kintone.plugin.app.proxy(PLUGIN_ID, url, 'GET', {}, {}).then(function(body) { alltags = alltags.concat(JSON.parse(body[0]).data); @@ -282,7 +287,8 @@ jQuery.noConflict(); return alltags; } if (JSON.parse(body[0]).hasMore === true) { - return SansanPostRecords.getSansanTag(offset + limit, alltags); + nptoken = JSON.parse(body[0]).nextPageToken; + return SansanPostRecords.getSansanTag(nptoken, alltags); } return alltags; }, function(error) { diff --git a/examples/sansan/manifest.json b/examples/sansan/manifest.json index f5e3072..ffda02e 100644 --- a/examples/sansan/manifest.json +++ b/examples/sansan/manifest.json @@ -1,6 +1,6 @@ { "manifest_version": 1, - "version": 3, + "version": 4, "type": "APP", "name": { "ja": "Sansan for kintone",