normalize_url 0.0.2 → 0.0.3

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: 540321091211ecaa6d08afffbd12cd43437b648b
4
- data.tar.gz: 61ecab0b4e64c33edfe120666f05f7636fbe51b7
3
+ metadata.gz: 55028bf73f8d7ab29f8b6eed85f5af3645e2b1a5
4
+ data.tar.gz: cc45799207ab2006d5d145441897a621ccc2fc71
5
5
  SHA512:
6
- metadata.gz: f4234b44bc0e43f256885814b39ee38d3a39b37a0953bf14a18c75fb9a0e166789d8877fffdf4e244f8f0686d19276b8aabdf0e77f97c625d5a7bc0c0b77d3e9
7
- data.tar.gz: 4de7be9fb6120d2d7a83aa244e32d88510b7fa03d18e15c0c4e8dfbbfb20fadc539c55de21b645e24557c11c8fcd06f210e333b28814c37db622705cd785cf5e
6
+ metadata.gz: a394f7e5d7f4de0d0dd5b5331efc30de7872aae59e5c695b14e957bf4cf3f5effbf1d451a39894c63b09813db9e4c75e59f954c17ede921910c90986bfd951f7
7
+ data.tar.gz: 16a6d91566ce59953ed3a3ed063ff843320826c45cf5a9a7742172dbf982a02f1756354a5c984fe85ab8b9acc781a968146238441feeaa0e61030cac8809ac8b
data/README.md CHANGED
@@ -10,11 +10,13 @@ resource should look exactly the same.
10
10
  For example:
11
11
 
12
12
  - `http://example.com/products`
13
+ - `HTTP://EXAMPLE.COM/products/`
13
14
  - `http://example.com/products/`
14
15
  - `http://example.com/foo/../products`
15
16
  - `http://example.com/products#comments-section`
16
17
  - `http://example.com//products/`
17
18
  - `http://example.com/products?`
19
+ - `http://example.com/products?utm_source=whatever`
18
20
 
19
21
  will all become `http://example.com/products` after normalization.
20
22
 
@@ -71,6 +73,12 @@ NormalizeUrl.process("http://example.com/foo/", remove_trailing_slash: false) #
71
73
 
72
74
  `http://example.com/foo#bar` -> `http://example.com/foo`
73
75
 
76
+ - Remove tracking. Option `:remove_tracking`.
77
+
78
+ Example:
79
+
80
+ `http://example.com/?utm_source=whatever` -> `http://example.com/`
81
+
74
82
  - Sort query string. Option `:sort_query`.
75
83
 
76
84
  Example:
@@ -15,7 +15,7 @@ module NormalizeUrl
15
15
  awesm
16
16
  xtor
17
17
  PHPSESSID
18
- ].to_set
18
+ ].to_set.freeze
19
19
 
20
20
  def initialize(original_uri, options={})
21
21
  @uri = Addressable::URI.parse(original_uri).normalize
@@ -31,6 +31,7 @@ module NormalizeUrl
31
31
  process :remove_repeating_slashes
32
32
  process :remove_hash
33
33
  process :remove_tracking
34
+ process :remove_params
34
35
  process :sort_query
35
36
  uri.to_s
36
37
  end
@@ -62,9 +63,17 @@ module NormalizeUrl
62
63
  end
63
64
 
64
65
  def process_remove_tracking
66
+ remove_params TRACKING_QUERY_PARAMS
67
+ end
68
+
69
+ def process_remove_params
70
+ remove_params Array(@options.fetch(:remove_params, nil)).map(&:to_s)
71
+ end
72
+
73
+ def remove_params(params)
65
74
  return unless uri.query_values
66
75
  original = uri.query_values
67
- cleaned = original.reject{ |key, _| TRACKING_QUERY_PARAMS.include?(key) }
76
+ cleaned = original.reject{ |key, _| params.include?(key) }
68
77
 
69
78
  if cleaned.empty?
70
79
  uri.query_values = nil
@@ -1,3 +1,3 @@
1
1
  module NormalizeUrl
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: normalize_url
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Pravosud