adops_report_scrapper 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +3 -0
  5. data/CODE_OF_CONDUCT.md +13 -0
  6. data/Gemfile +18 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +51 -0
  9. data/Rakefile +152 -0
  10. data/adops_report_scrapper.gemspec +24 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +7 -0
  13. data/lib/adops_report_scrapper.rb +38 -0
  14. data/lib/adops_report_scrapper/adaptv_client.rb +80 -0
  15. data/lib/adops_report_scrapper/adforge_client.rb +35 -0
  16. data/lib/adops_report_scrapper/adiply_client.rb +49 -0
  17. data/lib/adops_report_scrapper/adsense_client.rb +55 -0
  18. data/lib/adops_report_scrapper/adsupply_client.rb +27 -0
  19. data/lib/adops_report_scrapper/adx_client.rb +55 -0
  20. data/lib/adops_report_scrapper/base_client.rb +74 -0
  21. data/lib/adops_report_scrapper/brightroll_client.rb +47 -0
  22. data/lib/adops_report_scrapper/browsi_client.rb +44 -0
  23. data/lib/adops_report_scrapper/contentad_client.rb +91 -0
  24. data/lib/adops_report_scrapper/conversant_client.rb +66 -0
  25. data/lib/adops_report_scrapper/criteo_client.rb +25 -0
  26. data/lib/adops_report_scrapper/facebookaudience_client.rb +56 -0
  27. data/lib/adops_report_scrapper/gcs_client.rb +56 -0
  28. data/lib/adops_report_scrapper/liveintent_client.rb +90 -0
  29. data/lib/adops_report_scrapper/marfeel_client.rb +59 -0
  30. data/lib/adops_report_scrapper/nativo_client.rb +60 -0
  31. data/lib/adops_report_scrapper/netseer_client.rb +73 -0
  32. data/lib/adops_report_scrapper/openx_client.rb +161 -0
  33. data/lib/adops_report_scrapper/revcontent_client.rb +51 -0
  34. data/lib/adops_report_scrapper/sonobi_client.rb +91 -0
  35. data/lib/adops_report_scrapper/springserve_client.rb +52 -0
  36. data/lib/adops_report_scrapper/tremor_client.rb +52 -0
  37. data/lib/adops_report_scrapper/triplelift_client.rb +72 -0
  38. data/lib/adops_report_scrapper/version.rb +3 -0
  39. data/secret.sample.yml +77 -0
  40. data/tmp/.keep +0 -0
  41. metadata +117 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 368ff448654fe142f098a05d72c263f4a7c7bacc
4
+ data.tar.gz: 8664f20d302251678c328d37401275164476451a
5
+ SHA512:
6
+ metadata.gz: 652e2f66cc8326a1e6ebedfd5615f1b0ebaf555c80fd2c8763ac57e69a3e804ca6d2cbd7ed8d3a00b2f59471dd67117c59bc0befd6eb96386758e30eaac3d45e
7
+ data.tar.gz: 60ebf84d57a88314c7c922cd445ef943b572e38ba295e6c0e1ba4df100c8ad800eca2377627560898988cd0050fb4df9c8eadddfea12999972d92c2f8ed4325b
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /secret.yml
10
+ /tmp/*
11
+ !/tmp/.keep
12
+ /.byebug_history
13
+ /capybara-*.png
14
+ /*-oauth2.json
15
+ /discovery.cache
16
+ /adops_report_scrapper*.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in adops_report_scrapper.gemspec
4
+ gemspec
5
+
6
+ gem 'byebug'
7
+
8
+ gem 'httpclient'
9
+ gem 'kaminari'
10
+ gem 'rest-client'
11
+ gem 'capybara'
12
+ gem 'poltergeist', require: 'phantomjs/poltergeist'
13
+ gem 'phantomjs'
14
+ gem 'http-cookie'
15
+ gem 'rubyzip'
16
+ gem 'google-api-client', '~> 0.8.2'
17
+ gem 'cheddar'
18
+ gem 'roo', '~> 2.4.0'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Stayman Hou
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # Adops_Report_Scrapper
2
+
3
+ Adops Report Scrapper is a collection of web scrappers that can automatically extract the data from your ad server, ad networks, ad exchanges, and other ad partners. It is an open source alternative to [STAQ](http://www.staq.com/). Say good-bye to spreadsheet. At the moment, this gem only focus on getting the data in. It is up to you how you would aggregate the data into your pageview & dfp/ad server data set.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'adops_report_scrapper'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install adops_report_scrapper
20
+
21
+ ## Usage
22
+
23
+ #### Example
24
+
25
+ ```ruby
26
+ require 'adops_report_scrapper'
27
+ AdopsReportScrapper.get_scrapper(:brightroll, 'login', 'secret', {}).get_data
28
+
29
+ # return an array of arrays. First array is the header of the data table. Other arrays are the data
30
+ # example: [["Watch", "Status", "Name", "ID", "CPM Floor", "Revenue", "eCPM", "Requests", "Responses", "Response Rate", "Impressions", "Impression Rate", "Fill Rate", "Viewable Rate", "Clicks", "CTR", "Mid Rate", "Completion Rate", "Companion Impressions", "Companion Clicks", "Companion CTR", "Created On", "Last Modified"], ["", "", "My Post RON CDN", "3863603", "$6.00", "$9.99", "$6.68", "14,951", "2,556", "17.10%", "1,496", "58.53%", "10.01%", "60.87%", "7", "0.47%", "51.80%", "45.05%", "0.00%", "0", "0.00%", "03/23/2015", "06/25/2016"], ["", "", "My Post 400x300", "3855941", "$6.00", "$0.04", "$6.07", "78", "37", "47.44%", "6", "16.22%", "7.69%", "0.00%", "0", "0.00%", "50.00%", "66.67%", "0.00%", "0", "0.00%", "12/20/2013", "06/24/2016"], ["", "", "My Post", "3860218", "$7.00", "$0.03", "$8.07", "26", "12", "46.15%", "4", "33.33%", "15.38%", "0.00%", "0", "0.00%", "125.00%", "125.00%", "0.00%", "0", "0.00%", "10/10/2014", "06/09/2016"], ["", "", "My Post 640x480", "3855297", "$7.00", "$0.00", "$0.00", "0", "0", "0.00%", "0", "0.00%", "0.00%", "0.00%", "0", "0.00%", "0.00%", "0.00%", "0.00%", "0", "0.00%", "11/25/2013", "06/28/2016"], ["", "", "My Post 300x250", "3855943", "$2.00", "$0.00", "$0.00", "0", "0", "0.00%", "0", "0.00%", "0.00%", "0.00%", "0", "0.00%", "0.00%", "0.00%", "0.00%", "0", "0.00%", "12/20/2013", "06/09/2016"], ["", "", "Mobile - iPhone web…e My Post NCT", "3856072", "$4.00", "$0.00", "$0.00", "0", "0", "0.00%", "0", "0.00%", "0.00%", "0.00%", "0", "0.00%", "0.00%", "0.00%", "0.00%", "0", "0.00%", "01/07/2014", "05/23/2016"], ["", "", "Mobile - Android we…- The My Post", "3856089", "$4.00", "$0.00", "$0.00", "0", "0", "0.00%", "0", "0.00%", "0.00%", "0.00%", "0", "0.00%", "0.00%", "0.00%", "0.00%", "0", "0.00%", "01/08/2014", "05/23/2016"], ["", "", "Mobile - iPad web -…e My Post NCT", "3856127", "$4.00", "$0.00", "$0.00", "0", "0", "0.00%", "0", "0.00%", "0.00%", "0.00%", "0", "0.00%", "0.00%", "0.00%", "0.00%", "0", "0.00%", "01/10/2014", "05/23/2016"], ["", "", "My Today 6836382", "3860216", "$7.00", "$0.00", "$0.00", "0", "0", "0.00%", "0", "0.00%", "0.00%", "0.00%", "0", "0.00%", "0.00%", "0.00%", "0.00%", "0", "0.00%", "10/10/2014", "06/29/2016"], ["", "", "My Herald", "3860220", "$6.00", "$0.00", "$0.00", "0", "0", "0.00%", "0", "0.00%", "0.00%", "0.00%", "0", "0.00%", "0.00%", "0.00%", "0.00%", "0", "0.00%", "10/10/2014", "06/09/2016"], ["", "", "My News", "3860222", "$7.00", "$0.00", "$0.00", "0", "0", "0.00%", "0", "0.00%", "0.00%", "0.00%", "0", "0.00%", "0.00%", "0.00%", "0.00%", "0", "0.00%", "10/10/2014", "06/29/2016"], ["", "", "My Blog", "3860224", "$5.00", "$0.00", "$0.00", "15", "7", "46.67%", "0", "0.00%", "0.00%", "0.00%", "0", "0.00%", "0.00%", "0.00%", "0.00%", "0", "0.00%", "10/10/2014", "06/09/2016"], ["", "", "My Times 400x300", "3863146", "$7.00", "$0.00", "$0.00", "0", "0", "0.00%", "0", "0.00%", "0.00%", "0.00%", "0", "0.00%", "0.00%", "0.00%", "0.00%", "0", "0.00%", "03/02/2015", "06/29/2016"], ["", "", "My Post RON UK", "3863604", "$5.46", "$0.00", "$0.00", "0", "0", "0.00%", "0", "0.00%", "0.00%", "0.00%", "0", "0.00%", "0.00%", "0.00%", "0.00%", "0", "0.00%", "03/23/2015", "06/09/2016"], ["", "", "My Post RON AU", "3863906", "$4.43", "$0.00", "$0.00", "0", "0", "0.00%", "0", "0.00%", "0.00%", "0.00%", "0", "0.00%", "0.00%", "0.00%", "0.00%", "0", "0.00%", "04/01/2015", "06/09/2016"]]
31
+ ```
32
+
33
+ ## Supported Scrappers
34
+
35
+ Check `lib/adops_report_scrapper` directory for implemented scrappers.
36
+
37
+ Check `secret.sample.yml` for expected args to be passed to each scrapper.
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
42
+
43
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( https://github.com/StaymanHou/adops_report_scrapper/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,152 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'yaml'
3
+ require 'csv'
4
+ require 'date'
5
+ require 'adops_report_scrapper'
6
+
7
+ require 'byebug'
8
+
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] do # openx is the most unstable one, run it first
11
+ puts '========== You are all set'
12
+ end
13
+
14
+ desc 'Collect tremor data'
15
+ task :tremor do
16
+ save_as_csv :tremor, :tremor
17
+ end
18
+
19
+ desc 'collect brightroll data'
20
+ task :brightroll do
21
+ save_as_csv :brightroll, :brightroll
22
+ end
23
+
24
+ desc 'Collect yellowhammer data'
25
+ task :yellowhammer do
26
+ save_as_csv :yellowhammer, :springserve
27
+ end
28
+
29
+ desc 'Collect adaptv data'
30
+ task :adaptv do
31
+ save_as_csv :adaptv, :adaptv
32
+ end
33
+
34
+ desc 'Collect fourninefive data'
35
+ task :fourninefive do
36
+ save_as_csv :fourninefive, :adforge
37
+ end
38
+
39
+ desc 'Collect adx data'
40
+ task :adx do
41
+ save_as_csv :adx, :adx
42
+ end
43
+
44
+ desc 'Collect revcontent data'
45
+ task :revcontent do
46
+ save_as_csv :revcontent, :revcontent
47
+ end
48
+
49
+ desc 'Collect gcs data'
50
+ task :gcs do
51
+ save_as_csv :gcs, :gcs
52
+ end
53
+
54
+ desc 'Collect browsi data'
55
+ task :browsi do
56
+ save_as_csv :browsi, :browsi
57
+ end
58
+
59
+ desc 'Collect openx data'
60
+ task :openx do
61
+ save_as_csv :openx, :openx
62
+ end
63
+
64
+ desc 'Collect netseer data'
65
+ task :netseer do
66
+ save_as_csv :netseer, :netseer
67
+ end
68
+
69
+ desc 'Collect sonobi data'
70
+ task :sonobi do
71
+ save_as_csv :sonobi, :sonobi
72
+ end
73
+
74
+ desc 'Collect nativo data'
75
+ task :nativo do
76
+ save_as_csv :nativo, :nativo
77
+ end
78
+
79
+ desc 'Collect adsupply data'
80
+ task :adsupply do
81
+ save_as_csv :adsupply, :adsupply
82
+ end
83
+
84
+ desc 'Collect marfeel data'
85
+ task :marfeel do
86
+ save_as_csv :marfeel, :marfeel
87
+ end
88
+
89
+ desc 'Collect adsense data'
90
+ task :adsense do
91
+ save_as_csv :adsense, :adsense
92
+ end
93
+
94
+ desc 'Collect criteo data'
95
+ task :criteo do
96
+ save_as_csv :criteo, :criteo
97
+ end
98
+
99
+ desc 'Collect triplelift data'
100
+ task :triplelift do
101
+ save_as_csv :triplelift, :triplelift
102
+ end
103
+
104
+ desc 'Collect conversant data'
105
+ task :conversant do
106
+ save_as_csv :conversant, :conversant
107
+ end
108
+
109
+ desc 'Collect liveintent data'
110
+ task :liveintent do
111
+ save_as_csv :liveintent, :liveintent
112
+ end
113
+
114
+ desc 'Collect adiply data'
115
+ task :adiply do
116
+ save_as_csv :adiply, :adiply
117
+ end
118
+
119
+ desc 'Collect contentad data'
120
+ task :contentad do
121
+ save_as_csv :contentad, :contentad
122
+ end
123
+
124
+ desc 'Collect facebookaudience data'
125
+ task :facebookaudience do
126
+ save_as_csv :facebookaudience, :facebookaudience
127
+ end
128
+
129
+ def get_yesterdays_file_path(adnetwork)
130
+ "tmp/#{Date.today.prev_day}/#{adnetwork}.csv"
131
+ end
132
+
133
+ def write_csv(adnet, data)
134
+ Dir.mkdir "tmp/#{Date.today.prev_day}" unless Dir.exists? "tmp/#{Date.today.prev_day}"
135
+ CSV.open(get_yesterdays_file_path(adnet), 'w') do |csv|
136
+ data.each do |row|
137
+ csv << row
138
+ end
139
+ end
140
+ end
141
+
142
+ def save_as_csv(adnet, scrapper) # adnet and scrapper are both sym
143
+ if File.file?(get_yesterdays_file_path(adnet))
144
+ puts "========== #{adnet} data already scraped"
145
+ return
146
+ end
147
+ puts "========== working on #{adnet}"
148
+ cred = YAML.load_file('secret.yml')[adnet.to_s]
149
+ data = AdopsReportScrapper.get_scrapper(adnet, cred['login'], cred['secret'], cred['options']).get_data
150
+ byebug
151
+ write_csv(adnet, data)
152
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'adops_report_scrapper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "adops_report_scrapper"
8
+ spec.version = AdopsReportScrapper::VERSION
9
+ spec.authors = ["Stayman Hou"]
10
+ spec.email = ["stayman.hou@gmail.com"]
11
+
12
+ spec.summary = %q{Adops Report Scrapper is a collection of web scrappers that can automatically extract the data from your ad partners.}
13
+ spec.description = %q{Adops Report Scrapper is a collection of web scrappers that can automatically extract the data from your ad server, ad networks, ad exchanges, and other ad partners. It is an open source alternative to [STAQ](http://www.staq.com/). Say good-bye to spreadsheet. At the moment, this gem only focus on getting the data in. It is up to you how you would aggregate the data into your pageview & dfp/ad server data set.}
14
+ spec.homepage = 'https://github.com/StaymanHou/adops_report_scrapper'
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.8"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "adops_report_scrapper"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+ require "adops_report_scrapper/version"
2
+
3
+ module AdopsReportScrapper
4
+ def self.get_scrapper(module_name, login, secret, options = nil)
5
+ scrapper_client_klass = self.const_get "#{self.camelcase(module_name)}Client"
6
+ scrapper_client_klass.new(login, secret, options)
7
+ end
8
+
9
+ private
10
+
11
+ def self.camelcase(str)
12
+ str.to_s.downcase.split('_').map { |word| word.capitalize }.join
13
+ end
14
+ end
15
+
16
+ require 'adops_report_scrapper/adaptv_client'
17
+ require 'adops_report_scrapper/adforge_client'
18
+ require 'adops_report_scrapper/adiply_client'
19
+ require 'adops_report_scrapper/adsense_client'
20
+ require 'adops_report_scrapper/adsupply_client'
21
+ require 'adops_report_scrapper/adx_client'
22
+ require 'adops_report_scrapper/brightroll_client'
23
+ require 'adops_report_scrapper/browsi_client'
24
+ require 'adops_report_scrapper/contentad_client'
25
+ require 'adops_report_scrapper/conversant_client'
26
+ require 'adops_report_scrapper/criteo_client'
27
+ require 'adops_report_scrapper/facebookaudience_client'
28
+ require 'adops_report_scrapper/gcs_client'
29
+ require 'adops_report_scrapper/liveintent_client'
30
+ require 'adops_report_scrapper/marfeel_client'
31
+ require 'adops_report_scrapper/nativo_client'
32
+ require 'adops_report_scrapper/netseer_client'
33
+ require 'adops_report_scrapper/openx_client'
34
+ require 'adops_report_scrapper/revcontent_client'
35
+ require 'adops_report_scrapper/sonobi_client'
36
+ require 'adops_report_scrapper/springserve_client'
37
+ require 'adops_report_scrapper/tremor_client'
38
+ require 'adops_report_scrapper/triplelift_client'
@@ -0,0 +1,80 @@
1
+ require 'date'
2
+ require_relative 'base_client'
3
+
4
+ class AdopsReportScrapper::AdaptvClient < AdopsReportScrapper::BaseClient
5
+ private
6
+
7
+ def login
8
+ @client.visit 'https://onevideo.aol.com/#/logon'
9
+ @client.fill_in 'adaptv_email', :with => @login
10
+ @client.fill_in 'adaptv_password', :with => @secret
11
+ @client.click_button 'Sign in >'
12
+ begin
13
+ @client.find :xpath, '//*[text()="Analytics"]'
14
+ rescue Exception => e
15
+ raise e, 'Adaptv login error'
16
+ end
17
+ end
18
+
19
+ def scrap
20
+ request_report
21
+ extract_data_from_report
22
+ end
23
+
24
+ def request_report
25
+ @client.find(:xpath, '//*[text()="Analytics"]').click
26
+ @client.find(:xpath, '//*[text()="Reports"]').click
27
+ wait_for_spin
28
+ @client.find(:xpath, '//*[text()="New Report"]').click
29
+ wait_for_spin
30
+
31
+ @client.fill_in 'Report Name', :with => "tmp-#{Time.now.to_i}"
32
+
33
+ @client.check 'Media'
34
+ @client.check 'Geo: Country'
35
+
36
+ @client.click_link 'Metrics'
37
+
38
+ @client.check 'Ad Attempts'
39
+ @client.check 'Ad Opportunities'
40
+ @client.check 'Ad Break Impressions'
41
+ @client.check 'Ad Impressions'
42
+ @client.check 'IAB Viewable Ad Impressions'
43
+ @client.check '100% Completed Views'
44
+ @client.check 'Ad Skips'
45
+ @client.check 'Clicks'
46
+ @client.check 'Ad Revenue'
47
+
48
+ @client.click_button 'Run Report'
49
+ wait_for_spin
50
+
51
+ @client.find(:xpath, '//option[text()="100"]').select_option
52
+ sleep 5
53
+ end
54
+
55
+ def extract_data_from_report
56
+ @data = []
57
+ thead = @client.find :xpath, '//table[1]/thead/tr'
58
+ @data << thead.find_css('td,th').map { |td| td.visible_text }
59
+ 99.times do |_i|
60
+ rows = @client.find_all :xpath, '//table[1]/tbody/tr'
61
+ @data += rows.map { |tr| tr.find_css('td,th').map { |td| td.visible_text } }
62
+ pagee = @client.find(:xpath, '//*[contains(text()," / ")]').text.split(' / ')
63
+ break if pagee[0] == pagee[1]
64
+ @client.click_button 'Next'
65
+ sleep 5
66
+ end
67
+ end
68
+
69
+ def wait_for_spin
70
+ 30.times do |_i| # wait 5 min
71
+ begin
72
+ @client.find(:css, '.busy-spinner-large')
73
+ rescue Exception => e
74
+ break
75
+ end
76
+ sleep 10
77
+ end
78
+ sleep 5
79
+ end
80
+ end