Class: Feed2Gram::RefreshesToken

Inherits:
Object
  • Object
show all
Defined in:
lib/feed2gram/refreshes_token.rb

Instance Method Summary collapse

Instance Method Details

#call(config) ⇒ Object

“API mode”



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/feed2gram/refreshes_token.rb', line 16

def call(config)
  return unless config.access_token_refreshed_at.nil? ||
    config.access_token_refreshed_at < Time.now - (60 * 60)

  data = Http.get("/oauth/access_token", {
    grant_type: "fb_exchange_token",
    client_id: config.facebook_app_id,
    client_secret: config.facebook_app_secret,
    fb_exchange_token: config.access_token
  })

  data[:access_token]
end

#refresh!(config, options) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/feed2gram/refreshes_token.rb', line 3

def refresh!(config, options)
  puts "Refreshing Facebook OAuth token" if options.verbose
  new_access_token = call(config)
  return unless new_access_token

  config.access_token = new_access_token
  config.access_token_refreshed_at = Time.now.utc

  puts "Updating Facebook OAuth token in: #{options.config_path}" if options.verbose
  File.write(options.config_path, config.as_yaml)
end