Class: FacebookAds::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/facebook_ads/session.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token: nil, app_secret: nil, server_host: FacebookAds.config.server_host, api_version: FacebookAds.config.api_version) ⇒ Session

Returns a new instance of Session.



16
17
18
19
20
21
22
23
24
# File 'lib/facebook_ads/session.rb', line 16

def initialize(access_token: nil,
               app_secret:   nil,
               server_host:  FacebookAds.config.server_host,
               api_version:  FacebookAds.config.api_version)
  @access_token = access_token
  @app_secret   = app_secret
  @server_host  = server_host
  @api_version  = api_version
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



14
15
16
# File 'lib/facebook_ads/session.rb', line 14

def access_token
  @access_token
end

#api_versionObject

Returns the value of attribute api_version.



14
15
16
# File 'lib/facebook_ads/session.rb', line 14

def api_version
  @api_version
end

#app_secretObject

Returns the value of attribute app_secret.



14
15
16
# File 'lib/facebook_ads/session.rb', line 14

def app_secret
  @app_secret
end

#server_hostObject

Returns the value of attribute server_host.



14
15
16
# File 'lib/facebook_ads/session.rb', line 14

def server_host
  @server_host
end

Class Method Details

.anonymous_sessionObject



66
67
68
# File 'lib/facebook_ads/session.rb', line 66

def anonymous_session
  new()
end

.current_sessionObject



81
82
83
# File 'lib/facebook_ads/session.rb', line 81

def current_session
  @@current_session ||= default_session
end

.current_session=(session) ⇒ Object



85
86
87
# File 'lib/facebook_ads/session.rb', line 85

def current_session=(session)
  @@current_session = session
end

.default_sessionObject



70
71
72
73
74
# File 'lib/facebook_ads/session.rb', line 70

def default_session
  # TODO
  @default_session ||= new( access_token: FacebookAds.config.access_token,
                            app_secret: FacebookAds.config.app_secret)
end

.default_session=(session) ⇒ Object



76
77
78
79
# File 'lib/facebook_ads/session.rb', line 76

def default_session=(session)
  # TODO
  @default_session = session
end

Instance Method Details

#appsecret_proofObject



39
40
41
42
43
44
45
# File 'lib/facebook_ads/session.rb', line 39

def appsecret_proof
  OpenSSL::HMAC.hexdigest(
    OpenSSL::Digest.new('sha256'),
    @app_secret,
    @access_token
  )
end

#request(method, path, params = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/facebook_ads/session.rb', line 26

def request(method, path, params = nil)
  case method
    when :get, :post, :delete
      api_conn.send(method, path.gsub(/^\//,''), params) do |req|
        req.headers[:user_agent] = "fbbizsdk-ruby-v#{VERSION}".freeze
        req.params[:access_token] = access_token if access_token
        req.params[:appsecret_proof] = appsecret_proof if app_secret
      end
    else
      raise 'Unsupported HTTP method: ' + method
  end
end