Sha256: a457182500182c8b2858e28108bf20ed65e8b2b0b531865ee2bfb90ffdfd9e00

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 KB

Contents

require 'faraday'
require 'json'

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

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

    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

    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

    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
e_stat-0.0.2 lib/e_stat/api.rb
e_stat-0.0.1 lib/e_stat/api.rb