adops_report_scrapper 0.2.40 → 0.2.41

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: 6ea333993401f2ff4d7e13f6d5cd32ae5248ac8d
4
- data.tar.gz: a6e2210faa6c7aef1538239d21d6a28475d90aba
3
+ metadata.gz: 9c607980aba3786d27f887c7cf3e483e5ca9f9c7
4
+ data.tar.gz: 612447f3d4b4fd75d33829a526f50bd62f77d701
5
5
  SHA512:
6
- metadata.gz: 31531634eb4f4fd169568e78c02f86bcf120481d457529a2f2c66dff4e285eb9d7fde7504eecc4d366543cf26b01ec09b0529b75aee554b02315614b055ce1b9
7
- data.tar.gz: 51e8a886df41d46d0565fb898a553d858bac656f1b5afba9ede6984ca8b9f61f6dd1c496ccbcde3f86c0d6003ffaa2e540c5b8007474924345120577bb7059bc
6
+ metadata.gz: 3d343ae25f045bc41b47f1c63461292cc1693cbf4cad20b4f7de623a3ea96a6da084be319158062e11f63b5331a2f460eb1b183262782c2253bbf28e8e34dcd4
7
+ data.tar.gz: bc3e7b151ce2e26f6a17437e03f93ffb6a4f975de8019ad354f2b8a42b419bbf4526798c283b9b8d3b17072dbabb8c532b587542ed54a756db3bd776a7281dc6
data/CHANGELOG CHANGED
@@ -1,5 +1,8 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.2.41
4
+ springserve client bug fix for account_id option. revcontent client refactor using their rest api
5
+
3
6
  ## 0.2.40
4
7
  tremor resume timezone option
5
8
 
@@ -1,51 +1,43 @@
1
1
  require 'date'
2
2
  require_relative 'base_client'
3
+ require 'rest-client'
3
4
 
4
5
  class AdopsReportScrapper::RevcontentClient < AdopsReportScrapper::BaseClient
5
6
  private
6
7
 
7
- def login
8
- @client.visit 'https://www.revcontent.com/login'
9
- @client.fill_in 'name', :with => @login
10
- @client.fill_in 'password', :with => @secret
11
- @client.click_button 'Sign In'
12
- begin
13
- @client.find :xpath, '//*[contains(text(),"Widgets")]'
14
- rescue Exception => e
15
- raise e, 'Revcontent login error'
16
- end
8
+ def init_client
17
9
  end
18
10
 
19
- def scrap
20
- @client.find(:xpath, '//*[contains(text(),"Widgets")]').click
21
- @client.find(:css, '.fa.fa-calendar').click
22
- @client.find(:xpath, '//*[text()="Yesterday"]').click
23
- @data = []
24
- %w(desktoplg desktop tablet phone unknown).each do |device|
25
- request_report(device)
26
- extract_data_from_report(device)
27
- end
11
+ def before_quit_with_error
28
12
  end
29
13
 
30
- def request_report(device)
31
- @client.find(:css, '.fa.fa-desktop').click
32
- @client.find(:xpath, '//*[text()="All Devices"]').click
33
- @client.find(:css, '.fa.fa-desktop').click
34
- @client.check device
35
- end
14
+ def scrap
15
+ date_str = @date.strftime('%Y-%m-%d')
16
+
17
+ headers = { cache_control: 'no-cache' }
36
18
 
37
- def extract_data_from_report(device)
38
- rows = @client.find_all :xpath, '//table/*/tr'
39
- rows = rows.map { |tr| tr.find_css('td,th').map { |td| td.visible_text } }
40
- header = rows.shift
41
- rows.shift
42
- if @data.count == 0
43
- header.unshift 'Device'
44
- @data << header
19
+ response = RestClient.post 'https://api.revcontent.io/oauth/token', { grant_type: 'client_credentials', client_id: @login, client_secret: @secret }, headers
20
+ data = JSON.parse response
21
+ token = data['access_token']
22
+
23
+ headers = { authorization: "Bearer #{token}", content_type: :json, cache_control: 'no-cache' }
24
+
25
+ data = []
26
+
27
+ %w(desktoplg desktop tablet mobile unknown).each do |device|
28
+ response = RestClient.get "https://api.revcontent.io/stats/api/v1.0/widgets?date_from=#{date_str}&date_to=#{date_str}&device=#{device}", headers
29
+ _data = JSON.parse response
30
+ _data = _data['data']
31
+ _data.each { |datum| datum['device'] = device }
32
+ data += _data
45
33
  end
46
- rows.each do |row|
47
- row.unshift device
34
+
35
+ header = data[0].keys
36
+ @data = [header]
37
+ @data += data.map do |datum|
38
+ header.map { |key| datum[key] }
48
39
  end
49
- @data += rows
40
+
41
+ byebug
50
42
  end
51
43
  end
@@ -6,14 +6,12 @@ class AdopsReportScrapper::SpringserveClient < AdopsReportScrapper::BaseClient
6
6
  private
7
7
 
8
8
  def init_client
9
- end
10
-
11
- def before_quit_with_error
12
9
  fail 'please specify springserve account_id' unless @options['account_id']
13
10
  @account_id = @options['account_id']
14
11
  end
15
12
 
16
- private
13
+ def before_quit_with_error
14
+ end
17
15
 
18
16
  def scrap
19
17
  date_str = @date.strftime('%Y-%m-%d')
@@ -1,3 +1,3 @@
1
1
  module AdopsReportScrapper
2
- VERSION = "0.2.40"
2
+ VERSION = "0.2.41"
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.2.40
4
+ version: 0.2.41
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stayman Hou
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-15 00:00:00.000000000 Z
11
+ date: 2017-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient