Class: MagicBell::User

Inherits:
ApiResource show all
Includes:
ApiOperations
Defined in:
lib/magicbell/api_resources/user.rb

Instance Attribute Summary collapse

Attributes inherited from ApiResource

#id

Instance Method Summary collapse

Methods included from ApiOperations

#get, #post, #put

Methods inherited from ApiResource

#attribute, #attributes, #create, create, create_path, #create_path, create_url, #create_url, find, #name, name, #retrieve, #update, #url

Constructor Details

#initialize(client, attributes) ⇒ User

Returns a new instance of User.



7
8
9
10
11
12
13
# File 'lib/magicbell/api_resources/user.rb', line 7

def initialize(client, attributes)
  @client = client
  @email = attributes["email"]
  @external_id = attributes["external_id"]

  super(client, attributes)
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



5
6
7
# File 'lib/magicbell/api_resources/user.rb', line 5

def email
  @email
end

#external_idObject (readonly)

Returns the value of attribute external_id.



5
6
7
# File 'lib/magicbell/api_resources/user.rb', line 5

def external_id
  @external_id
end

Instance Method Details

#authentication_headersObject



50
51
52
53
54
55
56
# File 'lib/magicbell/api_resources/user.rb', line 50

def authentication_headers
  if external_id
    MagicBell.authentication_headers.merge("X-MAGICBELL-USER-EXTERNAL-ID" => external_id)
  elsif email
    MagicBell.authentication_headers.merge("X-MAGICBELL-USER-EMAIL" => email)
  end
end

#find_notification(notification_id) ⇒ Object



20
21
22
23
# File 'lib/magicbell/api_resources/user.rb', line 20

def find_notification(notification_id)
  client = self
  MagicBell::UserNotification.find(client, notification_id)
end

#mark_all_notifications_as_readObject



25
26
27
28
# File 'lib/magicbell/api_resources/user.rb', line 25

def mark_all_notifications_as_read
  client = self
  MagicBell::UserNotificationsRead.new(client).create
end

#mark_all_notifications_as_seenObject



30
31
32
33
# File 'lib/magicbell/api_resources/user.rb', line 30

def mark_all_notifications_as_seen
  client = self
  MagicBell::UserNotificationsSeen.new(client).create
end

#notification_preferencesObject



35
36
37
38
# File 'lib/magicbell/api_resources/user.rb', line 35

def notification_preferences
  client = self
  MagicBell::UserNotificationPreferences.new(client)
end

#notifications(query_params = {}) ⇒ Object



15
16
17
18
# File 'lib/magicbell/api_resources/user.rb', line 15

def notifications(query_params = {})
  client = self
  MagicBell::UserNotifications.new(client, query_params)
end

#pathObject



40
41
42
43
44
45
46
47
48
# File 'lib/magicbell/api_resources/user.rb', line 40

def path
  if id
    self.class.path + "/#{id}"
  elsif external_id
    self.class.path + "/external_id:#{external_id}"
  elsif email
    self.class.path + "/email:#{email}"
  end
end