class AdopsReportScrapper::RhythmoneClient

Public Instance Methods

date_supported?(date = nil) click to toggle source
# File lib/adops_report_scrapper/rhythmone_client.rb, line 7
def date_supported?(date = nil)
  _date = date || @date
  return true if _date >= Date.today - 3
  false
end

Private Instance Methods

before_quit_with_error() click to toggle source
# File lib/adops_report_scrapper/rhythmone_client.rb, line 24
def before_quit_with_error
end
init_client() click to toggle source
# File lib/adops_report_scrapper/rhythmone_client.rb, line 15
def init_client
  fail 'please specify rhythmone client_id' unless @options['client_id']
  fail 'please specify rhythmone client_secret' unless @options['client_secret']
  fail 'please specify rhythmone publisher_id' unless @options['publisher_id']
  @client_id = @options['client_id']
  @client_secret = @options['client_secret']
  @publisher_id = @options['publisher_id']
end
login() click to toggle source
# File lib/adops_report_scrapper/rhythmone_client.rb, line 27
def login
  response = RestClient.post 'https://api.portal.rhythmone.com/v1/users/login', client_id: @client_id, client_secret: @client_secret, grant_type: 'password', password: @secret, username: @login
  token_obj = JSON.parse response.body
  @access_token = token_obj['access_token']
end
scrap() click to toggle source
# File lib/adops_report_scrapper/rhythmone_client.rb, line 33
def scrap
  date_str = @date.strftime('%Y%m%d')
  data_obj = nil
  flag_valid_data_found = false
  5.times do
    response = HTTPClient.get("https://api.portal.rhythmone.com/v1/publishers/#{@publisher_id}/reports/standard_report", { ad_dimension: 0, endDate: date_str, endDateType: 1, groupBy1: 1, groupByTimePeriodType: 1, rmp_placement: 0, startDate: date_str, startDatePredefined: 0, startDateType: 1 }, { 'Authorization' => "Bearer #{@access_token}" })
    data_obj = JSON.parse response.body
    if data_obj.is_a?(Array) && !response.body.include?('Data is still processing')
      flag_valid_data_found = true
      break
    end
    sleep 5
  end
  fail 'rhythmone report failed' unless flag_valid_data_found
  @data = data_obj
end