Class: NotionRubyMapping::Payload

Inherits:
Object
  • Object
show all
Defined in:
lib/notion_ruby_mapping/payload.rb

Overview

Payload class

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Payload

Returns a new instance of Payload.



6
7
8
# File 'lib/notion_ruby_mapping/payload.rb', line 6

def initialize(json)
  @json = json || {}
end

Instance Method Details

#clearHash

Returns {}.

Returns:

  • (Hash)

    {}



50
51
52
# File 'lib/notion_ruby_mapping/payload.rb', line 50

def clear
  @json = {}
end

#merge_property(json) ⇒ Object

Parameters:

  • json (Hash)


26
27
28
29
# File 'lib/notion_ruby_mapping/payload.rb', line 26

def merge_property(json)
  @json["properties"] ||= {}
  @json["properties"].merge!(json)
end

#property_schema_json(*others) ⇒ Hash

Returns created json.

Parameters:

  • others (Object)

Returns:

  • (Hash)

    created json



39
40
41
# File 'lib/notion_ruby_mapping/payload.rb', line 39

def property_schema_json(*others)
  others.compact.reduce({}) { |hash, o| hash.merge o.property_schema_json }.merge @json
end

#property_values_json(*others) ⇒ Hash

Returns created json.

Parameters:

  • others (Object)

Returns:

  • (Hash)

    created json



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

def property_values_json(*others)
  others.compact.reduce({}) { |hash, o| hash.merge o.property_values_json }.merge @json
end

#set_icon(emoji: nil, url: nil) ⇒ NotionRubyMapping::Payload

Returns updated Payload.

Parameters:

  • emoji (String) (defaults to: nil)
  • url (String) (defaults to: nil)

Returns:



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/notion_ruby_mapping/payload.rb', line 13

def set_icon(emoji: nil, url: nil)
  payload = if emoji
              {"type" => "emoji", "emoji" => emoji}
            elsif url
              {"type" => "external", "external" => {"url" => url}}
            else
              {}
            end
  @json["icon"] = payload
  self
end

#update_property_schema_json(*others) ⇒ Hash

Returns created json.

Parameters:

  • others (Object)

Returns:

  • (Hash)

    created json



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

def update_property_schema_json(*others)
  others.compact.reduce({}) { |hash, o| hash.merge o.update_property_schema_json }.merge @json
end