susuwatari 0.0.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -22,20 +22,20 @@ This gem allows you to use the API of Patrick Meenan excellent [webpagetest.org]
22
22
  => :completed
23
23
 
24
24
  mei.result.keys
25
- => [ "testId", "summary", "testUrl", "location", "connectivity",
26
- "bwDown", "bwUp", "latency", "plr", "completed", "runs", "average",
25
+ => [ "test_id", "summary", "test_url", "location", "connectivity",
26
+ "bw_down", "bw_up", "latency", "plr", "completed", "runs", "average",
27
27
  "median", "run"]
28
28
 
29
- mei.result.testId
29
+ mei.result.test_id
30
30
  => "aASFDasfdads2"
31
31
 
32
- mei.result.run.firstView.images.waterfall
32
+ mei.result.run.first_view.images.waterfall
33
33
  => "http://www.webpagetest.org/results/12/02/09/KG/35XV333/1_waterfall.png"
34
34
 
35
- mei.result.run.firstView.results.score_cache
35
+ mei.result.run.first_view.results.score_cache
36
36
  => "98"
37
37
 
38
- mei.result.run.firstView.results.requests
38
+ mei.result.run.first_view.results.requests
39
39
  => 12
40
40
 
41
41
  You can check what a result looks like [here](https://sites.google.com/a/webpagetest.org/docs/advanced-features/webpagetest-restful-apis#TOC-Getting-test-results).
@@ -73,16 +73,20 @@ Once you've installed the gem, you can use it like this:
73
73
  => :completed
74
74
 
75
75
  mei.result.keys
76
- => [ "testId", "summary", "testUrl", "location", "connectivity",
77
- "bwDown", "bwUp", "latency", "plr", "completed", "runs", "average",
76
+ => [ "test_id", "summary", "test_url", "location", "connectivity",
77
+ "bw_down", "bw_up", "latency", "plr", "completed", "runs", "average",
78
78
  "median", "run"]
79
79
 
80
80
  #You can access the results as a hash
81
- mei.result["testId"]
81
+ mei.result[:test_id]
82
82
  => 'aBd333'
83
83
 
84
84
  #Or in a pseudo-object oriented fashion
85
- mei.result.testId
85
+ mei.result.test_id
86
86
  => 'aBd333'
87
87
 
88
+ Locations
89
+ ----
90
+ To see a list of all the available locations and how you need to pass
91
+ the `location` parameter check [locations](http://www.webpagetest.org/getLocations.php)
88
92
 
@@ -1,4 +1,5 @@
1
1
  require 'active_support/core_ext/hash/conversions'
2
+ require 'active_support/inflections'
2
3
 
3
4
  require 'csv'
4
5
 
@@ -40,7 +41,25 @@ module Susuwatari
40
41
 
41
42
  def fetch_result
42
43
  response = RestClient.get "#{RESULT_URL_PREFIX}/#{test_id}/"
43
- @test_result = Hashie::Mash.new(Hash.from_xml(response.body)).response.data
44
+ response = deep_symbolize(Hash.from_xml(response.body)){ |key| key.underscore }
45
+ @test_result = Hashie::Mash.new(response).response.data
46
+ end
47
+
48
+ # Thanks to https://gist.github.com/998709 with a slightly modification.
49
+ def deep_symbolize(hsh, &block)
50
+ hsh.inject({}) { |result, (key, value)|
51
+ # Recursively deep-symbolize subhashes
52
+ value = deep_symbolize(value, &block) if value.is_a? Hash
53
+
54
+ # Pre-process the key with a block if it was given
55
+ key = yield key if block_given?
56
+ # Symbolize the key string if it responds to to_sym
57
+ sym_key = key.to_sym rescue key
58
+
59
+ # write it back into the result and return the updated hash
60
+ result[sym_key] = value
61
+ result
62
+ }
44
63
  end
45
64
  end
46
65
  end
@@ -1,3 +1,3 @@
1
1
  module Susuwatari
2
- VERSION = "0.0.3"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: susuwatari
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-02-17 00:00:00.000000000Z
13
+ date: 2012-03-28 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
- requirement: &2161800200 !ruby/object:Gem::Requirement
17
+ requirement: &2153361960 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 3.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2161800200
25
+ version_requirements: *2153361960
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: json
28
- requirement: &2161799700 !ruby/object:Gem::Requirement
28
+ requirement: &2153361460 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 1.5.0
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2161799700
36
+ version_requirements: *2153361460
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: hashie
39
- requirement: &2161799240 !ruby/object:Gem::Requirement
39
+ requirement: &2153361000 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 1.2.0
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *2161799240
47
+ version_requirements: *2153361000
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rest-client
50
- requirement: &2161798780 !ruby/object:Gem::Requirement
50
+ requirement: &2153360540 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,7 +55,7 @@ dependencies:
55
55
  version: 1.6.7
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *2161798780
58
+ version_requirements: *2153360540
59
59
  description: Allows to schedule tests on webpagetest.org
60
60
  email:
61
61
  - bk@benjaminkrause.com