Module: Geocore

Includes:
HTTParty
Defined in:
lib/geocore.rb,
lib/geocore/version.rb

Constant Summary collapse

VERSION =
"0.4.0"

Instance Method Summary collapse

Instance Method Details

#cities_bounds(city_codes_array) ⇒ Object



61
62
63
# File 'lib/geocore.rb', line 61

def cities_bounds(city_codes_array)
  self.class.get('/public/ref/jp/cities/bounds?city_codes=' + URI.escape(city_codes_array.join(','), Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")))
end

#city(city_code) ⇒ Object



89
90
91
# File 'lib/geocore.rb', line 89

def city(city_code)
  self.class.get('/public/ref/jp/cities/' + city_code.to_s)  # Code examples: Shinjuku = 13104, Saiwai(Kawasaki) = 14132, Nishi(Yokohama) = 14103, city_codes_array = [13104, 14132, 14103]
end

#feed_statusObject



21
22
23
# File 'lib/geocore.rb', line 21

def feed_status
  return @feed_status
end

#initialize(user) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/geocore.rb', line 9

def initialize(user)
  @url = "http://dev1.geocore.jp/api/auth"
  response = HTTParty.post(@url, body: {'id' => user., 'password' => user.api_key, 'project_id' => user.project_id})
  if response['status'] == "success"
    @feed_status = 'healthy'
    @token = response["result"]["token"]
    @header = {'Geocore-Access-Token': @token}
  else
    @feed_status = 'Error'
  end
end

#level0Object



29
30
31
# File 'lib/geocore.rb', line 29

def level0
  self.class.get("/public/ref/gadm")
end

#level1(level0Id) ⇒ Object



33
34
35
# File 'lib/geocore.rb', line 33

def level1(level0Id)
  self.class.get("/public/ref/gadm" + level0Id.to_s)
end

#level2(level0Id, level1Id) ⇒ Object



37
38
39
# File 'lib/geocore.rb', line 37

def level2(level0Id, level1Id)
  self.class.get("/public/ref/gadm" + level0Id.to_s + '/' + level1Id.to_s)
end

#level3(level0Id, level1Id, level2Id) ⇒ Object



41
42
43
# File 'lib/geocore.rb', line 41

def level3(level0Id, level1Id, level2Id)
  self.class.get("/public/ref/gadm" + level0Id.to_s + '/' + level1Id.to_s + '/' + level2Id.to_s)
end

#nearest_city(lat, lon) ⇒ Object



93
94
95
# File 'lib/geocore.rb', line 93

def nearest_city(lat, lon)
  self.class.get('/public/ref/jp/cities/nearest?lat=' + lat + '&lon=' + lon)
end

#placesObject



25
26
27
# File 'lib/geocore.rb', line 25

def places
  self.class.get("/places", headers: @header)
end

#prefecture(prefecture_code) ⇒ Object



85
86
87
# File 'lib/geocore.rb', line 85

def prefecture(prefecture_code)
  self.class.get('/public/ref/jp/prefectures/' + prefecture_code.to_s)
end

#prefecture_bounds(prefecture_code) ⇒ Object



57
58
59
# File 'lib/geocore.rb', line 57

def prefecture_bounds(prefecture_code)
  self.class.get('/public/ref/jp/prefectures/' + prefecture_code.to_s + '/bounds')
end

#prefecture_cities(prefecture_code) ⇒ Object



53
54
55
# File 'lib/geocore.rb', line 53

def prefecture_cities(prefecture_code)
  self.class.get('/public/ref/jp/prefectures/' + prefecture_code.to_s + '/cities')
end

#prefecture_train_line_stations(prefecture_code, line_code) ⇒ Object



77
78
79
# File 'lib/geocore.rb', line 77

def prefecture_train_line_stations(prefecture_code, line_code)
  self.class.get('/public/ref/jp/prefectures/' + prefecture_code.to_s + '/lines/' + line_code.to_s + '/stations')
end

#prefecture_train_lines(prefecture_code) ⇒ Object



73
74
75
# File 'lib/geocore.rb', line 73

def prefecture_train_lines(prefecture_code)
  self.class.get('/public/ref/jp/prefectures/' + prefecture_code.to_s + '/lines')
end

#region_prefectures(region_code) ⇒ Object



49
50
51
# File 'lib/geocore.rb', line 49

def region_prefectures(region_code)
  self.class.get('/public/ref/jp/regions/' + region_code.to_s + '/prefectures')
end

#regions(code_prefix) ⇒ Object



45
46
47
# File 'lib/geocore.rb', line 45

def regions(code_prefix)
  self.class.get('/public/ref/jp/regions/' + code_prefix.to_s)
end

#station(station_code) ⇒ Object



101
102
103
# File 'lib/geocore.rb', line 101

def station(station_code)
  self.class.get('/public/ref/jp/stations/' + station_code)
end

#stations_bounds(station_codes_array) ⇒ Object



81
82
83
# File 'lib/geocore.rb', line 81

def stations_bounds(station_codes_array)
  self.class.get('/public/ref/jp/stations/bounds?station_codes=' + URI.escape(station_codes_array.join(','), Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")))
end

#train_line(line_code) ⇒ Object



97
98
99
# File 'lib/geocore.rb', line 97

def train_line(line_code)
  self.class.get('/public/ref/jp/lines/' + line_code)
end

#train_line_bounds(line_code) ⇒ Object



65
66
67
# File 'lib/geocore.rb', line 65

def train_line_bounds(line_code)
  self.class.get('/public/ref/jp/lines/' + line_code.to_s + '/bounds')
end

#train_lines_bounds(line_codes_array) ⇒ Object



69
70
71
# File 'lib/geocore.rb', line 69

def train_lines_bounds(line_codes_array)
  self.class.get('/public/ref/jp/cities/bounds?city_codes=' + URI.escape(line_codes_array.join(','), Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")))
end