Class: NotionRubyMapping::UserObject

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

Overview

TextObject

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_id: nil, json: {}) ⇒ TextObject

Parameters:

  • user_id (String) (defaults to: nil)


8
9
10
11
12
# File 'lib/notion_ruby_mapping/objects/user_object.rb', line 8

def initialize(user_id: nil, json: {})
  @user_id = NotionCache.instance.hex_id(user_id || json && json["id"])
  @json = json
  @will_update = false
end

Instance Attribute Details

#jsonObject (readonly)

Returns the value of attribute json.



13
14
15
# File 'lib/notion_ruby_mapping/objects/user_object.rb', line 13

def json
  @json
end

#user_idObject

Returns the value of attribute user_id.



13
14
15
# File 'lib/notion_ruby_mapping/objects/user_object.rb', line 13

def user_id
  @user_id
end

#will_updateObject (readonly)

Returns the value of attribute will_update.



13
14
15
# File 'lib/notion_ruby_mapping/objects/user_object.rb', line 13

def will_update
  @will_update
end

Class Method Details

.all(dry_run: false) ⇒ Object

Parameters:

  • dry_run (Boolean) (defaults to: false)

    true if dry_run



16
17
18
19
20
21
22
23
# File 'lib/notion_ruby_mapping/objects/user_object.rb', line 16

def self.all(dry_run: false)
  nc = NotionCache.instance
  if dry_run
    Base.dry_run_script :get, nc.users_path
  else
    nc.users
  end
end

.find(user_id, dry_run: false) ⇒ NotionRubyMapping::UserObject, String

Parameters:

  • user_id (String)
  • dry_run (Boolean) (defaults to: false)

    true if dry_run

Returns:



28
29
30
31
32
33
34
35
# File 'lib/notion_ruby_mapping/objects/user_object.rb', line 28

def self.find(user_id, dry_run: false)
  nc = NotionCache.instance
  if dry_run
    Base.dry_run_script :get, nc.user_path(user_id)
  else
    nc.user user_id
  end
end

.find_me(dry_run: false) ⇒ Object

Parameters:

  • dry_run (Boolean) (defaults to: false)

    true if dry_run



38
39
40
# File 'lib/notion_ruby_mapping/objects/user_object.rb', line 38

def self.find_me(dry_run: false)
  find "me", dry_run: dry_run
end

.user_object(user_id_or_uo) ⇒ UserObject

Returns self or created UserObject.

Parameters:

Returns:



44
45
46
47
48
49
50
# File 'lib/notion_ruby_mapping/objects/user_object.rb', line 44

def self.user_object(user_id_or_uo)
  if user_id_or_uo.is_a? UserObject
    user_id_or_uo
  else
    UserObject.new user_id: user_id_or_uo
  end
end

Instance Method Details

#inspectString (frozen)

Returns:

  • (String (frozen))


53
54
55
# File 'lib/notion_ruby_mapping/objects/user_object.rb', line 53

def inspect
  "#{self.class.name}-#{@user_id}"
end

#nameString

Returns:

  • (String)


58
59
60
# File 'lib/notion_ruby_mapping/objects/user_object.rb', line 58

def name
  @json["name"]
end

#property_values_jsonHash

Returns:

  • (Hash)


63
64
65
66
67
68
# File 'lib/notion_ruby_mapping/objects/user_object.rb', line 63

def property_values_json
  {
    "object" => "user",
    "id" => @user_id,
  }
end