Module: FbGraph::Connections::Settings

Included in:
Page
Defined in:
lib/fb_graph/connections/settings.rb

Constant Summary collapse

AVAILABLE_SETTINGS =
[
  :users_can_post,
  :users_can_post_photos,
  :users_can_tag_photos,
  :users_can_post_videos
]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fb_graph/connections/settings.rb', line 11

def self.included(klass)
  AVAILABLE_SETTINGS.each do |setting|
    klass.class_eval <<-SETTING
      def #{setting}?(options = {})
        settings(options).include? :#{setting}
      end

      def #{setting}!(options = {})
        enable! :#{setting}, options
      end

      def #{setting.to_s.sub('can', 'cannot')}!(options = {})
        disable! :#{setting}, options
      end
    SETTING
  end
end

Instance Method Details

#disable!(setting, options = {}) ⇒ Object



41
42
43
# File 'lib/fb_graph/connections/settings.rb', line 41

def disable!(setting, options = {})
  __update_setting__ setting, false, options
end

#enable!(setting, options = {}) ⇒ Object



37
38
39
# File 'lib/fb_graph/connections/settings.rb', line 37

def enable!(setting, options = {})
  __update_setting__ setting, true, options
end

#settings(options = {}) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/fb_graph/connections/settings.rb', line 29

def settings(options = {})
  @settings = nil if options[:no_cache]
  @settings ||= self.connection(:settings, options).inject([]) do |_settings_, _setting_|
    _settings_ << _setting_[:setting].downcase.to_sym if _setting_[:value]
    _settings_
  end
end