はじめに
hkob の雑記録の第460回目(通算33日目)は、TableView の Retrieve a view で ViewProperty を設定してみます。
configuration の設定
まず、configuration を展開して、type キーとして table が、properties として ViewProperty の Array が設定されるようにします。テストは name が確認できればいいでしょうか。
# frozen_string_literal: true require_relative "../../spec_helper" module NotionRubyMapping RSpec.describe TableView do tc = TestConnection.instance let!(:nc) { tc.nc } describe "find" do context "when real access" do let(:target) { View.find TestConnection::TABLE_VIEW_ID } it { expect(target).to be_a TableView } it { expect(target.id).to eq nc.hex_id(TestConnection::TABLE_VIEW_ID) } it { expect(target.type).to eq "table" } it { expect(target.properties.map(&:name)).to eq %w[Title TextTitle NumberTitle SelectTitle MultiSelectTitle DateTitle UserTitle File&MediaTitle CheckboxTitle UrlTitle MailTitle TelTitle CreatedTimeTitle CreatedByTitle LastEditedTimeTitle LastEditedByTitle FormulaTitle RelationTitle RollupTitle StatusTitle IDTitle PositionTitle VerificationTitle OwnerTitle BlockedByTitle BlockingTitle SubItemTitle ParentTitle] } end context "when dry run" do let(:dry_run) { View.find TestConnection::TABLE_VIEW_ID, dry_run: true } it_behaves_like "dry run", :get, :view_path, id: TestConnection::TABLE_VIEW_ID end end end end
view.rb の修正
configuration の読み込みの基本はどの view でも変わらないので、親の view.rb を修正すればいいはずです。とりあえず type と properties の設定を実装してみました。
class View # @param [String, nil] id # @param [String, nil] json def initialize(id: nil, json: nil) @nc = NotionCache.instance @json = json @id = @nc.hex_id(id || @json && @json["id"]) configuration = @json["configuration"] return unless @json && configuration @type = configuration["type"] @properties = configuration["properties"].map do |property| ViewProperty.create_from_json property["property_name"], property end end attr_reader :id, :json, :type, :properties
おわりに
ひとまず properties の読み込みを実行し、ViewProperty が割当されるようになりました。この後、その他の configuration の設定を進めていきます。