Class: Sendly::LinksResource
- Inherits:
-
Object
- Object
- Sendly::LinksResource
- Defined in:
- lib/sendly/links_resource.rb
Overview
Links resource — branded URL shortening.
Mint branded short links for a destination URL, list the links your workspace has created (with click analytics), and enable or disable an individual link (a per-link kill switch).
Branded, owned-domain short links improve deliverability — carriers filter public shorteners — and give you click data.
NOTE: URL shortening is not yet generally available. It is gated behind the
url_shortener rollout flag (currently founder-only); for API-key clients a
flag-off account reads as a 404 NotFoundError (the feature is
absent) until the flag is on for your account.
Instance Method Summary collapse
-
#create(url:) ⇒ Sendly::ShortLink
Mint a branded short link for a destination URL.
-
#disable(code) ⇒ Sendly::ShortLinkStatus
Disable a short link (its redirect returns 404 until re-enabled).
-
#enable(code) ⇒ Sendly::ShortLinkStatus
Re-enable a previously disabled short link.
-
#initialize(client) ⇒ LinksResource
constructor
A new instance of LinksResource.
-
#list(limit: nil, offset: nil) ⇒ Sendly::ShortLinkList
List the short links your workspace has created, newest first, with click counts and a 14-day daily click histogram.
-
#update(code, disabled:) ⇒ Sendly::ShortLinkStatus
Enable or disable a short link.
Constructor Details
#initialize(client) ⇒ LinksResource
Returns a new instance of LinksResource.
162 163 164 |
# File 'lib/sendly/links_resource.rb', line 162 def initialize(client) @client = client end |
Instance Method Details
#create(url:) ⇒ Sendly::ShortLink
Mint a branded short link for a destination URL. Uses your workspace's brand slug when one is configured.
173 174 175 176 177 178 |
# File 'lib/sendly/links_resource.rb', line 173 def create(url:) validate_url!(url) response = @client.post("/links", { url: url }) ShortLink.new(response) end |
#disable(code) ⇒ Sendly::ShortLinkStatus
Disable a short link (its redirect returns 404 until re-enabled). Convenience wrapper over #update.
216 217 218 |
# File 'lib/sendly/links_resource.rb', line 216 def disable(code) update(code, disabled: true) end |
#enable(code) ⇒ Sendly::ShortLinkStatus
Re-enable a previously disabled short link. Convenience wrapper over #update.
225 226 227 |
# File 'lib/sendly/links_resource.rb', line 225 def enable(code) update(code, disabled: false) end |
#list(limit: nil, offset: nil) ⇒ Sendly::ShortLinkList
List the short links your workspace has created, newest first, with click counts and a 14-day daily click histogram.
186 187 188 189 190 191 192 193 |
# File 'lib/sendly/links_resource.rb', line 186 def list(limit: nil, offset: nil) params = {} params[:limit] = limit if limit params[:offset] = offset if offset response = @client.get("/links", params) ShortLinkList.new(response) end |
#update(code, disabled:) ⇒ Sendly::ShortLinkStatus
Enable or disable a short link. A disabled link's redirect returns 404 until it is re-enabled.
203 204 205 206 207 208 209 |
# File 'lib/sendly/links_resource.rb', line 203 def update(code, disabled:) raise ValidationError, "Link code is required" if code.nil? || code.to_s.empty? encoded_code = URI.encode_www_form_component(code) response = @client.patch("/links/#{encoded_code}", { disabled: disabled }) ShortLinkStatus.new(response) end |