adops_report_scrapper 0.1.60 → 0.1.61

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 19d89b958d0f4d5fd4e37e0dad17197884411d70
4
- data.tar.gz: 87de46d54d5020c22dd819e11fbc86473332f121
3
+ metadata.gz: 69824afd48c63b45650950d184a9713ebeae951e
4
+ data.tar.gz: 9aa1dee3f08d42f7430cd7dfce42e8e467565850
5
5
  SHA512:
6
- metadata.gz: ac4741afc52119c8aaa92cd04dc9f6cb3944cf2f1027b2ed079e8caece386aad76e588df509163fc731d6924eddab47c7ae94c5d3dd1921fe6e347e07d54a6a7
7
- data.tar.gz: 7e0ec9de3b88b5d4b5f24887baa63fef4ce049f4539981c01ee895e02dd63e0aa1e759a437cb27c992084e030faed56eec11e0721fb9ebb2f024bd3157a5e5ed
6
+ metadata.gz: a8ba97f5ba81deb3869efde99d9cbdc691c05a26f1772c3f13dc09865e8d4c05e937df391561fb6e004c6a7e457c4608a4456746c14ee530a170a0c3411b64e8
7
+ data.tar.gz: 1c6bd33c7e073b9a5876cb417ae4f03af7aa5d0e854c42c2d408a315a4b3a099e07591b3243ec4e66318621399a50d7aba95a112a581e8ce0eba5e2e3d3c7903
data/CHANGELOG CHANGED
@@ -1,5 +1,8 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.1.61
4
+ implement appnexus
5
+
3
6
  ## 0.1.60
4
7
  fix for google survey - google survey is getting slow
5
8
 
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ require 'adops_report_scrapper'
7
7
  require 'byebug'
8
8
 
9
9
  desc 'Collect all data'
10
- task :all => [:openx, :tremor, :brightroll, :yellowhammer, :adaptv, :fourninefive, :adx, :revcontent, :gcs, :browsi, :netseer, :sonobi, :nativo, :adsupply, :marfeel, :adsense, :criteo, :triplelift, :conversant, :liveintent, :adiply, :contentad, :facebookaudience, :adtechus, :adtomation, :rhythmone, :littlethings] do # openx is the most unstable one, run it first
10
+ task :all => [:openx, :tremor, :brightroll, :yellowhammer, :adaptv, :fourninefive, :adx, :revcontent, :gcs, :browsi, :netseer, :sonobi, :nativo, :adsupply, :marfeel, :adsense, :criteo, :triplelift, :conversant, :liveintent, :adiply, :contentad, :facebookaudience, :adtechus, :adtomation, :rhythmone, :littlethings, :appnexus] do # openx is the most unstable one, run it first
11
11
  puts '========== You are all set'
12
12
  end
13
13
 
@@ -176,6 +176,11 @@ task :brightcom do
176
176
  save_as_csv :brightcom, :brightcom
177
177
  end
178
178
 
179
+ desc 'Collect appnexus data'
180
+ task :appnexus do
181
+ save_as_csv :appnexus, :appnexus
182
+ end
183
+
179
184
  def date
180
185
  @date ||= ENV['date'].nil? ? Date.today - 1 : Date.today - ENV['date'].to_i
181
186
  end
@@ -46,3 +46,4 @@ require 'adops_report_scrapper/undertone_client'
46
46
  require 'adops_report_scrapper/imonomy_client'
47
47
  require 'adops_report_scrapper/positivemobile_client'
48
48
  require 'adops_report_scrapper/brightcom_client'
49
+ require 'adops_report_scrapper/appnexus_client'
@@ -0,0 +1,41 @@
1
+ require 'date'
2
+ require_relative 'base_client'
3
+ require 'rest-client'
4
+ require 'csv'
5
+
6
+ class AdopsReportScrapper::AppnexusClient < AdopsReportScrapper::BaseClient
7
+ def date_supported?(date = nil)
8
+ _date = date || @date
9
+ return true if _date >= Date.today - 7
10
+ false
11
+ end
12
+
13
+ def init_client
14
+ end
15
+
16
+ def before_quit_with_error
17
+ end
18
+
19
+ private
20
+
21
+ def scrap
22
+ date_str = date.strftime '%F'
23
+
24
+ response = RestClient.post 'https://api.appnexus.com/auth', { 'auth' => { 'username' => @login, 'password' => @secret } }.to_json, { content_type: :json, accept: :json }
25
+ response_data = JSON.parse(response.body)
26
+ token = response_data['response']['token']
27
+
28
+ response = RestClient.post 'http://api.appnexus.com/report', { 'report' => { 'report_type' => 'network_analytics', 'report_interval' => 'last_7_days', 'columns' => %w(day publisher_name geo_country supply_type imp_requests imps clicks total_convs revenue) } }.to_json, { content_type: :json, accept: :json, authorization: token }
29
+ response_data = JSON.parse(response.body)
30
+ report_id = response_data['response']['report_id']
31
+
32
+ sleep 10
33
+
34
+ response = RestClient.get "http://api.appnexus.com/report?id=#{report_id}", { authorization: token }
35
+ response_data = JSON.parse(response.body)
36
+ fail 'appnexus report failed' unless response_data['response']['execution_status'] == 'ready'
37
+
38
+ response = RestClient.get "http://api.appnexus.com/report-download?id=#{report_id}", { authorization: token }
39
+ @data = CSV.parse(response.body).select { |row| row[0] == 'day' || (row[0] == date_str && row[4].to_i > 0) }
40
+ end
41
+ end
@@ -1,3 +1,3 @@
1
1
  module AdopsReportScrapper
2
- VERSION = "0.1.60"
2
+ VERSION = "0.1.61"
3
3
  end
data/secret.sample.yml CHANGED
@@ -117,3 +117,6 @@ positivemobile:
117
117
  brightcom:
118
118
  login: ------
119
119
  secret: ------
120
+ appnexus:
121
+ login: ------
122
+ secret: ------
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adops_report_scrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.60
4
+ version: 0.1.61
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stayman Hou
@@ -225,6 +225,7 @@ files:
225
225
  - lib/adops_report_scrapper/adtechus_client.rb
226
226
  - lib/adops_report_scrapper/adtomation_client.rb
227
227
  - lib/adops_report_scrapper/adx_client.rb
228
+ - lib/adops_report_scrapper/appnexus_client.rb
228
229
  - lib/adops_report_scrapper/base_client.rb
229
230
  - lib/adops_report_scrapper/brightcom_client.rb
230
231
  - lib/adops_report_scrapper/brightroll_client.rb