Class: EStat::API

Inherits:
Object
  • Object
show all
Defined in:
lib/e_stat/api.rb

Constant Summary collapse

BASE_URL =
'http://api.e-stat.go.jp/rest/2.0/app/json/'

Instance Method Summary collapse

Constructor Details

#initialize(key, options = {}) ⇒ API

Returns a new instance of API.



8
9
10
11
# File 'lib/e_stat/api.rb', line 8

def initialize(key, options={})
  @key = key
  @lang = options[:lang]
end

Instance Method Details

#get_meta_info(stats_data_id) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/e_stat/api.rb', line 31

def get_meta_info(stats_data_id)
  response = Faraday.get("#{BASE_URL}getMetaInfo", {
      appId: @key,
      lang: @lang,
      statsDataId: stats_data_id
  })
  attributes = JSON.parse(response.body)
  attributes['GET_META_INFO']
end

#get_stats_data(stats_data_id) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/e_stat/api.rb', line 41

def get_stats_data(stats_data_id)
  response = Faraday.get("#{BASE_URL}getStatsData", {
      appId: @key,
      lang: @lang,
      statsDataId: stats_data_id
  })
  attributes = JSON.parse(response.body)
  attributes['GET_STATS_DATA']
end

#get_stats_list(stats_field, stats_code, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/e_stat/api.rb', line 13

def get_stats_list(stats_field, stats_code, options={})
  response = Faraday.get("#{BASE_URL}getStatsList", {
      appId: @key,
      lang: @lang,
      statsField: stats_field,
      statsCode: stats_code,
      surveyYears: options[:survey_years],
      openYears: options[:open_years],
      searchWord: options[:search_word],
      searchKind: options[:search_kind],
      statsNameList: options[:stats_name_list],
      startPosition: options[:start_position],
      updatedDate: options[:updated_date]
  })
  attributes = JSON.parse(response.body)
  attributes['GET_STATS_LIST']
end