Class: FacebookDialog::Dialog

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Serializers::JSON
Defined in:
lib/facebook_dialog/dialog.rb

Direct Known Subclasses

Feed, Oauth

Constant Summary collapse

HTML_ONLY_KEYS =
[:redirect_uri, :display]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Dialog

Returns a new instance of Dialog.



11
12
13
14
# File 'lib/facebook_dialog/dialog.rb', line 11

def initialize(options = {})
  @options = options
  @options[:app_id] = FacebookDialog.api_key
end

Class Method Details

.base_uriObject



16
17
18
19
# File 'lib/facebook_dialog/dialog.rb', line 16

def self.base_uri
  raise ResourceNameNotDefined if resource_name.nil?
  "http://www.facebook.com/dialog/#{resource_name}/"
end

Instance Method Details

#queryObject



25
26
27
28
29
30
# File 'lib/facebook_dialog/dialog.rb', line 25

def query
  to_h.merge({ 
    redirect_uri: @options[:redirect_uri] || @options[:link],
    display: @options[:display] || "popup"
  })
end

#serializable_hash(options = {}) ⇒ Object



32
33
34
# File 'lib/facebook_dialog/dialog.rb', line 32

def serializable_hash(options = {})
  to_h.merge({method: self.class.resource_name})
end

#to_hObject



37
38
39
40
41
42
# File 'lib/facebook_dialog/dialog.rb', line 37

def to_h
  validate_options!
  options = @options.merge(self.class.defaults)
  options = options.reject{|key, value| HTML_ONLY_KEYS.include?(key) }
  serialize_options(options)
end

#urlObject



21
22
23
# File 'lib/facebook_dialog/dialog.rb', line 21

def url
  "#{self.class.base_uri}?#{Rack::Utils.build_query(query)}"
end