SlackのREST APIを呼び出してユーザーのDo Not Disturbステータスを取得するAppleScriptです。
SLackにサインアップしてAPIのアクセストークンを取得し、プログラムリスト中に記入して実行してください。
AppleScript名:POST method REST API__Slack_dnd.info.scptd |
— Created 2016-03-23 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use BridgePlus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html set accessToken to retAccessToken() —Access Token set reqURLStr to "https://slack.com/api/dnd.info" set aRec to {token:accessToken, user:"U11PVKT6D"} set aRes to callRestPOSTAPIAndParseResults(reqURLStr, aRec) of me set aRESTres to json of aRes set aRESCode to responseCode of aRes set aRESHeader to responseHeader of aRes –> {Content-Type:"application/json; charset=utf-8", Access-Control-Allow-Origin:"*", X-Amz-Cf-Id:"zOmILG860ZDWHHwDA5h7HtLNDqYd8nlQyL-Wf_dKfC-b5jDKkr_p8A==", Content-Security-Policy:"referrer no-referrer;", Content-Encoding:"gzip", Server:"Apache", X-XSS-Protection:"0", Transfer-Encoding:"Identity", Via:"1.1 f8ebfacf2280f8de661be7a1f87ba74e.cloudfront.net (CloudFront)", Date:"Tue, 19 Apr 2016 06:16:37 GMT", Strict-Transport-Security:"max-age=31536000; includeSubDomains; preload", Connection:"keep-alive", X-Content-Type-Options:"nosniff", Vary:"Accept-Encoding", X-Cache:"Miss from cloudfront"} aRESTres as list of string or string –> {next_dnd_start_ts:1461070800, next_dnd_end_ts:1461106800, snooze_enabled:0, ok:1, dnd_enabled:1} –POST methodのREST APIを呼ぶ on callRestPOSTAPIAndParseResults(aURL, aRec) load framework set aRes to retURLwithParams(aURL, aRec) of me if aRes = false then return false set aRequest to current application’s NSMutableURLRequest’s requestWithURL:(current application’s |NSURL|’s URLWithString:aRes) aRequest’s setHTTPMethod:"POST" aRequest’s setCachePolicy:(current application’s NSURLRequestReloadIgnoringLocalCacheData) aRequest’s setHTTPShouldHandleCookies:false aRequest’s setTimeoutInterval:60 –aRequest’s setValue:(token of aRec) forHTTPHeaderField:"token" –aRequest’s setValue:(channel of aRec) forHTTPHeaderField:"channel" –aRequest’s setValue:"application/json" forHTTPHeaderField:"Content-Type" –aRequest’s setHTTPBody:dataJson –CALL REST API set aRes to current application’s NSURLConnection’s sendSynchronousRequest:aRequest returningResponse:(reference) |error|:(missing value) –Parse Results set resList to aRes as list set bRes to contents of (first item of resList) set resStr to current application’s NSString’s alloc()’s initWithData:bRes encoding:(current application’s NSUTF8StringEncoding) log resStr set jsonString to current application’s NSString’s stringWithString:resStr set jsonData to jsonString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding) set aJsonDict to current application’s NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value) –Get Response Code set dRes to contents of second item of resList set resCode to ASify from (dRes’s statusCode()) –Get Response Header set resHeaders to ASify from (dRes’s allHeaderFields()) return {json:aJsonDict, responseCode:resCode, responseHeader:resHeaders} end callRestPOSTAPIAndParseResults on retAccessToken() return "xxxx-XXXXXXXXXXX-XXXXXXXXXXX-XXXXXXXXXXX-XXxXxxXXXX" end retAccessToken on retURLwithParams(aBaseURL, aRec) set aDic to current application’s NSMutableDictionary’s dictionaryWithDictionary:aRec set aKeyList to (aDic’s allKeys()) as list set aValList to (aDic’s allValues()) as list set aLen to length of aKeyList set bLen to length of aValList if aLen is not equal to bLen then return false set qList to {} repeat with i from 1 to aLen set aName to contents of item i of aKeyList set aVal to contents of item i of aValList set the end of qList to (current application’s NSURLQueryItem’s queryItemWithName:aName value:aVal) end repeat set aComp to current application’s NSURLComponents’s alloc()’s initWithString:aBaseURL aComp’s setQueryItems:qList set aURL to (aComp’s |URL|()’s absoluteString()) as text return aURL end retURLwithParams |
More from my site
(Visited 24 times, 1 visits today)