ä»äºã§ã¯ã¨ã³ã¸ãã¢ã§ãããªããWordãExcelã°ãã使ã£ã¦ãã¯ãã«ã«ãªæç« ãå¹´æããããã¾ã§æ¸ããªãã¨ãããªãã®ã§ãèªå·±åçºçã«ããã°ã©ãã³ã°ã
ä¹ ã ã«Rubyã触ã£ã¦ã¿ã¾ãããã¨ã¯è¨ã£ã¦ã家ã«å¸°ãã¨ãããã§å¯ã¦ãã¾ãã®ã§éå¤æéã§ããã¾ãã
ããããç´ æ´ãããã¢ããªããããã§ããããããããã (id:tuto0621)ãããã®ããã°ãæè¦ãã¦ãã¦ç¥ãã¾ãããiPhoneXã§ãã°ã£ã¡ãåãã¾ãã
ã¡ãã£ã¨ä¸ä¸ã足ãã¦ã¾ããããiPhoneã ãã§Rubyãå®è¡ã§ãã¾ããPythonã®Pythonistaã¨åãã¢ããªã§ãããRubyPicoã¯ç¡æã§ãããéã¨ã£ã¦ããã¬ãã«ãªã®ã§éå¤é»è»ã§ããã°ã©ãã³ã°ããã人ã¯å ¥ãã¦ããã¹ãã§ãã
iPhoneXã®ç»é¢ãµã¤ãºã«å¯¾å¿ãã¦ã»ãããªãããã¨ããããªãã
ã¹ã¯ã·ã§ã«ã³ã¼ããè²¼ã£ã¦ããã¾ãããæç²ãã¦ããã¨ãããªæãã
# é§ ãã¼ã¿.jp ããå±±æç·ã®è·¯ç·ãã¼ã¿ãåå¾ãã # ããã¯ããã§ããã®ã§ã³ã¡ã³ã #url = "http://www.ekidata.jp/api/l/11302.json" # ã©ããããããªããã©å±±æç·ãã¼ã¿ url = "http://express.heartrails.com/api/json?method=getStations&line=JR" # URLã®æå¾ã«æ¥æ¬èªã§ãå±±æç·ãã¨ä»ä¸ããã®ã§ã # æ¥æ¬èªã ãã¨ã³ã³ã¼ã m = URI.encode_www_form_component("å±±æç·") # äºçªç®ã®å¼æ°ã¯é©å½ # çç¥ãããæããã (ãË・з・Ë) json = Browser.post(url + m, json:"") # ã³ã³ã½ã¼ã«ã«è¡¨ç¤º puts json
ã¨ããæãã®ããããç°¡åãªã³ã¼ãã§ããWeb APIã¨ããã®ãè¿å¹´çµæ§å¢ãã¦ãã¦ãæ§ã ãªãã¼ã¿ãURLå©ãã¦ãããã¾ãããã®ä¾ã ã¨å±±æç·ã®è·¯ç·ãã¼ã¿ãåãã¾ãã
å¤åè¦ç´ ã®ãªããã¼ã¿ã¯ããã°ã©ã ã§æ±ãæã¦ã°ããã®ã§ãããç·´ç¿ã§ãã®ã§è·¯ç·ãã¼ã¿ãåã£ã¦ãã¦ã¾ãã
ãé§ ãã¼ã¿.jpãã¨ãããµã¤ãã®APIã§JSONãã¼ã¿ãåå¾ãã¦ã¿ãã®ã§ããããªããå½¢å¼ãæ°ã«å ¥ããªãã¦ãã¼ã¹ã§ããªãã£ãã®ã§ãããä¸ã¤ã®æ¹ã«ãã¦ã¿ã¾ããã
http://express.heartrails.com/api/json?method=getStations&line=JRå±±æç·
ã¨ããã®ãå ¬éããã¦ããURLãªã®ã§ãããã©ã¹ããæ¥æ¬èªãªã®ã§ã¨ã³ã³ã¼ããã¾ãããã¾ãèããªãã¿ã¤ããªã®ã§ã
URI.encode_www_form_component("http://express.heartrails.com/api/json?method=getStations&line=JRå±±æç·")
ã¨ããããªãããã¡ãã¡å¤æããã¦ãã¡ã ã£ãã®ã§ãè²¼ã£ãã³ã¼ãã®ããã«ãå±±æç·ãã ããå¤æãã¦ãã£ã¤ãã¦ã¿ã¾ããã
å°æå ã®æè¡ã ããªã誰ã«ãè² ããªãã
ãã¨ã¯postã§éãã ããªã®ã§ãããnet/http ã使ããªãã¿ããã ã£ãã®ã§ Browser ã使ãã¾ãããã³ã¡ã³ãã«ãæ¸ããéãäºçªç®ã®å¼æ°ãããããããªãã£ãã®ã§ç©ºæåã«ã
å®è¡ããã¨ã
{"response":{"station":[{"postal":"1080075","x":139.738535,"next":"大å´","prev":"ç°çº","y":35.628135,"line":"JRå±±æç·","prefecture":"æ±äº¬é½","name":"åå·"},{"postal":"1410032","x":139.728246,"next":"äºåç°","prev":"åå·","y":35.61994,"line":"JRå±±æç·","prefecture":"æ±äº¬é½","name":"大å´"},
ã¨ãããã¼ã¿ãè¿ã£ã¦ãã¾ãã(ä¸ã®ã¯ä¸é¨ã ãæç²)ãããã§ãã¨ã¯JSONã§æ±ãã ãã§ãã
# # å±±æç·ã®è·¯ç·ãã¼ã¿ãåå¾ã㦠# é§ åã表示ããããã°ã©ã # class YamanoteLine # # URLãåå¾ãã # def get_url # ã©ããããããªããã©å±±æç·ãã¼ã¿ url = "http://express.heartrails.com/api/json?method=getStations&line=JR" # URLã®æå¾ã«æ¥æ¬èªã§ãå±±æç·ãã¨ä»ä¸ããã®ã§ã # æ¥æ¬èªã ãã¨ã³ã³ã¼ã m = URI.encode_www_form_component("å±±æç·") return url + m end # # è·¯ç·ãã¼ã¿ãåå¾ # def get_json # äºçªç®ã®å¼æ°ã¯é©å½ # çç¥ãããæããã (ãË・з・Ë) json = Browser.post(get_url(), json:"") return JSON.parse(json) end # # åå¾ãããã¼ã¿ãç·¨é # def edit_json pjson = get_json() response = pjson['response'] station = response['station'] station.each do |val| puts val['name'] end end end # èµ·åå¦ç line = YamanoteLine.new line.edit_json()
Rubyã®ãªãããªãå ¼ãã¦ããã®ã§ãã¯ã©ã¹ãä½ã£ã¦ã¡ã½ãããä½ãã¾ããããã¾ãæå³ã®ããã¡ã½ããåå²ã§ã¯ãªãã®ã§ãããã¾ãã¨ããããã
JSONãã¼ã¿ããã¼ã¹ãã¦ããã·ã¥ã«ãããã®ãé 次åãåºãããã«ãã¦ã¿ã¾ããããããåããã¨ã
åå· å¤§å´ äºåç° ç®é» æµæ¯å¯¿ æ¸è°· å宿 代ã æ¨ æ°å®¿ æ°å¤§ä¹ ä¿ é«ç°é¦¬å ´ ç®ç½ æ± è¢ å¤§å¡ å·£é´¨ é§è¾¼ ç°ç«¯ 西æ¥æ®é æ¥æ®é 鶯谷 ä¸é 御å¾çº ç§èå ç¥ç° æ±äº¬ ææ¥½çº æ°æ© æµæ¾çº ç°çº
ã¨ãåå·ããä¸å¨åã£ã¦ç°çºã¾ã§åãã¦ãã¾ããããããã©ãæ´»ç¨ãããã¯è¬ã§ããããããåå·ã¨ç°çºã®éã«æ°é§ ãã§ãããããã°ã©ã ãç´ããã«å®è¡ããã¨æ°ããé§ ãå«ãã æ å ±ãåããã¯ãã§ãã
ä»åã¯ããã¾ã§ã