Sha256: 3572af3121d7863f1858a67e6a42015d240b7e9fd0a5ad20186012bc6863be67

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

require 'date'
require_relative 'base_client'
require 'rest-client'

class AdopsReportScrapper::AdsupplybuyerClient < AdopsReportScrapper::BaseClient
  def date_supported?(date = nil)
    _date = date || @date
    return true if _date < Date.today
    false
  end

  def init_client
  end

  def before_quit_with_error
  end

  private

  def scrap
    if @options[:hourly]
      scrap_hourly
    else
      scrap_daily
    end
  end

  def scrap_daily
    date_str = @date.strftime('%-m/%-d/%Y')
    time_zone_id = 'Eastern Standard Time'

    response = RestClient.post "https://ui.adsupply.com/PublicPortal/Advertiser/#{@login}/Report/Export", SqlCommandId: '', ExportToExcel: 'False', IsOLAP: 'False', DateFilter: date_str, TimeZoneId: time_zone_id, Grouping: '1', 'DimAdvertiser.Value': "#{@login}~", 'DimAdvertiser.IsActive': 'True', 'DimCampaign.Value': '', 'DimCampaign.IsActive': 'True', ApiKey: @secret

    data = JSON.parse response
    header = data[0].keys
    @data = [header]
    @data += data.map do |datum|
      header.map { |key| datum[key] }
    end
  end

  def scrap_hourly
    date_str = @date.strftime('%-m/%-d/%Y')
    time_zone_id = 'Eastern Standard Time'

    response = RestClient.post "https://ui.adsupply.com/PublicPortal/Advertiser/#{@login}/Report/Export", SqlCommandId: '', ExportToExcel: 'False', IsOLAP: 'False', DateFilter: date_str, TimeZoneId: time_zone_id, Grouping: '0', ApiKey: @secret

    data = JSON.parse response
    header = data[0].keys
    @data = [header]
    @data += data.map do |datum|
      header.map { |key| datum[key] }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
adops_report_scrapper-0.2.17 lib/adops_report_scrapper/adsupplybuyer_client.rb