Module: MixpanelTest::Parser::InstanceMethods
- Included in:
- MixpanelTest::Parser, Service
- Defined in:
- lib/mixpanel_test/parser.rb
Instance Method Summary collapse
- #decode_cookie(cookie) ⇒ Object
-
#decode_data(encoded_data) ⇒ Object
Decode the data string.
-
#parse_query_params(qs) ⇒ Object
Extract the query parameters as a hash from the query string.
Instance Method Details
#decode_cookie(cookie) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/mixpanel_test/parser.rb', line 30 def () #begin # split cookie and find a mixpanel section section = .split('; ').find do |tok| tok.match(/^mp_/) end; # Decode and find json data = URI.unescape(section).match(/\{.*\}/)[0] # Parse as JSON JSON.parse(data) #rescue # raise BadCookieError, but first, figure out how to test this functionality #end end |
#decode_data(encoded_data) ⇒ Object
Decode the data string.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mixpanel_test/parser.rb', line 17 def decode_data(encoded_data) # Decode the data data = Base64.decode64(encoded_data) # Eliminate extemporaneous chars outside the JSON data = data.match(/\{.*\}/)[0] # Parse with JSON data = JSON.parse(data) end |
#parse_query_params(qs) ⇒ Object
Extract the query parameters as a hash from the query string
12 13 14 |
# File 'lib/mixpanel_test/parser.rb', line 12 def parse_query_params(qs) qs.to_s.split('&').map do |s| s.split('=') end.map do |a| {URI.unescape(a[0]) => URI.unescape(a[1])} end.inject(&:merge) || {} end |