class AdtekioAdnetworks::Revenue::Fyber
Constants
- REPORT_URL
Public Instance Methods
hash(params)
click to toggle source
# File lib/adtekio_adnetworks/importers/revenue/fyber.rb, line 37 def hash(params) value = Hash[params.sort_by{|k, _| k}].reject do |_,v| v.to_s.blank? end.map do |k,v| "#{k}=#{v}" end.inject("/publishers/v1/28839/statistics.json") do |string, param| string + "&" + param end + "&" + credentials.key Digest::SHA1.hexdigest value end
http_client()
click to toggle source
# File lib/adtekio_adnetworks/importers/revenue/fyber.rb, line 56 def http_client @http_client ||= Net::HTTP::Persistent.new('fyber').tap do |client| client.verify_mode = OpenSSL::SSL::VERIFY_NONE end end
load_data(params)
click to toggle source
# File lib/adtekio_adnetworks/importers/revenue/fyber.rb, line 49 def load_data(params) uri = Addressable::URI.parse(REPORT_URL) uri.query_values = params.merge({:hashkey => hash(params)}) response = http_client.request(URI.parse(uri.to_s)) JSON(response.body)['applications'] end
report(from,to)
click to toggle source
# File lib/adtekio_adnetworks/importers/revenue/fyber.rb, line 28 def report(from,to) load_data({ :start_date => from.to_s, :end_date => to.to_s, :group_by => :applications, :aggregation_level => :days, }) end
revenues(from, to)
click to toggle source
# File lib/adtekio_adnetworks/importers/revenue/fyber.rb, line 11 def revenues(from, to) report(from,to).map do |dpt| appname = dpt['readable'].strip from.upto(to).each_with_index.map do |date, idx| { :completions => dpt["transactions"][idx].to_i, :impressions => dpt["views"][idx].to_i, :clicks => dpt["clicks"][idx].to_i, :amount => dpt["payout_usd"][idx].to_f, :date => date, :appname => appname, :not_matched => not_matched(:id => dpt["id"]) } end end.flatten.compact end