Socket
Book a DemoInstallSign in
Socket

ducklink

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ducklink

0.0.3
bundlerRubygems
Version published
Maintainers
1
Created
Source

Ducklink is a super-simple way of centrally managing the format of URLs which should be used for links to other sites. Quack.

Why

  • Maybe you have an affiliate deal with a site which requires redirecting through a third-party platform
  • Maybe you need to add parameters to URLs for campaign management
  • Er..
  • Hmm.

How

Given a URL, Ducklink will extract the host and try to match against one of its configured formats.

If nothing matches, the URL is returned untouched. If a match is found, then the URL returned will be based on the format together with any run-time parameters you passed in.

Add parameters

Ducklink::Decorator.configure do
	host 'www.example.com' do
		format '{{url}}?extra=params&added=here'
	end
end

Ducklink.decorate 'http://www.example.com/some/path'
=> http://www.example.com/some/path?extra=params&added=here

Redirects

Ducklink::Decorator.configure do
	host 'www.example.com' do
		format 'http://affiliate.example.com?clickref=42&url={{url}}'
	end
end

Ducklink.decorate 'http://www.example.com/some/path'
=> http://affiliate.example.com?clickref=42&url=http://www.example.com/some/path

If you need to, you can URLEncode the target URL explicitly:

Ducklink::Decorator.configure do
	host 'www.example.com' do
		format 'http://affiliate.example.com?clickref=42&url={{url}}'
		set :url, CGI::escape(self[:url])
	end
end

Ducklink.decorate 'http://www.example.com/some/path'
=> http://affiliate.example.com?clickref=42&url=http%3A%2F%2Fwww.example.com%2Fsome%2Fpath

Run-time parameters

Ducklink::Decorator.configure do
	host 'www.example.com' do |context|
		format 'http://affiliate.example.com?clickref={{reference}}&url={{url}}'
		set :reference, context[:reference]
	end
end

Ducklink.decorate 'http://www.example.com/some/path', :reference => 100
=> http://affiliate.example.com?clickref=100&url=http://www.example.com/some/path

Specify format of groups

Ducklink::Decorator.configure do
	group do
		format 'http://affiliate.example.com?clickref={{reference}}&url={{url}}#campaign={{campaign}}'
		host 'buy.example.com', 'shop.example.com' do |context|
			set :campaign, 'campaign1'
			set :reference, context[:reference]
		end
		host 'another.com' do |context|
			set :campaign, 'campaign2'
			set :reference, context[:reference]
		end
	end
end

Ducklink.decorate 'http://shop.example.com/goodies', :reference => 100
=> http://affiliate.example.com?clickref=100&url=http://shop.example.com/goodies#campaign=campaign1

TODO

  • Tests!
  • URL validity checks
  • Merge parameters if url already has them
  • Intelligently URL encode parameters
  • Support introspection of keys expected in context so calling code knows what to provide

Licence

Ducklink is released under the MIT Licence.

Copyright © 2011 Henry Garner

FAQs

Package last updated on 23 Jul 2011

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.