Sha256: 438e78e72decddb76dfd7862373c1327272682060a7f79b0ac8b5cf1266c18da

Contents?: true

Size: 1019 Bytes

Versions: 1

Compression:

Stored size: 1019 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

1 entries across 1 versions & 1 rubygems

Version Path
bing_ads_ruby_sdk-1.5.0 tasks/bing_ads_ruby_sdk.rake