Sha256: 4d416b5c7b1d618d11c48f69c3da095e009e39894016e3b0c428cc07f5140792

Contents?: true

Size: 767 Bytes

Versions: 8

Compression:

Stored size: 767 Bytes

Contents

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

      puts "Refreshing Facebook OAuth token" if options.verbose
      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
      })

      config.access_token = data[: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
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
feed2gram-1.2.4 lib/feed2gram/refreshes_token.rb
feed2gram-1.2.2 lib/feed2gram/refreshes_token.rb
feed2gram-1.2.1 lib/feed2gram/refreshes_token.rb
feed2gram-1.2.0 lib/feed2gram/refreshes_token.rb
feed2gram-1.1.0 lib/feed2gram/refreshes_token.rb
feed2gram-1.0.0 lib/feed2gram/refreshes_token.rb
feed2gram-0.0.4 lib/feed2gram/refreshes_token.rb
feed2gram-0.0.3 lib/feed2gram/refreshes_token.rb