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 |
More from my site
(Visited 31 times, 1 visits today)