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