Sha256: e25f05d20e0f3d25edb9e48ca05aa1e44a3dbdf16fbf76b700f82e6cacdb8631

Contents?: true

Size: 869 Bytes

Versions: 3

Compression:

Stored size: 869 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] 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')

    store = ::BingAdsRubySdk::OAuth2::FsStore.new(filename)
    auth = BingAdsRubySdk::OAuth2::AuthorizationHandler.new(
      developer_token: developer_token,
      client_id: bing_client_id,
      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

3 entries across 3 versions & 1 rubygems

Version Path
bing_ads_ruby_sdk-1.3.0 tasks/bing_ads_ruby_sdk.rake
bing_ads_ruby_sdk-1.2.0 tasks/bing_ads_ruby_sdk.rake
bing_ads_ruby_sdk-1.1.1 tasks/bing_ads_ruby_sdk.rake