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.



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

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.



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

def email
  @email
end

#preferencesObject

Returns the value of attribute preferences.



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

def preferences
  @preferences
end

Instance Method Details

#hmac_signatureObject



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

def hmac_signature
  MagicBell::HMAC.calculate @email
end

#notification_preferencesObject



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

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

#notification_preferences=(preferences) ⇒ Object



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

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

#notificationsObject



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

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