kanazawa_city-infra 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +172 -0
- data/Rakefile +1 -0
- data/kanazawa_city-infra.gemspec +22 -0
- data/lib/kanazawa_city/infra/version.rb +5 -0
- data/lib/kanazawa_city-infra.rb +108 -0
- metadata +86 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Keisuke KITA
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
# KanazawaCity::Infra
|
2
|
+
|
3
|
+
石川県金沢市の地図情報基盤APIにアクセスするライブラリです.
|
4
|
+
市有施設などの公共データを利用できます.
|
5
|
+
APIの詳細については[施設情報の二次利用について](http://www4.city.kanazawa.lg.jp/11010/opendata/index.html)を参照してください.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'kanazawa_city-infra'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install kanazawa_city-infra
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
API呼び出し結果の詳細な項目については[施設情報の二次利用について](http://www4.city.kanazawa.lg.jp/11010/opendata/index.html)の「地図情報発信基盤API利用マニュアル」を参照してください.
|
24
|
+
```ruby
|
25
|
+
require 'kanazawa_city-infra'
|
26
|
+
|
27
|
+
# ジャンルの一覧を取得 ジャンル情報が格納された配列を返します
|
28
|
+
genres = KanazawaCity::Infra.genres
|
29
|
+
|
30
|
+
# 施設情報の検索 施設情報が格納されたオブジェクトの配列を返します
|
31
|
+
fs = KanazawaCity::Infra.facilities(keyword: "まちのり") # キーワード検索
|
32
|
+
|
33
|
+
## メソッド呼び出し,ハッシュ,両方の形式で値を取得可能
|
34
|
+
fs[0].name # => まちのり事務局
|
35
|
+
fs[0]['name'] # => まちのり事務局
|
36
|
+
|
37
|
+
f = fs[0].detail # 施設の詳細な情報を取得
|
38
|
+
puts f.summary # 施設の概要
|
39
|
+
|
40
|
+
KanazawaCity::Infra.facilities(geocode: "36.5946816,136.6255726,2000") # 範囲検索
|
41
|
+
KanazawaCity::Infra.facilities(genre: 1) # ジャンルのidで検索
|
42
|
+
KanazawaCity::Infra.facilities(genre: genres[0]) # 取得したジャンルのオブジェクトで検索
|
43
|
+
KanazawaCity::Infra.facilities(genre: ["12-28", "13"]) # 複数のジャンルを指定
|
44
|
+
KanazawaCity::Infra.facilities(genre: ["1", genres[1]]) # idとオブジェクトを組み合わせることも可能
|
45
|
+
|
46
|
+
## 1回の取得件数を10件にする(デフォルト20件, 最大50件)
|
47
|
+
fs = KanazawaCity::Infra.facilities(genre: 1, count: 10)
|
48
|
+
## 全ての検索結果を走査する
|
49
|
+
while fs.has_next?
|
50
|
+
fs = fs.next
|
51
|
+
pp fs
|
52
|
+
end
|
53
|
+
```
|
54
|
+
取得した情報の細かい絞り込みにはEnumerable#select, Enumerable#detectなどが便利です.
|
55
|
+
|
56
|
+
### 検索結果の施設情報の取得例
|
57
|
+
```ruby
|
58
|
+
{
|
59
|
+
"id"=>"2007",
|
60
|
+
"name"=>"金沢21世紀美術館",
|
61
|
+
"address"=>"金沢市広坂1-2-1",
|
62
|
+
"url"=>"http://www.kanazawa21.jp/",
|
63
|
+
"tel"=>"076-220-2800",
|
64
|
+
"coordinates"=>{"latitude"=>36.5608672, "longitude"=>136.6582577},
|
65
|
+
"genres"=>
|
66
|
+
[{"id"=>2, "name"=>"文化・芸術", "query_id"=>2},
|
67
|
+
{"id"=>1,
|
68
|
+
"name"=>"観光",
|
69
|
+
"subgenre"=>{"id"=>1, "name"=>"美術館・博物館", "query_id"=>"1-1"},
|
70
|
+
"query_id"=>1}],
|
71
|
+
"detail_url"=>
|
72
|
+
"https://infra-api.city.kanazawa.ishikawa.jp/facilities/2007.json?lang=ja"
|
73
|
+
}
|
74
|
+
```
|
75
|
+
|
76
|
+
### 施設の詳細な情報の取得例
|
77
|
+
```ruby
|
78
|
+
{
|
79
|
+
"id"=>"386",
|
80
|
+
"name"=>"まちのり事務局",
|
81
|
+
"summary"=>
|
82
|
+
"● 「まちのり」は一般のレンタサイクルと違い、みんなで自転車をシェアするサービスです。\r\n● まちなかに設置した19ヶ所のサイクルポート(貸出・返却拠点)及びまちのり事務局であれば、どこでも自転車の貸出・返却ができます(貸出場所と違うポートに返却できます)。\r\n● 自転車を借りたら30分以内に、目的地近くのポートに返却してください。",
|
83
|
+
"address"=>"金沢市此花町3−2(ライブ1内)",
|
84
|
+
"tel"=>"0120-319-047",
|
85
|
+
"fax"=>"",
|
86
|
+
"email"=>"",
|
87
|
+
"opening_hours"=>"9:00~20:00",
|
88
|
+
"closed_days"=>"",
|
89
|
+
"fee"=>"基本料金 1日200円 1月1,000円 1年9,000円\r\n1回の利用時間が30分を超えると30分ごとに200円が加算",
|
90
|
+
"note"=>"",
|
91
|
+
"url"=>"http://www.machi-nori.jp/",
|
92
|
+
"coordinates"=>{"latitude"=>36.57687, "longitude"=>136.651408},
|
93
|
+
"genres"=>[{"id"=>13, "name"=>"まちのり", "query_id"=>13}],
|
94
|
+
"zipcode"=>"920-0852",
|
95
|
+
"medias"=>{"images"=>[], "videos"=>[], "audios"=>[]}
|
96
|
+
}
|
97
|
+
```
|
98
|
+
|
99
|
+
### 取得したジャンル情報の取得例
|
100
|
+
```ruby
|
101
|
+
{
|
102
|
+
"id"=>"1",
|
103
|
+
"name"=>"観光",
|
104
|
+
"subgenres"=>
|
105
|
+
[{"id"=>1, "name"=>"美術館・博物館", "query_id"=>"1-1"},
|
106
|
+
{"id"=>2, "name"=>"歴史・文化施設", "query_id"=>"1-2"},
|
107
|
+
{"id"=>3, "name"=>"寺社", "query_id"=>"1-3"},
|
108
|
+
{"id"=>4, "name"=>"庭園・公園", "query_id"=>"1-4"},
|
109
|
+
{"id"=>5, "name"=>"その他", "query_id"=>"1-5"}],
|
110
|
+
"query_id"=>"1"
|
111
|
+
}
|
112
|
+
```
|
113
|
+
|
114
|
+
### ジャンルのid一覧
|
115
|
+
```
|
116
|
+
1 観光
|
117
|
+
1-1 美術館・博物館
|
118
|
+
1-2 歴史・文化施設
|
119
|
+
1-3 寺社
|
120
|
+
1-4 庭園・公園
|
121
|
+
1-5 その他
|
122
|
+
2 文化・芸術
|
123
|
+
3 生涯学習
|
124
|
+
3-6 生涯学習
|
125
|
+
3-7 公民館
|
126
|
+
4 くらし
|
127
|
+
4-8 届け出・証明
|
128
|
+
4-9 その他
|
129
|
+
5 こども
|
130
|
+
5-10 児童館
|
131
|
+
5-11 児童クラブ
|
132
|
+
5-12 保育所
|
133
|
+
5-13 その他
|
134
|
+
6 スポーツ施設
|
135
|
+
6-14 体育館
|
136
|
+
6-15 プール
|
137
|
+
6-16 テニスコート
|
138
|
+
6-17 その他
|
139
|
+
7 福祉・健康
|
140
|
+
7-18 保健所・福祉健康センター
|
141
|
+
7-19 市立病院
|
142
|
+
7-20 その他
|
143
|
+
8 ビジネス
|
144
|
+
9 学校
|
145
|
+
9-21 市立小学校
|
146
|
+
9-22 市立中学校
|
147
|
+
9-24 金沢美大
|
148
|
+
9-25 市立工業高等学校
|
149
|
+
10 公園
|
150
|
+
11 駐車場・駐輪場
|
151
|
+
11-26 駐車場
|
152
|
+
11-27 駐輪場
|
153
|
+
12 ふらっとバス
|
154
|
+
12-28 此花ルートバス停
|
155
|
+
12-29 菊川ルートバス停
|
156
|
+
12-30 材木ルートバス停
|
157
|
+
12-31 長町ルートバス停
|
158
|
+
13 まちのり
|
159
|
+
14 避難所
|
160
|
+
```
|
161
|
+
|
162
|
+
## 備考
|
163
|
+
このライブラリから取得できるデータは金沢市から提供されています.
|
164
|
+
このライブラリを利用する場合には,[施設情報の二次利用について](http://www4.city.kanazawa.lg.jp/11010/opendata/index.html)の「施設情報の利用条件等」を確認してください.
|
165
|
+
|
166
|
+
## Contributing
|
167
|
+
|
168
|
+
1. Fork it
|
169
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
170
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
171
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
172
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'kanazawa_city/infra/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "kanazawa_city-infra"
|
8
|
+
gem.version = KanazawaCity::Infra::VERSION
|
9
|
+
gem.authors = ["Keisuke KITA"]
|
10
|
+
gem.email = ["kei.kita2501@gmail.com"]
|
11
|
+
gem.description = %q{Simple access KanazawaCity infra API}
|
12
|
+
gem.summary = %q{Simple access KanazawaCity infra API}
|
13
|
+
gem.homepage = "https://github.com/kitak/kanazawa_city-infra"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_runtime_dependency 'httparty'
|
21
|
+
gem.add_runtime_dependency 'hashie', "= 1.2.0"
|
22
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "kanazawa_city/infra/version"
|
3
|
+
require "httparty"
|
4
|
+
require "hashie"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
module KanazawaCity
|
8
|
+
module Infra
|
9
|
+
include HTTParty
|
10
|
+
format :json
|
11
|
+
base_uri "https://infra-api.city.kanazawa.ishikawa.jp"
|
12
|
+
API_VERSION = 'v1'
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def genres(options={})
|
16
|
+
options[:lang] ||= "ja"
|
17
|
+
|
18
|
+
res = JSON.parse(get("/#{API_VERSION}/genres/list.json", :query => options).body)
|
19
|
+
|
20
|
+
res["genres"].map do |g|
|
21
|
+
that = self
|
22
|
+
g[:query_id] = g["id"]
|
23
|
+
g = Hashie::Mash.new(g)
|
24
|
+
g.subgenres.map! do |sg|
|
25
|
+
sg["query_id"] = "#{g["id"]}-#{sg["id"]}"
|
26
|
+
sg
|
27
|
+
end
|
28
|
+
g.freeze
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def facilities(options={})
|
33
|
+
options[:lang] ||= "ja"
|
34
|
+
options[:genre] &&=
|
35
|
+
if options[:genre].kind_of? Array
|
36
|
+
options[:genre].map { |g|
|
37
|
+
if g.respond_to? "query_id"
|
38
|
+
g.query_id
|
39
|
+
elsif g.kind_of?(String) || g.kind_of?(Integer)
|
40
|
+
g
|
41
|
+
else
|
42
|
+
raise ArgumentError
|
43
|
+
end
|
44
|
+
}.join(',')
|
45
|
+
elsif options[:genre].respond_to? "query_id"
|
46
|
+
options[:genre].query_id
|
47
|
+
elsif options[:genre].kind_of? String
|
48
|
+
options[:genre]
|
49
|
+
else
|
50
|
+
raise ArgumentError
|
51
|
+
end
|
52
|
+
|
53
|
+
res = JSON.parse(get("/#{API_VERSION}/facilities/search.json", :query => options).body)
|
54
|
+
keyword = options[:keyword] || ""
|
55
|
+
next_page = res["next_page"] || ""
|
56
|
+
that = self
|
57
|
+
res = res["facilities"].map! do |f|
|
58
|
+
f["genres"].map! do |g|
|
59
|
+
g["query_id"] = g["id"]
|
60
|
+
g["subgenre"]["query_id"] = "#{g["id"]}-#{g["subgenre"]["id"]}" if g["subgenre"]
|
61
|
+
g
|
62
|
+
end
|
63
|
+
f = Hashie::Mash.new(f)
|
64
|
+
f.singleton_class.send(:define_method, :detail) do
|
65
|
+
that.facility(id: f["id"], lang: options[:lang])
|
66
|
+
end
|
67
|
+
f.freeze
|
68
|
+
end
|
69
|
+
res.singleton_class.send(:define_method, :"has_next?") do
|
70
|
+
! next_page.empty?
|
71
|
+
end
|
72
|
+
|
73
|
+
res.singleton_class.send(:define_method, :next) do
|
74
|
+
params = URI.parse(next_page).query.split('&')
|
75
|
+
query = params.inject({}) do |query, param|
|
76
|
+
k, v = param.split('=')
|
77
|
+
if k == "keyword"
|
78
|
+
query[k.to_sym] = URI.decode(keyword)
|
79
|
+
else
|
80
|
+
query[k.to_sym] = URI.decode(v)
|
81
|
+
end
|
82
|
+
query
|
83
|
+
end
|
84
|
+
that.facilities(query)
|
85
|
+
end
|
86
|
+
|
87
|
+
res
|
88
|
+
end
|
89
|
+
|
90
|
+
def facility(options={})
|
91
|
+
options[:lang] ||= "ja"
|
92
|
+
|
93
|
+
res = JSON.parse(get("/#{API_VERSION}/facilities/#{options[:id]}.json",
|
94
|
+
:query => {:lang => options[:lang]}).body)
|
95
|
+
|
96
|
+
f = res["facility"]
|
97
|
+
f["genres"].map! do |g|
|
98
|
+
g["query_id"] = g["id"]
|
99
|
+
g["subgenre"]["query_id"] = "#{g["id"]}-#{g["subgenre"]["id"]}" if g["subgenre"]
|
100
|
+
g
|
101
|
+
end
|
102
|
+
f = Hashie::Mash.new(f)
|
103
|
+
f.freeze
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kanazawa_city-infra
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Keisuke KITA
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: hashie
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - '='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.2.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - '='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.2.0
|
46
|
+
description: Simple access KanazawaCity infra API
|
47
|
+
email:
|
48
|
+
- kei.kita2501@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- kanazawa_city-infra.gemspec
|
59
|
+
- lib/kanazawa_city-infra.rb
|
60
|
+
- lib/kanazawa_city/infra/version.rb
|
61
|
+
homepage: https://github.com/kitak/kanazawa_city-infra
|
62
|
+
licenses: []
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.8.23
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Simple access KanazawaCity infra API
|
85
|
+
test_files: []
|
86
|
+
has_rdoc:
|