class AdopsReportScrapper::AppnexusClient
Public Instance Methods
before_quit_with_error()
click to toggle source
# File lib/adops_report_scrapper/appnexus_client.rb, line 16 def before_quit_with_error end
date_supported?(date = nil)
click to toggle source
# File lib/adops_report_scrapper/appnexus_client.rb, line 7 def date_supported?(date = nil) _date = date || @date return true if _date >= Date.today - 7 false end
init_client()
click to toggle source
# File lib/adops_report_scrapper/appnexus_client.rb, line 13 def init_client end
Private Instance Methods
scrap()
click to toggle source
# File lib/adops_report_scrapper/appnexus_client.rb, line 21 def scrap date_str = date.strftime '%F' response = RestClient.post 'https://api.appnexus.com/auth', { 'auth' => { 'username' => @login, 'password' => @secret } }.to_json, { content_type: :json, accept: :json } response_data = JSON.parse(response.body) token = response_data['response']['token'] response = RestClient.post 'http://api.appnexus.com/report', { 'report' => { 'report_type' => 'network_analytics', 'report_interval' => 'last_7_days', 'columns' => %w(day publisher_name site_name geo_country supply_type imp_requests imps clicks total_convs revenue) } }.to_json, { content_type: :json, accept: :json, authorization: token } response_data = JSON.parse(response.body) report_id = response_data['response']['report_id'] sleep 10 response = RestClient.get "http://api.appnexus.com/report?id=#{report_id}", { authorization: token } response_data = JSON.parse(response.body) fail 'appnexus report failed' unless response_data['response']['execution_status'] == 'ready' response = RestClient.get "http://api.appnexus.com/report-download?id=#{report_id}", { authorization: token } @data = CSV.parse(response.body).select { |row| row[0] == 'day' || (row[0] == date_str && row[5].to_i > 0) } end