url_with_ref 0.0.1

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/url_with_ref.rb +20 -0
  3. metadata +45 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e39e10178b4c8164d4b0725aa57021730868d444
4
+ data.tar.gz: c6c6706e2fb4ee7ec66bea61b897e9da39690513
5
+ SHA512:
6
+ metadata.gz: 4fe743f415be6fbf40076d824e54529aecb250bd965e42af5fb63be7c261cf3cec83df219123cf8c1c1d0e3534936697c40a70621847f675805b310a417bf2ee
7
+ data.tar.gz: 4b2a6d1e17bcccfbca8bdd464522d01c69ad1c017cf530b3624449ace0644bb4b4b4b58fbd90bff3afca4ba141395e25d5d108325f1c1c73e771a640c570c5f0
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+
5
+ class URLWithRef
6
+ def initialize(url, ref)
7
+ @url = url
8
+ @ref = ref
9
+ end
10
+
11
+ def to_s
12
+ uri = URI(@url&.strip).normalize
13
+ params = URI.decode_www_form(uri.query || "")
14
+ params << ["ref", @ref] unless params.any? { |param| param.index "ref" }
15
+ uri.query = URI.encode_www_form(params)
16
+ uri.to_s
17
+ rescue StandardError => e
18
+ @url
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: url_with_ref
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Marc Köhlbrugge
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Appends a ?ref=foobar parameter to URLs. Uses &ref=foobar when there
14
+ already query parameters. Does not override existing any existing ref parameter.
15
+ email: hey@marckohlbrugge.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/url_with_ref.rb
21
+ homepage: http://rubygems.org/gems/url_with_ref
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.6.11
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Easily create ?ref=foobar type tracking URLs
45
+ test_files: []