Class: MagicBell::User

Inherits:
Object
  • Object
show all
Defined in:
lib/magicbell/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ User

Returns a new instance of User.



10
11
12
13
14
15
16
17
18
19
# File 'lib/magicbell/user.rb', line 10

def initialize(attributes)
  @attributes = attributes
  @email = @attributes[:email]
  @conn = Faraday.new({
    url: MagicBell.api_host, 
    headers: MagicBell.project_specific_headers.merge(
      'X-MAGICBELL-USER-EMAIL' => @email
    )
  })
end

Instance Attribute Details

#emailObject

Returns the value of attribute email.



7
8
9
# File 'lib/magicbell/user.rb', line 7

def email
  @email
end

#preferencesObject

Returns the value of attribute preferences.



8
9
10
# File 'lib/magicbell/user.rb', line 8

def preferences
  @preferences
end

Instance Method Details

#hmac_signatureObject



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

def hmac_signature
  MagicBell::HMAC.calculate @email
end

#notification_preferencesObject



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

def notification_preferences
  response = @conn.get "/notification_preferences.json"
  JSON.parse(response.body)["notification_preferences"]
end

#notification_preferences=(preferences) ⇒ Object



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

def notification_preferences=(preferences)
   @conn.put "/notification_preferences.json", 
                {notification_preferences: preferences}
end

#notificationsObject



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

def notifications
  response = @conn.get "/notifications.json"
  JSON.parse(response.body)["notifications"]
end