Class: FacebookAds::Session
- Inherits:
-
Object
- Object
- FacebookAds::Session
- Defined in:
- lib/facebook_ads/session.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#api_version ⇒ Object
Returns the value of attribute api_version.
-
#app_secret ⇒ Object
Returns the value of attribute app_secret.
-
#server_host ⇒ Object
Returns the value of attribute server_host.
Class Method Summary collapse
- .anonymous_session ⇒ Object
- .current_session ⇒ Object
- .current_session=(session) ⇒ Object
- .default_session ⇒ Object
- .default_session=(session) ⇒ Object
Instance Method Summary collapse
- #appsecret_proof ⇒ Object
-
#initialize(access_token: nil, app_secret: nil, server_host: FacebookAds.config.server_host, api_version: FacebookAds.config.api_version) ⇒ Session
constructor
A new instance of Session.
- #request(method, path, params = nil) ⇒ Object
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_token ⇒ Object
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_version ⇒ Object
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_secret ⇒ Object
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_host ⇒ Object
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_session ⇒ Object
66 67 68 |
# File 'lib/facebook_ads/session.rb', line 66 def anonymous_session new() end |
.current_session ⇒ Object
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_session ⇒ Object
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_proof ⇒ Object
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 |