adops_report_scrapper 0.1.23 → 0.1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: baf2e5206eb476a1f34966d49549797e4eff6e04
4
- data.tar.gz: 0ac95ba0dead4c7cad4ccb594fabf5ce0bb427f5
3
+ metadata.gz: 1ef9379e7a810f802c7f741f4d44aa61c9354de4
4
+ data.tar.gz: 7ea5c8aafab042ac43b344723c11598cddb75834
5
5
  SHA512:
6
- metadata.gz: 9b6554e264f5ebaccd8c535b4982aa625b39ae078c4f09306e0bdbdcc619e6ec8633e4f01a053c1155c3290a3c76ee9ca16a376f0ceca5883e7ae00fb0a99cf4
7
- data.tar.gz: 9215b66a1b1a7574f908ab2a676aedad1521b38f4aece0f9138dab14a36aec9778c27a6784e38e376edf265c2935633dbec83e469a883d040f7cfc13600fe143
6
+ metadata.gz: 43ee246ae6835df0bb846f00c9e9086efb34239defaa9dce2b8e83e339be5185b6292a1d7c5c9a39fd3f7fe0d5868bc8467afd87e7e6ac149cfeaa0fd6e630de
7
+ data.tar.gz: bc633303cb0745ab0d97ad4f59acc6d5f6e33e766acfc25a8231255c2b34d17e055da1c2392bea3c85960e0b2a4bcc580b4ef4ac789102fbbde291b4fc55685a
data/CHANGELOG CHANGED
@@ -1,5 +1,8 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.1.24
4
+ improve rhythmone via using api
5
+
3
6
  ## 0.1.21
4
7
  improve rhythmone
5
8
 
@@ -1,56 +1,44 @@
1
1
  require 'date'
2
2
  require_relative 'base_client'
3
+ require 'rest-client'
4
+ require 'httpclient'
3
5
 
4
6
  class AdopsReportScrapper::RhythmoneClient < AdopsReportScrapper::BaseClient
5
- private
6
-
7
- def login
8
- @client.visit 'https://portal.rhythmone.com/login'
9
- sleep 1
10
- return if @client.find_all(:xpath, '//*[contains(text(),"REPORTING")]').count > 0
11
- @client.fill_in 'email', :with => @login
12
- @client.fill_in 'password', :with => @secret
13
- @client.click_button 'Sign in'
14
-
15
- begin
16
- @client.find :xpath, '//*[contains(text(),"REPORTING")]'
17
- rescue Exception => e
18
- raise e, 'Rhythmone login error'
19
- end
7
+ def date_supported?(date = nil)
8
+ _date = date || @date
9
+ return true if _date >= Date.today - 3
10
+ false
20
11
  end
21
12
 
22
- def scrap
23
- request_report
24
- extract_data_from_report
13
+ private
14
+
15
+ def init_client
16
+ fail 'please specify rhythmone client_id' unless @options['client_id']
17
+ fail 'please specify rhythmone client_secret' unless @options['client_secret']
18
+ fail 'please specify rhythmone publisher_id' unless @options['publisher_id']
19
+ @client_id = @options['client_id']
20
+ @client_secret = @options['client_secret']
21
+ @publisher_id = @options['publisher_id']
25
22
  end
26
23
 
27
- def request_report
28
- @client.find(:xpath, '//*[contains(text(),"REPORTING")]').click
29
- wait_for_loading
30
- @client.find(:xpath, '//option[contains(text(),"Yesterday")]').select_option
31
- sleep 1
32
- @client.find(:xpath, '//select[@ng-model="filter.group1"]').find(:xpath, 'option[contains(text(),"Placement")]').select_option
33
- wait_for_loading
34
- @client.click_button 'Generate report'
35
- sleep 2
36
- wait_for_loading
24
+ def before_quit_with_error
37
25
  end
38
26
 
39
- def extract_data_from_report
40
- rows = @client.find_all :xpath, '//table/*/tr'
41
- rows = rows.to_a
42
- @data = rows.map { |tr| tr.find_css('td,th').map { |td| td.visible_text } }
27
+ def login
28
+ response = RestClient.post 'https://api.portal.rhythmone.com/v1/users/login', client_id: @client_id, client_secret: @client_secret, grant_type: 'password', password: @secret, username: @login
29
+ token_obj = JSON.parse response.body
30
+ @access_token = token_obj['access_token']
43
31
  end
44
32
 
45
- def wait_for_loading
46
- 30.times do |_i| # wait 5 min
47
- begin
48
- @client.find(:xpath, '//overlay-spinner/div')
49
- rescue Exception => e
50
- break
51
- end
52
- sleep 10
33
+ def scrap
34
+ date_str = @date.strftime('%Y%m%d')
35
+ data_obj = nil
36
+ 5.times do
37
+ response = HTTPClient.get("https://api.portal.rhythmone.com/v1/publishers/#{@publisher_id}/reports/standard_report", { ad_dimension: 0, endDate: date_str, endDateType: 1, groupBy1: 1, groupByTimePeriodType: 1, rmp_placement: 0, startDate: date_str, startDatePredefined: 0, startDateType: 1 }, { 'Authorization' => "Bearer #{@access_token}" })
38
+ data_obj = JSON.parse response.body
39
+ break if data_obj.is_a? Array
40
+ sleep 5
53
41
  end
54
- sleep 10
42
+ @data = data_obj
55
43
  end
56
44
  end
@@ -1,3 +1,3 @@
1
1
  module AdopsReportScrapper
2
- VERSION = "0.1.23"
2
+ VERSION = "0.1.24"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adops_report_scrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.23
4
+ version: 0.1.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stayman Hou
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-12 00:00:00.000000000 Z
11
+ date: 2016-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient