1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AUTOSAR CountdownAdvent Calendar 2022

Day 1

docker(102) RESAS-API をdockerで

Last updated at Posted at 2019-12-13

Ruby + RESAS-API で観光資源の位置情報(緯度経度)を取得する
https://qiita.com/niwasawa/items/608bbac1fbef3e086210

macOS
$ docker run -v /Users/administrator/Downloads/ruby:/tmp/ruby -p 8080:8080 -it ruby /bin/bash
ubuntu
# apt update; apt -y upgrade
# apt install -y vim wget apt-utils sudo
# vi resas.rb
# ruby resas.rb
{"statusCode"=>"403", "message"=>"Forbidden.", "description"=>""}
Traceback (most recent call last):
resas.rb:34:in `<main>': undefined method `[]' for nil:NilClass (NoMethodError)

市区町村一覧
https://opendata.resas-portal.go.jp/docs/api/v1/cities.html

GET api/v1/cities

| 都道府県 | 市町村 | 支庁市郡 | 区町村 | ふりがな | 変更 |
|:--|:--|:--|:--|:--|:--|:--|:--|:--|
| 23 | 100 | 名古屋市 | | なごやし | | | 政令指定都市 |
| 23 | 101 | 千種区 | ちくさく |
| 23 | 102 | 東区 | ひがしく |
| 23 | 103 | 北区 | きたく |
| 23 | 104 | 西区 | にしく |
| 23 | 105 | 中村区 | なかむらく |
| 23 | 106 | 中区 | なかく |
| 23 | 107 | 昭和区 | しょうわく |
| 23 | 108 | 瑞穂区 | みずほく |
| 23 | 109 | 熱田区 | あつたく |
| 23 | 110 | 中川区 | なかがわく |
| 23 | 111 | 港区 | みなとく |
| 23 | 112 | 南区 | みなみく |
| 23 | 113 | 守山区 | もりやまく |
| 23 | 114 | 緑区 | みどりく |
| 23 | 115 | 名東区 | めいとうく | 1975.0201 | 分離 | ←千種区,昭和区 |
| 23 | 116 | 天白区 | てんぱくく | 1975.0201 | 分離 | ←昭和区 |

require 'net/http'
require 'uri'
require 'json'

def get(url, params, headers)

  if params != nil && !params.empty?
    url += '?' + URI.encode_www_form(params)
  end

  uri = URI.parse(url)

  https = Net::HTTP.new(uri.host, uri.port)
  https.use_ssl = true

  req = Net::HTTP::Get.new(uri.request_uri, headers)
  res = https.request(req)

  json = res.body
  return JSON.parse(json)

end

url = 'https://opendata.resas-portal.go.jp/api/v1/tourism/attractions'
params = {
  'prefCode' => '23',
  'cityCode' => '100',
}
headers = {
  'X-API-KEY' => 'id'
}
data = get(url, params, headers)
puts data
data['result']['data'].each do |v|
  puts "#{v['resourceName']}: #{v['lat']},#{v['lng']}"
end
# ruby resas.rb
400
Traceback (most recent call last):
resas.rb:34:in `<main>': undefined method `[]' for nil:NilClass (NoMethodError)

docker hubに保存

docker run -v /Users/administrator/Downloads/ruby:/tmp/ruby -p 8080:8080 -it kaizenjapan/ruby_resas /bin/bash

文書履歴(document history)

ver. 0.01 初稿 20191213
ver. 0.02 加筆 20191214
ver. 0.03 標題加筆 20200101

最後までおよみいただきありがとうございました。

いいね 💚、フォローをお願いします。

Thank you very much for reading to the last sentence.

Please press the like icon 💚 and follow me for your happy life.

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?