diff --git a/app/controllers/api/v1/market_data_controller.rb b/app/controllers/api/v1/market_data_controller.rb index 4e7f491df..5b8a2cfd5 100644 --- a/app/controllers/api/v1/market_data_controller.rb +++ b/app/controllers/api/v1/market_data_controller.rb @@ -3,6 +3,10 @@ module V1 class MarketDataController < ApplicationController skip_before_action :check_header_info + def index + render json: MarketData.new.indicators_json + end + def show render json: MarketData.new(indicator: params[:id]).call end diff --git a/app/models/market_data.rb b/app/models/market_data.rb index 1fb1343c8..338b8bf68 100644 --- a/app/models/market_data.rb +++ b/app/models/market_data.rb @@ -23,6 +23,10 @@ def call send(indicator) end + def indicators_json + VALID_INDICATORS.index_with { |indicator| send(indicator) } + end + def ecosystem_locked if current_timestamp < first_released_timestamp_other ECOSYSTEM_QUOTA * 0.97 diff --git a/config/routes.rb b/config/routes.rb index 46f05ca0d..4a91a6226 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -53,7 +53,7 @@ resources :daily_statistics, only: :show resources :block_statistics, only: :show ## TODO: unused route resources :epoch_statistics, only: :show - resources :market_data, only: :show + resources :market_data, only: [:index, :show] resources :udts, only: %i(index show update) do collection do get :download_csv diff --git a/test/controllers/api/v1/market_data_controller_test.rb b/test/controllers/api/v1/market_data_controller_test.rb index c21284292..f4c353516 100644 --- a/test/controllers/api/v1/market_data_controller_test.rb +++ b/test/controllers/api/v1/market_data_controller_test.rb @@ -36,7 +36,7 @@ class MarketDataControllerTest < ActionDispatch::IntegrationTest create(:daily_statistic, treasury_amount: "45507635189304330.674891957030103511696912093394364431189654516859837775", created_at_unixtimestamp: Time.current.yesterday.beginning_of_day.to_i) end - test "should set right content type when call index" do + test "should set right content type when call show" do create(:address, address_hash: "ckb1qyqy6mtud5sgctjwgg6gydd0ea05mr339lnslczzrc", balance: 10**8 * 1000) valid_get api_v1_market_datum_url("circulating_supply") @@ -69,9 +69,9 @@ class MarketDataControllerTest < ActionDispatch::IntegrationTest test "should return current circulating supply" do create(:address, address_hash: "ckb1qyqy6mtud5sgctjwgg6gydd0ea05mr339lnslczzrc", balance: 10**8 * 1000) valid_get api_v1_market_datum_url("circulating_supply") - MarketData.new(indicator: "circulating_supply").call + result = MarketData.new(indicator: "circulating_supply").call - assert_equal MarketData.new(indicator: "circulating_supply").call.to_s, json + assert_equal result.to_s, json end end end