Class: Togglehq::Notify::Preferences

Inherits:
Object
  • Object
show all
Defined in:
lib/togglehq/notify/preferences.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Preferences

Returns a new instance of Preferences.



8
9
10
# File 'lib/togglehq/notify/preferences.rb', line 8

def initialize(params = {})
  @categories = params[:categories]
end

Instance Attribute Details

#categoriesObject

Returns the value of attribute categories.



6
7
8
# File 'lib/togglehq/notify/preferences.rb', line 6

def categories
  @categories
end

Class Method Details

.allObject

Gets all available notification categories and their associated preferences for the current app

Returns:

  • an array of notification categories



14
15
16
17
18
19
20
21
22
23
# File 'lib/togglehq/notify/preferences.rb', line 14

def self.all
  response = Togglehq::Request.new("/preferences").get!
  if response.status == 200
    json = JSON.parse(response.body)
    preferences = Togglehq::Notify::Preferences.new(categories: json)
    return preferences
  else
    raise "Unexpected error getting app preferences"
  end
end