Sha256: e54870c1775927ad478b836a1cf0c81c2d80d25f20bac0370e12d227de58c7ad

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require "dotenv/load"

namespace :bing_token do
  desc "Gets OAuth token from MS and stores it in a JSON file defined by filename parameter"
  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

1 entries across 1 versions & 1 rubygems

Version Path
bing_ads_ruby_sdk-1.5.2 lib/bing_ads_ruby_sdk/tasks/bing_ads_ruby_sdk.rake