Class: Facepalm::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/facepalm/config.rb

Overview

Facebook application configuration class

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.



25
26
27
# File 'lib/facepalm/config.rb', line 25

def initialize(options = {})
  self.config = options.to_options
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



4
5
6
# File 'lib/facepalm/config.rb', line 4

def config
  @config
end

Class Method Details

.defaultObject

A shortcut to access default configuration stored in RAILS_ROOT/config/facebook.yml



8
9
10
# File 'lib/facepalm/config.rb', line 8

def default
  @@default ||= self.new(load_default_config_from_file)
end

.load_default_config_from_fileObject

Raises:

  • (NotConfigured)


12
13
14
15
16
17
18
19
20
21
22
# File 'lib/facepalm/config.rb', line 12

def load_default_config_from_file
  config_data = YAML.load(
    ERB.new(
      File.read(::Rails.root.join("config", "facebook.yml"))
    ).result
  )[::Rails.env]

  raise NotConfigured.new("Unable to load configuration for #{ ::Rails.env } from config/facebook.yml") unless config_data

  config_data
end

Instance Method Details

#api_clientObject

Koala Facebook API client instantiated with application access token



43
44
45
# File 'lib/facepalm/config.rb', line 43

def api_client
  @api_client ||= Koala::Facebook::API.new(app_access_token)
end

#app_access_tokenObject

Fetches application access token



48
49
50
# File 'lib/facepalm/config.rb', line 48

def app_access_token
  @app_access_token ||= oauth_client.get_app_access_token
end

#callback_url(protocol) ⇒ Object

Application callback URL



62
63
64
# File 'lib/facepalm/config.rb', line 62

def callback_url(protocol)
  protocol + callback_domain
end

#canvas_page_url(protocol) ⇒ Object

URL of the application canvas page



57
58
59
# File 'lib/facepalm/config.rb', line 57

def canvas_page_url(protocol)
  "#{ protocol }apps.facebook.com/#{ namespace }"
end

#oauth_clientObject



38
39
40
# File 'lib/facepalm/config.rb', line 38

def oauth_client
  @oauth_client ||= Koala::Facebook::OAuth.new(app_id, secret)
end

#subscription_tokenObject



52
53
54
# File 'lib/facepalm/config.rb', line 52

def subscription_token
  Digest::MD5.hexdigest(secret)
end