adops_report_scrapper 0.2.11 → 0.2.12

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: 930f32bcaba2b9f0e1ef064c7653de22ba9d16e1
4
- data.tar.gz: 641ea80bcbda0f079dcb391986cd01192963ff38
3
+ metadata.gz: 1c5a877e8b9e8f755a4d1023995b6ada71b78809
4
+ data.tar.gz: a556c03cbfe2abed04f11982647e56ccb8b21d70
5
5
  SHA512:
6
- metadata.gz: 94d1a047b48bb209727e2ea25ff93e9464e856b608437b731725a6675ee7745b46aa96b5f7fcdc3a1f4797142d6b829c93bf619051090def9c3c70aafc831094
7
- data.tar.gz: eb7cd5e709dfa30f9b49ba8adb87a32c81398c7f26ad5185bcfb30a68d8e05260975bbcea50689b89217edb9c2ea5cbfea6de48703141420ef1db4a18bfb1c5a
6
+ metadata.gz: e39030a6c4936f4753718acdf28cbc94b0aeff3c6cd35ef2b075ca9959aefea73b8fed249b32aa366f026bfd3e858a58c6c70300a9e327560cf23b8ec8bcb97e
7
+ data.tar.gz: 9d9686e72bdb9d80dc0164965039063a4266910aa9c5c0e771775076194873cda5136d25a8fa2f7c2c039e34a19bf5011253e40653b91ea5b1279a0eef33d21a
data/CHANGELOG CHANGED
@@ -1,5 +1,8 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.2.12
4
+ fix springserve client, use their rest api instead
5
+
3
6
  ## 0.2.11
4
7
  bug fix
5
8
  implement email client
@@ -1,53 +1,33 @@
1
1
  require 'date'
2
2
  require_relative 'base_client'
3
+ require 'rest-client'
3
4
 
4
5
  class AdopsReportScrapper::SpringserveClient < AdopsReportScrapper::BaseClient
5
6
  private
6
7
 
7
- def login
8
- @client.visit 'http://video.springserve.com/'
9
- @client.fill_in 'Email', :with => @login
10
- @client.fill_in 'Password', :with => @secret
11
- @client.click_button 'Log in'
12
- begin
13
- @client.find :xpath, '//*[contains(text(),"Reporting")]'
14
- rescue Exception => e
15
- raise e, 'Springserve login error'
16
- end
8
+ def init_client
17
9
  end
18
10
 
19
- def scrap
20
- request_report
21
- extract_data_from_report
11
+ def before_quit_with_error
22
12
  end
23
13
 
24
- def request_report
25
- @client.find(:xpath, '//*[contains(text(),"Reporting")]').click
26
- @client.find(:xpath, '//*[contains(text(),"Create Reports")]').click
14
+ private
27
15
 
28
- # select date
29
- @client.find(:css, '#date_range_chosen').click
30
- @client.find(:xpath, '//*[text()="Yesterday"]').click
16
+ def scrap
17
+ date_str = @date.strftime('%Y-%m-%d')
31
18
 
32
- @client.find(:css, '#dimensions_chosen').click
33
- @client.find(:xpath, '//*[text()="Country"]').click
19
+ response = RestClient.post "https://video.springserve.com/api/v0/auth", email: @login, password: @secret
20
+ data = JSON.parse response
21
+ token = data['token']
34
22
 
35
- @client.find(:xpath, '//*[@value="Run Report"]').click
23
+ headers = { content_type: :json, accept: :json, authorization: token }
36
24
 
37
- 30.times do |_i| # wait 5 min
38
- begin
39
- @client.find(:css, '#spinner_image')
40
- rescue Exception => e
41
- break
42
- end
43
- sleep 10
25
+ response = RestClient.post "https://video.springserve.com/api/v0/report", { timezone: 'America/New_York', date_range: 'Yesterday', interval: 'cumulative', dimensions: ['country', 'supply_tag_id']}.to_json, headers
26
+ data = JSON.parse response
27
+ header = data[0].keys
28
+ @data = [header]
29
+ @data += data.map do |datum|
30
+ header.map { |key| datum[key] }
44
31
  end
45
- sleep 10
46
- end
47
-
48
- def extract_data_from_report
49
- rows = @client.find_all :xpath, '//table[1]/*/tr'
50
- @data = rows.map { |tr| tr.find_css('td,th').map { |td| td.visible_text } }.reject { |row| row[0] == 'Total' }
51
- @data = [] if @data.flatten.include? 'No data available in table'
52
32
  end
53
33
  end
@@ -1,3 +1,3 @@
1
1
  module AdopsReportScrapper
2
- VERSION = "0.2.11"
2
+ VERSION = "0.2.12"
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.11
4
+ version: 0.2.12
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-04-27 00:00:00.000000000 Z
11
+ date: 2017-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient