Sha256: d166cced06e97ee1b8627754ac1dfd6ad59864616c9b9fc2d0d2a689dec2708a

Contents?: true

Size: 1022 Bytes

Versions: 4

Compression:

Stored size: 1022 Bytes

Contents

require 'dotenv/load'

namespace :bing_token do
  desc "Gets and stores Bing OAuth token in file"
  task :get, [:filename, :bing_developer_token, :bing_client_id, :bing_client_secret] do |task, args|

    filename = args[:filename] || ENV.fetch('BING_STORE_FILENAME')
    developer_token = args[:bing_developer_token] || ENV.fetch('BING_DEVELOPER_TOKEN')
    bing_client_id = args[:bing_client_id] || ENV.fetch('BING_CLIENT_ID')
    bing_client_secret = args[:bing_client_secret] || ENV.fetch('BING_CLIENT_SECRET', nil)

    store = ::BingAdsRubySdk::OAuth2::FsStore.new(filename)
    auth = BingAdsRubySdk::OAuth2::AuthorizationHandler.new(
      developer_token: developer_token,
      client_id: bing_client_id,
      client_secret: bing_client_secret,
      store: store
    )
    puts "Go to #{auth.code_url}",
         "You will be redirected to a URL at the end. Paste it here in the console and press enter"

    full_url = STDIN.gets.chomp
    auth.fetch_from_url(full_url)

    puts "Written to store"
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bing_ads_ruby_sdk-1.3.4 tasks/bing_ads_ruby_sdk.rake
bing_ads_ruby_sdk-1.3.3 tasks/bing_ads_ruby_sdk.rake
bing_ads_ruby_sdk-1.3.2 tasks/bing_ads_ruby_sdk.rake
bing_ads_ruby_sdk-1.3.1 tasks/bing_ads_ruby_sdk.rake