Class: Feed2Thread::RefreshesToken

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

Instance Method Summary collapse

Instance Method Details

#refresh!(config, options) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/feed2thread/refreshes_token.rb', line 3

def refresh!(config, options)
  return unless config.access_token_refreshed_at.nil? ||
    config.access_token_refreshed_at < Time.now - (60 * 60)

  puts "Refreshing Threads access token" if options.verbose
  data = Http.get("/refresh_access_token", {
    grant_type: "th_refresh_token",
    access_token: config.access_token
  })

  config.access_token = data[:access_token]
  config.access_token_refreshed_at = Time.now.utc

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