Class: HttpSequence
- Inherits:
-
Object
- Object
- HttpSequence
- Defined in:
- lib/http_sequence.rb
Instance Method Summary collapse
- #clean_contents!(contents) ⇒ Object
-
#initialize(har_file) ⇒ HttpSequence
constructor
A new instance of HttpSequence.
- #post_params_to_hash(params) ⇒ Object
- #replay ⇒ Object
Constructor Details
#initialize(har_file) ⇒ HttpSequence
Returns a new instance of HttpSequence.
21 22 23 24 25 26 27 |
# File 'lib/http_sequence.rb', line 21 def initialize(har_file) f = File.open(har_file) contents = f.read clean_contents!(contents) @har_contents = JSON.parse(contents) end |
Instance Method Details
#clean_contents!(contents) ⇒ Object
7 8 9 10 |
# File 'lib/http_sequence.rb', line 7 def clean_contents!(contents) contents.gsub!(/\A\xEF\xBB\xBF/, '') contents.force_encoding 'UTF-8' end |
#post_params_to_hash(params) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/http_sequence.rb', line 12 def post_params_to_hash(params) params_hash = {} params.each do|p| params_hash[p['name']] = p['value'] end params_hash end |
#replay ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/http_sequence.rb', line 29 def replay() @har_contents['log']['entries'].each do|entry| request = entry['request'] query_string = request['queryString'] url = request['url'] method = request['method'] client = HTTPClient.new if method == 'GET' client.get url else params = entry['request']['postData']['params'] params = post_params_to_hash params client.post url, params end end end |