AppleScript名:Returns the value in BTC |
— Created 2017-12-24 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.5" use scripting additions use framework "Foundation" property |NSURL| : a reference to current application’s |NSURL| property NSData : a reference to current application’s NSData property NSJSONSerialization : a reference to current application’s NSJSONSerialization set aInfo to retValueInBTC("JPY", "10000") of me –> "0.00654764" on retValueInBTC(aCurrency, aVal) set aRec to {currency:aCurrency, value:aVal} set reqURLStr to "https://blockchain.info/tobtc" set aURL to retURLwithParams(reqURLStr, aRec) of me try with timeout of 10 seconds set curl_command to "curl " & quoted form of aURL set jRes to do shell script curl_command return jRes end timeout on error return missing value end try end retValueInBTC 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 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 |
タグ: 10.11savvy
Bitcoin Exchange Rates APIを呼び出す
AppleScript名:Bitcoin Exchange Rates APIを呼び出す |
— Created 2017-12-11 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.5" use scripting additions use framework "Foundation" property |NSURL| : a reference to current application’s |NSURL| property NSData : a reference to current application’s NSData property NSJSONSerialization : a reference to current application’s NSJSONSerialization set aInfo to getBitcoinExchangeRating() of me as list of string or string –> {CNY:{15m:85561.31, sell:85497.93, symbol:"¥", last:85561.31, buy:85624.69}, PLN:{15m:45977.18, sell:45943.12, symbol:"zł", last:45977.18, buy:46011.23}, THB:{15m:426039.93, sell:425724.34, symbol:"฿", last:426039.93, buy:426355.52}, AUD:{15m:16863.96, sell:16851.47, symbol:"$", last:16863.96, buy:16876.45}, CLP:{15m:8071171.16, sell:8065192.44, symbol:"$", last:8071171.16, buy:8077149.89}, SEK:{15m:108311.42, sell:108231.19, symbol:"kr", last:108311.42, buy:108391.65}, BRL:{15m:43429.07, sell:43396.9, symbol:"R$", last:43429.07, buy:43461.24}, DKK:{15m:81673.5, sell:81613.0, symbol:"kr", last:81673.5, buy:81734.0}, GBP:{15m:9741.63, sell:9734.41, symbol:"£", last:9741.63, buy:9748.84}, RUB:{15m:759210.64, sell:758648.26, symbol:"RUB", last:759210.64, buy:759773.03}, CHF:{15m:12874.51, sell:12864.97, symbol:"CHF", last:12874.51, buy:12884.04}, ISK:{15m:1379204.64, sell:1378183.0, symbol:"kr", last:1379204.64, buy:1380226.29}, SGD:{15m:17490.64, sell:17477.68, symbol:"$", last:17490.64, buy:17503.6}, EUR:{15m:11399.17, sell:11385.02, symbol:"€", last:11399.17, buy:11413.33}, NZD:{15m:18527.65, sell:18513.92, symbol:"$", last:18527.65, buy:18541.37}, USD:{15m:13013.82, sell:13004.18, symbol:"$", last:13013.82, buy:13023.46}, TWD:{15m:389815.96, sell:389527.21, symbol:"NT$", last:389815.96, buy:390104.72}, KRW:{15m:14025514.37, sell:14015124.95, symbol:"₩", last:14025514.37, buy:14035903.78}, JPY:{15m:1474075.39, sell:1472983.47, symbol:"¥", last:1474075.39, buy:1475167.31}, INR:{15m:833116.13, sell:832498.99, symbol:"₹", last:833116.13, buy:833733.26}, HKD:{15m:101728.97, sell:101653.61, symbol:"$", last:101728.97, buy:101804.32}, CAD:{15m:16568.51, sell:16556.23, symbol:"$", last:16568.51, buy:16580.78}} set aVal to (aInfo’s valueForKeyPath:"JPY") as list of string or string –> {15m:1483814.35, sell:1483366.93, symbol:"¥", last:1483814.35, buy:1484261.76} on getBitcoinExchangeRating() try with timeout of 10 seconds set link to "https://blockchain.info/ticker" –Exchange Rates API set theURL to |NSURL|’s URLWithString:link set jsonData to NSData’s dataWithContentsOfURL:theURL set aJsonDict to (NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value)) return aJsonDict end timeout on error return missing value end try end getBitcoinExchangeRating |
GET method REST API_Anime API_getInfo_in_a_year_and_cour v2
AppleScript名:GET method REST API_Anime API_getInfo_in_a_year_and_cour v2 |
— Created 2016-05-11 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aYear to 2018 set aCour to 1 set reqURLStr to "http://api.moemoe.tokyo/anime/v1/master/" & (aYear as string) & "/" & (aCour as string) set aRes to callRestGETAPIAndParseResults(reqURLStr) of me set aRESTres to json of aRes set aRESCode to responseCode of aRes –> 200 set aRESHeader to (responseHeader of aRes) as list of string or string –> {Connection:"keep-alive", Access-Control-Allow-Origin:"*", Content-Type:"application/json; charset=utf-8", Content-Length:"353", Server:"nginx/1.8.0", Date:"Wed, 11 May 2016 01:14:49 GMT"} return aRESTres as list of string or string –> (NSArray) {{id:281, title_short3:"", sex:0, sequel:0, created_at:"2016-01-01 23:40:06.0", public_url:"http://gundam-tb.net/", twitter_hash_tag:"gundam_tb", title:"機動戦士ガンダム サンダーボルト", updated_at:"2016-01-01 23:40:06.0", twitter_account:"gundam_tb", title_short1:"サンダーボルト", title_short2:"", cours_id:9}, ……. –GET methodのREST APIを呼ぶ on callRestGETAPIAndParseResults(aURL) –Request set aRequest to current application’s NSMutableURLRequest’s requestWithURL:(current application’s |NSURL|’s URLWithString:aURL) aRequest’s setHTTPMethod:"GET" aRequest’s setCachePolicy:(current application’s NSURLRequestReloadIgnoringLocalCacheData) aRequest’s setHTTPShouldHandleCookies:false aRequest’s setTimeoutInterval:60 –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) 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 (dRes’s statusCode()) as list of string or string –Get Response Header set resHeaders to (dRes’s allHeaderFields()) as list of string or string return {json:aJsonDict, responseCode:resCode, responseHeader:resHeaders} end callRestGETAPIAndParseResults |
GET method REST API_Anime API_getInfo_in_a_year v2
AppleScript名:GET method REST API_Anime API_getInfo_in_a_year v2 |
— Created 2016-05-11 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set reqURLStr to "http://api.moemoe.tokyo/anime/v1/master/" & "2016" set aRes to callRestGETAPIAndParseResults(reqURLStr) of me set aRESTres to json of aRes set aRESCode to responseCode of aRes –> 200 set aRESHeader to (responseHeader of aRes) as list of string or string –as anything –> {Connection:"keep-alive", Access-Control-Allow-Origin:"*", Content-Type:"application/json; charset=utf-8", Content-Length:"353", Server:"nginx/1.8.0", Date:"Wed, 11 May 2016 01:14:49 GMT"} return aRESTres as list of string or string –> {{id:281, title:"機動戦士ガンダム サンダーボルト"}, {id:282, title:"プリンス・オブ・ストライド オルタナティブ"}, {id:283, title:"無彩限のファントム・ワールド"}, {id:284, title:"ハルチカ〜ハルタとチカは青春する〜"}, {id:285, title:"ノルン+ノネット"}, {id:286, title:"アクティヴレイド -機動強襲室第八係-"}, {id:287, title:"少女たちは荒野を目指す"}, {id:288, title:"僕だけがいない街"}, {id:289, title:"おじさんとマシュマロ"}, {id:290, title:"ファンタシースターオンライン2 ジ アニメーション"}, {id:291, title:"だがしかし"}, {id:292, title:"暗殺教室(第2期)"}, {id:293, title:"ディバインゲート"}, {id:294, title:"おしえて!ギャル子ちゃん"}, {id:295, title:"石膏ボーイズ"}, {id:296, title:"霊剣山 星屑たちの宴"}, {id:297, title:"GATE 自衛隊 彼の地にて、斯く戦えり(2期)"}, {id:298, title:"昭和元禄落語心中"}, {id:299, title:"紅殻のパンドラ"}, {id:300, title:"ブブキ・ブランキ"}, {id:301, title:"ラクエンロジック"}, {id:302, title:"デュラララ!!×2 結"}, {id:303, title:"ナースウィッチ小麦ちゃんR"}, {id:304, title:"虹色デイズ"}, {id:305, title:"大家さんは思春期!"}, {id:306, title:"Dimension W"}, {id:307, title:"灰と幻想のグリムガル"}, {id:308, title:"シュヴァルツェスマーケン"}, {id:309, title:"最弱無敗の神装機竜(バハムート)"}, {id:310, title:"赤髪の白雪姫(第2期)"}, {id:311, title:"てーきゅう(第7期)"}, {id:312, title:"魔法少女なんてもういいですから。"}, {id:313, title:"蒼の彼方のフォーリズム"}, {id:314, title:"この素晴らしい世界に祝福を!"}, {id:315, title:"亜人"}, {id:316, title:"FAIRY TAIL ZERO"}, {id:317, title:"ももくり"}, {id:318, title:"この男子、魔法がお仕事です。"}, {id:319, title:"SUSHI POLICE"}, {id:320, title:"血液型くん!4"}, {id:321, title:"迷家‐マヨイガ‐"}, {id:322, title:"宇宙パトロールルル子"}, {id:323, title:"機動戦士ガンダムユニコーン RE:0096"}, {id:324, title:"影鰐-KAGEWANI-承"}, {id:325, title:"ぼのぼの"}, {id:326, title:"フューチャーカード バディファイト トリプルディー"}, {id:327, title:"逆転裁判"}, {id:328, title:"学戦都市アスタリスク 2nd SEASON"}, {id:329, title:"僕のヒーローアカデミア"}, {id:330, title:"マクロス⊿"}, {id:331, title:"コンクリート・レボルティオ~超人幻想~THE LAST SONG"}, {id:332, title:"くまみこ"}, {id:333, title:"怪盗ジョーカー(シーズン3)"}, {id:334, title:"ばくおん!!"}, {id:335, title:"聖戦ケルベロス 竜刻のファタリテ"}, {id:336, title:"ハンドレッド"}, {id:337, title:"薄桜鬼~御伽草子~"}, {id:338, title:"ジョーカー・ゲーム"}, {id:339, title:"双星の陰陽師"}, {id:340, title:"SUPER LOVERS"}, {id:341, title:"鬼斬"}, {id:342, title:"文豪ストレイドッグス"}, {id:343, title:"あんハピ♪"}, {id:344, title:"クロムクロ"}, {id:345, title:"ネトゲの嫁は女の子じゃないと思った?"}, {id:346, title:"甲鉄城のカバネリ"}, {id:347, title:"少年メイド"}, {id:348, title:"坂本ですが?"}, {id:349, title:"田中くんはいつもけだるげ"}, {id:350, title:"キズナイーバー"}, {id:351, title:"はいふり"}, {id:352, title:"ふらいんぐうぃっち"}, {id:353, title:"とんかつDJアゲ太郎"}, {id:354, title:"三者三葉"}, {id:355, title:"うさかめ"}, {id:356, title:"マギ シンドバッドの冒険"}, {id:357, title:"Re:ゼロから始める異世界生活"}, {id:358, title:"うしおととら(第3クール)"}, {id:359, title:"ワガママハイスペック"}, {id:360, title:"ジョジョの奇妙な冒険 ダイヤモンドは砕けない"}, {id:361, title:"テラフォーマーズ リベンジ"}, {id:362, title:"プリパラ(3rdシーズン)"}, {id:363, title:"エンドライド"}, {id:364, title:"ビッグオーダー"}} –GET methodのREST APIを呼ぶ on callRestGETAPIAndParseResults(aURL) –Request set aRequest to current application’s NSMutableURLRequest’s requestWithURL:(current application’s |NSURL|’s URLWithString:aURL) aRequest’s setHTTPMethod:"GET" aRequest’s setCachePolicy:(current application’s NSURLRequestReloadIgnoringLocalCacheData) aRequest’s setHTTPShouldHandleCookies:false aRequest’s setTimeoutInterval:60 –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) 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 (dRes’s statusCode()) as list of string or string –as anything –Get Response Header set resHeaders to (dRes’s allHeaderFields()) as list of string or string –as anything return {json:aJsonDict, responseCode:resCode, responseHeader:resHeaders} end callRestGETAPIAndParseResults |
GET method REST API_Anime API_get cours v2
AppleScript名:GET method REST API_Anime API_get cours v2 |
— Created 2016-05-11 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set reqURLStr to "http://api.moemoe.tokyo/anime/v1/master/cours" set aRes to callRestGETAPIAndParseResults(reqURLStr) of me set aRESTres to json of aRes set aRESCode to responseCode of aRes –> 200 set aRESHeader to (responseHeader of aRes) as list of string or string –> {Connection:"keep-alive", Access-Control-Allow-Origin:"*", Content-Type:"application/json; charset=utf-8", Content-Length:"353", Server:"nginx/1.8.0", Date:"Wed, 11 May 2016 01:14:49 GMT"} return aRESTres as list of string or string –as anything –> {7:{id:7, year:2015, cours:3}, 3:{id:3, year:2014, cours:3}, 8:{id:8, year:2015, cours:4}, 4:{id:4, year:2014, cours:4}, 9:{id:9, year:2016, cours:1}, 5:{id:5, year:2015, cours:1}, 1:{id:1, year:2014, cours:1}, 6:{id:6, year:2015, cours:2}, 10:{id:10, year:2016, cours:2}, 2:{id:2, year:2014, cours:2}} –GET methodのREST APIを呼ぶ on callRestGETAPIAndParseResults(aURL) –Request set aRequest to current application’s NSMutableURLRequest’s requestWithURL:(current application’s |NSURL|’s URLWithString:aURL) aRequest’s setHTTPMethod:"GET" aRequest’s setCachePolicy:(current application’s NSURLRequestReloadIgnoringLocalCacheData) aRequest’s setHTTPShouldHandleCookies:false aRequest’s setTimeoutInterval:60 –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) 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 (dRes’s statusCode()) as list of string or string –as anything –Get Response Header set resHeaders to (dRes’s allHeaderFields()) as list of string or string –as anything return {json:aJsonDict, responseCode:resCode, responseHeader:resHeaders} end callRestGETAPIAndParseResults |
POST method REST API__Slack_users.list
SlackのREST APIを呼び出してチーム内のユーザー一覧を取得する(users.list)AppleScriptです。
SLackにサインアップしてAPIのアクセストークンを取得し、プログラムリスト中に記入して実行してください。
AppleScript名:POST method REST API__Slack_users.list.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/users.list" set aRec to {token:accessToken, presence:"1"} –#applescript 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 –> {members:{{id:"U11PVKT6D", real_name:"Takaaki Naganoya", profile:{image_24:"https://secure.gravatar.com/avatar/e7a98cc29b3b4a35f38226814d60415c.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F66f9%2Fimg%2Favatars%2Fava_0026-24.png", real_name:"Takaaki Naganoya", real_name_normalized:"Takaaki Naganoya", image_48:"https://secure.gravatar.com/avatar/e7a98cc29b3b4a35f38226814d60415c.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F272a%2Fimg%2Favatars%2Fava_0026-48.png", image_72:"https://secure.gravatar.com/avatar/e7a98cc29b3b4a35f38226814d60415c.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F66f9%2Fimg%2Favatars%2Fava_0026-72.png", image_192:"https://secure.gravatar.com/avatar/e7a98cc29b3b4a35f38226814d60415c.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F7fa9%2Fimg%2Favatars%2Fava_0026-192.png", avatar_hash:"ge7a98cc29b3", image_32:"https://secure.gravatar.com/avatar/e7a98cc29b3b4a35f38226814d60415c.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F0180%2Fimg%2Favatars%2Fava_0026-32.png", first_name:"Takaaki", last_name:"Naganoya", email:"maro@piyocast.com", image_512:"https://secure.gravatar.com/avatar/e7a98cc29b3b4a35f38226814d60415c.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F7fa9%2Fimg%2Favatars%2Fava_0026-512.png"}, is_owner:1, is_restricted:0, is_primary_owner:1, tz_label:"Japan Standard Time", is_ultra_restricted:0, tz:"Asia/Tokyo", has_2fa:0, presence:"active", color:"9f69e7", deleted:0, tz_offset:32400, is_bot:0, team_id:"T11N8QR19", is_admin:1, name:"maro", status:missing value}, {id:"USLACKBOT", real_name:"slackbot", profile:{image_24:"https://a.slack-edge.com/0180/img/slackbot_24.png", real_name:"slackbot", image_48:"https://a.slack-edge.com/2fac/plugins/slackbot/assets/service_48.png", image_72:"https://a.slack-edge.com/0180/img/slackbot_72.png", image_192:"https://a.slack-edge.com/66f9/img/slackbot_192.png", real_name_normalized:"slackbot", image_32:"https://a.slack-edge.com/2fac/plugins/slackbot/assets/service_32.png", avatar_hash:"sv1444671949", fields:missing value, first_name:"slackbot", last_name:"", image_512:"https://a.slack-edge.com/7fa9/img/slackbot_512.png", email:missing value}, is_owner:0, is_restricted:0, is_primary_owner:0, tz_label:"Pacific Daylight Time", is_ultra_restricted:0, tz:missing value, color:"757575", deleted:0, tz_offset:-25200, is_bot:0, team_id:"T11N8QR19", is_admin:0, name:"slackbot", status:missing value}}, cache_ts:1461054217, ok: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 |
POST method REST API__Slack_users.info
SlackのREST APIを呼び出してチーム内のユーザー情報を取得する(users.info)AppleScriptです。
SLackにサインアップしてAPIのアクセストークンを取得し、プログラムリスト中に記入して実行してください。
AppleScript名:POST method REST API__Slack_users.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/users.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 –> {user:{id:"U11PVKT6D", real_name:"Takaaki Naganoya", profile:{image_24:"https://secure.gravatar.com/avatar/e7a98cc29b3b4a35f38226814d60415c.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2F66f9%2Fimg%2Favatars%2Fava_0026-24.png", real_name:"Takaaki Naganoya", real_name_normalized:"Takaaki Naganoya", image_48:"https://secure.gravatar.com/avatar/e7a98cc29b3b4a35f38226814d60415c.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2F272a%2Fimg%2Favatars%2Fava_0026-48.png", image_72:"https://secure.gravatar.com/avatar/e7a98cc29b3b4a35f38226814d60415c.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2F66f9%2Fimg%2Favatars%2Fava_0026-72.png", image_192:"https://secure.gravatar.com/avatar/e7a98cc29b3b4a35f38226814d60415c.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2F7fa9%2Fimg%2Favatars%2Fava_0026-192.png", avatar_hash:"ge7a98cc29b3", image_32:"https://secure.gravatar.com/avatar/e7a98cc29b3b4a35f38226814d60415c.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2F0180%2Fimg%2Favatars%2Fava_0026-32.png", first_name:"Takaaki", last_name:"Naganoya", email:"maro@piyocast.com", image_512:"https://secure.gravatar.com/avatar/e7a98cc29b3b4a35f38226814d60415c.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F7fa9%2Fimg%2Favatars%2Fava_0026-512.png"}, is_owner:1, is_restricted:0, is_primary_owner:1, tz_label:"Japan Standard Time", is_ultra_restricted:0, tz:"Asia/Tokyo", has_2fa:0, color:"9f69e7", deleted:0, tz_offset:32400, is_bot:0, team_id:"T11N8QR19", is_admin:1, name:"maro", status:missing value}, ok: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 |
POST method REST API__Slack_users.getPresence
SlackのREST APIを呼び出してユーザーの所在情報を取得する(users.getPresence)AppleScriptです。
SLackにサインアップしてAPIのアクセストークンを取得し、プログラムリスト中に記入して実行してください。
AppleScript名:POST method REST API__Slack_users.getPresence.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/users.getPresence" 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 –> {presence:"away", auto_away:false, connection_count:0, online:false, ok:true, manual_away:false} –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 |
POST method REST API__Slack_usergroups.list
SlackのREST APIを呼び出してチーム内のユーザーグループ一覧を取得する(usergroups.list)AppleScriptです。
SLackにサインアップしてAPIのアクセストークンを取得し、プログラムリスト中に記入して実行してください。
AppleScript名:POST method REST API__Slack_usergroups.list |
— 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/usergroups.list" set aRec to {token:accessToken, include_disabled:"1", include_count:"1", include_users:"1"} 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 –> {usergroups:{}, ok: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 |
POST method REST API__Slack_groups.list
SlackのREST APIを呼び出してユーザーがアクセス可能なプライベートなチャンネル一覧を取得する(groups.list)AppleScriptです。
SLackにサインアップしてAPIのアクセストークンを取得し、プログラムリスト中に記入して実行してください。
AppleScript名:POST method REST API__Slack_groups.list |
— 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/groups.info" set aRec to {token:accessToken, channel:"C11NJCBU3"} 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 –> {error:"channel_not_found", ok:0} –本Scriptはまだチェックが必要と思われる –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 |
POST method REST API__Slack_files.list
SlackのREST APIを呼び出してチーム内のファイル一覧を取得する(files.list)AppleScriptです。
SLackにサインアップしてAPIのアクセストークンを取得し、プログラムリスト中に記入して実行してください。
AppleScript名:POST method REST API__Slack_files.list.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/files.list" 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 –> {files:{}, paging:{pages:0, count:100, total:0, page:1}, ok: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 |
POST method REST API__Slack_emoji.list
SlackのREST APIを呼び出してチーム向けのカスタム絵文字リストを取得する(emoji.list)AppleScriptです。
SLackにサインアップしてAPIのアクセストークンを取得し、プログラムリスト中に記入して実行してください。
AppleScript名:POST method REST API__Slack_emoji.list.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/emoji.list" set aRec to {token:accessToken} 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 –> {emoji:{feelsgood:"https://emoji.slack-edge.com/T11N8QR19/feelsgood/7bcbaa15fa.png", rage3:"https://emoji.slack-edge.com/T11N8QR19/rage3/8e11678fbf.png", squirrel:"https://emoji.slack-edge.com/T11N8QR19/squirrel/465f40c0e0.png", piggy:"https://emoji.slack-edge.com/T11N8QR19/piggy/b7762ee8cd.png", beryl:"https://emoji.slack-edge.com/T11N8QR19/beryl/efe1ba7e7a.png", dusty_stick:"https://emoji.slack-edge.com/T11N8QR19/dusty_stick/6177a62312.png", shipit:"alias:squirrel", white_square:"alias:white_large_square", hurtrealbad:"https://emoji.slack-edge.com/T11N8QR19/hurtrealbad/b9c3d648e6.png", rage2:"https://emoji.slack-edge.com/T11N8QR19/rage2/feaf8897c6.png", rube:"https://emoji.slack-edge.com/T11N8QR19/rube/74ef8ef199.png", black_square:"alias:black_large_square", glitch_crab:"https://emoji.slack-edge.com/T11N8QR19/glitch_crab/db049f1f9c.png", finnadie:"https://emoji.slack-edge.com/T11N8QR19/finnadie/08e66eb46d.png", rage1:"https://emoji.slack-edge.com/T11N8QR19/rage1/0c3685290c.png", troll:"alias:trollface", slack:"https://emoji.slack-edge.com/T11N8QR19/slack/5ee0c9bea3.png", fu:"https://emoji.slack-edge.com/T11N8QR19/fu/2f615de37f.png", neckbeard:"https://emoji.slack-edge.com/T11N8QR19/neckbeard/c8ec7bf188.png", metal:"https://emoji.slack-edge.com/T11N8QR19/metal/9f936a4278.png", cubimal_chick:"https://emoji.slack-edge.com/T11N8QR19/cubimal_chick/85961c43d7.png", bowtie:"https://emoji.slack-edge.com/T11N8QR19/bowtie/f3ec6f2bb0.png", godmode:"https://emoji.slack-edge.com/T11N8QR19/godmode/1bd6476fbb.png", pride:"https://emoji.slack-edge.com/T11N8QR19/pride/56b1bd3388.png", simple_smile:"https://a.slack-edge.com/66f9/img/emoji_2015/apple-old/simple_smile.png", rage4:"https://emoji.slack-edge.com/T11N8QR19/rage4/a8029a3996.png", trollface:"https://emoji.slack-edge.com/T11N8QR19/trollface/8c0ac4ae98.png", octocat:"https://emoji.slack-edge.com/T11N8QR19/octocat/627964d7c9.png", goberserk:"https://emoji.slack-edge.com/T11N8QR19/goberserk/d8b892d59b.png", suspect:"https://emoji.slack-edge.com/T11N8QR19/suspect/ca4ab3c7c7.png"}, cache_ts:"1452230549.000000", ok: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-XXxXxxXXX8" 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 |
POST method REST API__Slack_dnd.teaminfo
SlackのREST APIを呼び出してチームのDo Not Disturbステータスを取得する(dnd.teaminfo)AppleScriptです。
SLackにサインアップしてAPIのアクセストークンを取得し、プログラムリスト中に記入して実行してください。
AppleScript名:POST method REST API__Slack_dnd.teaminfo.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.teamInfo" 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 –> {users:{U11PVKT6D:{next_dnd_start_ts:1461070800, dnd_enabled:1, next_dnd_end_ts:1461106800}}, ok: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 |
POST method REST API__Slack_dnd.info
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 |
POST method REST API__Slack_chat.update
SlackのREST APIを呼び出してチャット内容のアップデート(chat.update)を実行するAppleScriptです。
SLackにサインアップしてAPIのアクセストークンを取得し、プログラムリスト中に記入して実行してください。
AppleScript名:POST method REST API__Slack_chat.update |
— 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/chat.update" set aRec to {token:accessToken, include_disabled:"1", include_count:"1", include_users:"1"} 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 –> {error:"channel_not_found", ok:0} –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 |
POST method REST API__Slack_chat.postMessage
SlackのREST APIを呼び出してチャット投稿(chat.postMessage)を実行するAppleScriptです。
SLackにサインアップしてAPIのアクセストークンを取得し、プログラムリスト中に記入して実行してください。
AppleScript名:POST method REST API__Slack_chat.postMessage |
— 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/chat.postMessage" set aRec to {token:accessToken, channel:"C11NJCBU3", |text|:"こんにちは", parse:"full", link_names:"1", username:"piyomaruBot"} set aRes to callWebPOSTAPIAndParseResults(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 –> {ts:"1461111976.000006", message:{username:"bot", ts:"1461111976.000006", type:"message", subtype:"bot_message", text:"こんにちは"}, channel:"C11NJCBU3", ok:1} –POST methodのWeb APIを呼ぶ on callWebPOSTAPIAndParseResults(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 callWebPOSTAPIAndParseResults 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 |
POST method REST API__Slack_channels.list
SlackのREST APIを呼び出してチャンネル一覧取得(channels.list)を実行するAppleScriptです。
SLackにサインアップしてAPIのアクセストークンを取得し、プログラムリスト中に記入して実行してください。
AppleScript名:POST method REST API__Slack_channels.list.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/channels.list" set aRec to {token:accessToken, exclude_archived:"1"} 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 –> {channels:{{id:"C11NJCBU3", num_members:1, members:{"U11PVKT6D"}, is_general:0, is_archived:0, topic:{value:"", creator:"", last_set:0}, creator:"U11PVKT6D", is_member:1, is_channel:1, created:1461049266, purpose:{value:"AppleScript Talk", creator:"U11PVKT6D", last_set:1461049267}, name:"applescript"}, {id:"C11PQC1AT", num_members:1, members:{"U11PVKT6D"}, is_general:1, is_archived:0, topic:{value:"Company-wide announcements and work-based matters", creator:"", last_set:0}, creator:"U11PVKT6D", is_member:1, is_channel:1, created:1461045242, purpose:{value:"This channel is for team-wide communication and announcements. All team members are in this channel.", creator:"", last_set:0}, name:"general"}, {id:"C11PQC1C7", num_members:1, members:{"U11PVKT6D"}, is_general:0, is_archived:0, topic:{value:"Non-work banter and water cooler conversation", creator:"", last_set:0}, creator:"U11PVKT6D", is_member:1, is_channel:1, created:1461045242, purpose:{value:"A place for non-work-related flimflam, faffing, hodge-podge or jibber-jabber you’d prefer to keep out of more focused work-related channels.", creator:"", last_set:0}, name:"random"}}, ok: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 |
POST method REST API__Slack_channels.info
SlackのREST APIを呼び出してチャンネル情報取得(channels.info)を実行するAppleScriptです。
SLackにサインアップしてAPIのアクセストークンを取得し、プログラムリスト中に記入して実行してください。
AppleScript名:POST method REST API__Slack_channels.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/channels.info" set aRec to {token:accessToken, channel:"C11NJCBU3"} –#applescript 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 –> {error:"channel_not_found", ok:0} –> {channel:{id:"C11NJCBU3", members:{"U11PVKT6D"}, last_read:"0000000000.000000", is_general:0, unread_count:0, is_archived:0, topic:{value:"", creator:"", last_set:0}, creator:"U11PVKT6D", is_member:1, is_channel:1, created:1461049266, unread_count_display:0, purpose:{value:"AppleScript Talk", creator:"U11PVKT6D", last_set:1461049267}, name:"applescript", latest:{text:"<@U11PVKT6D|maro> set the channel purpose: AppleScript Talk", purpose:"AppleScript Talk", ts:"1461049267.000003", type:"message", subtype:"channel_purpose", user:"U11PVKT6D"}}, ok: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 |
POST method REST API__Slack_auth.test
AppleScript名:POST method REST API__Slack_auth.test.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/auth.test" set aRec to {token:accessToken} 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 –> {user:"maro", team_id:"X99X9XX99", user_id:"X99XXXX9X", ok:1, url:"https://piyomarusoftware.slack.com/", team:"Piyomaru Software"} –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 |
POST method REST API__Slack_api.test
SlackのREST APIを呼び出してAPI呼び出しテスト(api.test)を実行するAppleScriptです。
SlackにサインアップしてAPIのアクセストークンを取得し、プログラムリスト中に記入して実行してください。
AppleScript名:POST method REST API__Slack_api.test |
— 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/api.test" set aRes to callRestPOSTAPIAndParseResults(reqURLStr, accessToken) of me set aRESTres to json of aRes set aRESCode to responseCode of aRes –> 200 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 –> {ok:1} –POST methodのREST APIを呼ぶ on callRestPOSTAPIAndParseResults(aURL, anAPIkey) load framework set aRequest to current application’s NSMutableURLRequest’s requestWithURL:(current application’s |NSURL|’s URLWithString:aURL) aRequest’s setHTTPMethod:"POST" aRequest’s setCachePolicy:(current application’s NSURLRequestReloadIgnoringLocalCacheData) aRequest’s setHTTPShouldHandleCookies:false aRequest’s setTimeoutInterval:60 aRequest’s setValue:anAPIkey forHTTPHeaderField:"Authorization" –aRequest’s setValue:jsonString forHTTPHeaderField:"Dropbox-API-Arg" –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 |