domreactor-redglass 0.0.6 → 0.0.7
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.
data/domreactor-redglass.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'domreactor-redglass/version'
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = 'domreactor-redglass'
|
8
8
|
s.version = DomReactorRedGlass::VERSION
|
9
|
-
s.date = '
|
9
|
+
s.date = '2014-04-26'
|
10
10
|
s.summary = 'DomReactor plugin for RedGlass.'
|
11
11
|
s.description = 'Send RedGlass page archives to DomReactor for automated layout analysis.'
|
12
12
|
s.authors = ["Frank O'Hara", "Chris Lamb"]
|
data/lib/domreactor-redglass.rb
CHANGED
@@ -3,6 +3,7 @@ require 'domreactor-redglass/archive'
|
|
3
3
|
require 'domreactor-redglass/archive_location'
|
4
4
|
require 'domreactor-redglass/config'
|
5
5
|
require 'domreactor-redglass/version'
|
6
|
+
require 'domreactor-redglass/report_poller'
|
6
7
|
|
7
8
|
module DomReactorRedGlass
|
8
9
|
|
@@ -21,6 +22,12 @@ module DomReactorRedGlass
|
|
21
22
|
@chain_reaction.post_archives(archive_location)
|
22
23
|
end
|
23
24
|
|
25
|
+
def poll_report(opts={})
|
26
|
+
poller = ReportPoller.new(@chain_reaction, opts)
|
27
|
+
poller.poll_completion
|
28
|
+
poller.report
|
29
|
+
end
|
30
|
+
|
24
31
|
def parse_json_file(path)
|
25
32
|
json_str = File.open(path, 'rb') {|f| f.read}
|
26
33
|
JSON.parse(json_str, symbolize_names: true)
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'timeout'
|
2
|
+
require 'rest_client'
|
3
|
+
|
4
|
+
class ReportPoller
|
5
|
+
attr_reader :time_limit
|
6
|
+
|
7
|
+
def initialize(chain_reaction, opts={})
|
8
|
+
@chain_reaction = chain_reaction
|
9
|
+
@time_limit = opts[:time_limit] || 60
|
10
|
+
end
|
11
|
+
|
12
|
+
def params
|
13
|
+
@params ||= build_params(@chain_reaction)
|
14
|
+
end
|
15
|
+
|
16
|
+
def poll_completion
|
17
|
+
Timeout::timeout(@time_limit) {
|
18
|
+
percent_complete = @chain_reaction.info[:percent_complete]
|
19
|
+
until percent_complete == 100
|
20
|
+
percent_complete = fetch_percent_complete
|
21
|
+
sleep 1 unless percent_complete == 100
|
22
|
+
end
|
23
|
+
percent_complete
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def report
|
28
|
+
fetch_report
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def build_params(chain_reaction)
|
34
|
+
{
|
35
|
+
auth_token: chain_reaction.auth_token,
|
36
|
+
chain_reaction_id: chain_reaction.id,
|
37
|
+
content_type: 'application/json',
|
38
|
+
accept: :json
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def fetch_percent_complete
|
43
|
+
fetch_chain_reaction[:percent_complete]
|
44
|
+
end
|
45
|
+
|
46
|
+
def fetch_chain_reaction
|
47
|
+
response = RestClient.get(@chain_reaction.chain_reaction_url, { params: params })
|
48
|
+
JSON.parse(response, symbolize_names: true)[:chain_reaction]
|
49
|
+
end
|
50
|
+
|
51
|
+
def fetch_report
|
52
|
+
response = RestClient.get("#{@chain_reaction.chain_reaction_url}/reports", { params: params })
|
53
|
+
JSON.parse(response, symbolize_names: true)[:reports].first
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'timeout'
|
3
|
+
|
4
|
+
describe ReportPoller do
|
5
|
+
let(:chain_reaction) { DomReactorRedGlass::ChainReaction.new({}) }
|
6
|
+
before do
|
7
|
+
RestClient.stub(:post) { {chain_reaction: {id: 42, some_info: 'yay'}}.to_json }
|
8
|
+
ChainReaction.any_instance.stub(:baseline_browser) { {id: 1} }
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'time limit defaults to 60 seconds' do
|
12
|
+
poller = ReportPoller.new(chain_reaction)
|
13
|
+
poller.time_limit.should eq 60
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'times out' do
|
17
|
+
poller = ReportPoller.new(chain_reaction, { time_limit: 2 })
|
18
|
+
chain_reaction.should_receive(:info).and_return({ percent_complete: 0 })
|
19
|
+
poller.should_receive(:fetch_percent_complete).at_least(1).times.and_return(1)
|
20
|
+
expect{ poller.poll_completion }.to raise_error(TimeoutError)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'polls until completion' do
|
24
|
+
poller = ReportPoller.new(chain_reaction, { time_limit: 2 })
|
25
|
+
chain_reaction.should_receive(:info).and_return({ percent_complete: 0 })
|
26
|
+
poller.should_receive(:fetch_percent_complete).and_return(100)
|
27
|
+
poller.poll_completion.should eq 100
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: domreactor-redglass
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2014-04-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rest-client
|
@@ -161,6 +161,7 @@ files:
|
|
161
161
|
- lib/domreactor-redglass/archive_location.rb
|
162
162
|
- lib/domreactor-redglass/chain_reaction.rb
|
163
163
|
- lib/domreactor-redglass/config.rb
|
164
|
+
- lib/domreactor-redglass/report_poller.rb
|
164
165
|
- lib/domreactor-redglass/version.rb
|
165
166
|
- spec/archive_location_spec.rb
|
166
167
|
- spec/archive_spec.rb
|
@@ -178,6 +179,7 @@ files:
|
|
178
179
|
- spec/data/valid_archive/firefox_20.0_1369614644/screenshot.png
|
179
180
|
- spec/data/valid_archive/firefox_20.0_1369614644/source.html
|
180
181
|
- spec/domreactor_spec.rb
|
182
|
+
- spec/report_poller_spec.rb
|
181
183
|
- spec/spec_helper.rb
|
182
184
|
homepage: https://github.com/bimech/domreactor-redglass
|
183
185
|
licenses:
|
@@ -221,4 +223,5 @@ test_files:
|
|
221
223
|
- spec/data/valid_archive/firefox_20.0_1369614644/screenshot.png
|
222
224
|
- spec/data/valid_archive/firefox_20.0_1369614644/source.html
|
223
225
|
- spec/domreactor_spec.rb
|
226
|
+
- spec/report_poller_spec.rb
|
224
227
|
- spec/spec_helper.rb
|