adops_report_scrapper 0.1.52 → 0.1.53

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: 1f6f461225876e13e3630b7a79d5e10deb56e869
4
- data.tar.gz: d044c856cab3f97e690da2d6e6443bedea7f3e49
3
+ metadata.gz: 53dcb8d2f6564cdbe088c2328fbc083fd9569943
4
+ data.tar.gz: ad1d6f7925db7a8c1bcec00125d1fb982d802da8
5
5
  SHA512:
6
- metadata.gz: b6505ae27409d35f0c4bed26c63c336a65cf71ddaa62cef792003f9e7908067baff330b44fdae6406402c41fea4e842c620702d00fd9a116146b9d9e1000a354
7
- data.tar.gz: a0ed7026cd9c87942958342db8aa18bb69d3f2ccb96ccc26a2b7fce5bf88264fec93fd4041f45c29f664bd06056f61515fbd84f3a440251012ed7f9dcfde1a9a
6
+ metadata.gz: 09ebadfdde3371c20e7f6d2b7af9a3c399f3d5cf77016fd890a12d406602c16ca765a8d9e03471b1dbbe4b63f8d6c35ac12cc36b20f457d77d6085f5d463ea99
7
+ data.tar.gz: 129d3e422282c08c39c7854619372228e281f85514a0e418b43cf4245e0704ef6020b26e583dd763932250c8390cd776cfa8dca9e65d95bba20de4310148311c
data/CHANGELOG CHANGED
@@ -1,5 +1,8 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.1.53
4
+ implement positivemobile
5
+
3
6
  ## 0.1.52
4
7
  fix adaptv - what the hack are they thinking by spliting the username and password into two steps?!
5
8
 
data/Rakefile CHANGED
@@ -166,6 +166,11 @@ task :imonomy do
166
166
  save_as_csv :imonomy, :imonomy
167
167
  end
168
168
 
169
+ desc 'Collect positivemobile data'
170
+ task :positivemobile do
171
+ save_as_csv :positivemobile, :positivemobile
172
+ end
173
+
169
174
  def date
170
175
  @date ||= ENV['date'].nil? ? Date.today - 1 : Date.today - ENV['date'].to_i
171
176
  end
@@ -1,8 +1,6 @@
1
1
  require 'date'
2
2
  require_relative 'base_client'
3
3
 
4
- # gcs sometimes doesn't update data in 24 hours
5
-
6
4
  class AdopsReportScrapper::ImonomyClient < AdopsReportScrapper::BaseClient
7
5
  def date_supported?(date = nil)
8
6
  _date = date || @date
@@ -0,0 +1,70 @@
1
+ require 'date'
2
+ require_relative 'base_client'
3
+
4
+ class AdopsReportScrapper::PositivemobileClient < AdopsReportScrapper::BaseClient
5
+ def date_supported?(date = nil)
6
+ _date = date || @date
7
+ return true if _date >= Date.today - 7
8
+ false
9
+ end
10
+
11
+ private
12
+
13
+ def login
14
+ @client.visit 'https://rapidv.positivemobile.com/'
15
+ @client.fill_in 'Username', :with => @login
16
+ @client.fill_in 'Password', :with => @secret
17
+ @client.click_button 'Sign in'
18
+ begin
19
+ @client.find :xpath, '//*[text()="Reports"]'
20
+ rescue Exception => e
21
+ raise e, 'Positivemobile login error'
22
+ end
23
+
24
+
25
+ cookies = @client.driver.cookies
26
+ @client = HTTPClient.new
27
+ @client.cookie_manager.cookies = cookies.values.map do |cookie|
28
+ cookie = cookie.instance_variable_get(:@attributes)
29
+ HTTP::Cookie.new cookie
30
+ end
31
+ end
32
+
33
+ def scrap
34
+ request_report
35
+ extract_data_from_report
36
+ end
37
+
38
+ def request_report
39
+ date_str = @date.strftime('%Y-%m-%d')
40
+
41
+ header = {
42
+ Accept: 'Accept:application/json, text/plain, */*',
43
+ Origin: 'https://rapidv.positivemobile.com',
44
+ Referer: ':https//rapidv.positivemobile.com/reports',
45
+ 'User-Agent': 'Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1',
46
+ 'Content-Type': 'application/json',
47
+ }
48
+
49
+ body = {
50
+ dimensions: ['tagName', 'udc'],
51
+ filters: [],
52
+ from: "#{date_str}T00:00:00.000Z",
53
+ metrics: ['imp', 'revenue_publisher_cpm', 'dspimpv'],
54
+ timeFrame: 'Custom',
55
+ timeLevel: 'Daily',
56
+ timeZone: 'America/New_York',
57
+ to: "#{date_str}T00:00:00.000Z",
58
+ type: 'Supply'
59
+ }.to_json
60
+
61
+ @response = @client.post('https://rapidv.positivemobile.com/api/reports/run', header: header, body: body )
62
+ end
63
+
64
+ def extract_data_from_report
65
+ rows = JSON.parse @response.body
66
+ keys = rows.first.keys
67
+ @data = [keys]
68
+ @data += rows.map(&:values)
69
+ end
70
+ end
@@ -1,3 +1,3 @@
1
1
  module AdopsReportScrapper
2
- VERSION = "0.1.52"
2
+ VERSION = "0.1.53"
3
3
  end
@@ -44,3 +44,4 @@ require 'adops_report_scrapper/littlethings_client'
44
44
  require 'adops_report_scrapper/rubicon_client'
45
45
  require 'adops_report_scrapper/undertone_client'
46
46
  require 'adops_report_scrapper/imonomy_client'
47
+ require 'adops_report_scrapper/positivemobile_client'
data/secret.sample.yml CHANGED
@@ -111,3 +111,6 @@ undertone:
111
111
  imonomy:
112
112
  login: ------
113
113
  secret: ------
114
+ positivemobile:
115
+ login: ------
116
+ 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.52
4
+ version: 0.1.53
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stayman Hou
@@ -240,6 +240,7 @@ files:
240
240
  - lib/adops_report_scrapper/nativo_client.rb
241
241
  - lib/adops_report_scrapper/netseer_client.rb
242
242
  - lib/adops_report_scrapper/openx_client.rb
243
+ - lib/adops_report_scrapper/positivemobile_client.rb
243
244
  - lib/adops_report_scrapper/revcontent_client.rb
244
245
  - lib/adops_report_scrapper/rhythmone_client.rb
245
246
  - lib/adops_report_scrapper/rubicon_client.rb