Module: DynamicLinks
- Defined in:
- lib/dynamic_links/redis_config.rb,
lib/dynamic_links.rb,
lib/dynamic_links/engine.rb,
lib/dynamic_links/logger.rb,
lib/dynamic_links/version.rb,
lib/dynamic_links/shortener.rb,
lib/dynamic_links/validator.rb,
lib/dynamic_links/async/locker.rb,
app/models/dynamic_links/client.rb,
lib/dynamic_links/configuration.rb,
lib/dynamic_links/error_classes.rb,
lib/dynamic_links/strategy_factory.rb,
app/jobs/dynamic_links/application_job.rb,
app/jobs/dynamic_links/shorten_url_job.rb,
app/models/dynamic_links/shortened_url.rb,
app/models/dynamic_links/application_record.rb,
app/helpers/dynamic_links/application_helper.rb,
app/mailers/dynamic_links/application_mailer.rb,
app/jobs/dynamic_links/generate_short_links_job.rb,
app/controllers/dynamic_links/redirects_controller.rb,
app/controllers/dynamic_links/application_controller.rb,
lib/dynamic_links/shortening_strategies/md5_strategy.rb,
lib/dynamic_links/shortening_strategies/base_strategy.rb,
lib/dynamic_links/shortening_strategies/mock_strategy.rb,
lib/dynamic_links/shortening_strategies/crc32_strategy.rb,
app/controllers/dynamic_links/v1/short_links_controller.rb,
lib/dynamic_links/shortening_strategies/sha256_strategy.rb,
lib/dynamic_links/shortening_strategies/nano_id_strategy.rb,
lib/generators/dynamic_links/add_kgs_migration_generator.rb,
lib/dynamic_links/shortening_strategies/redis_counter_strategy.rb
Overview
Table name: dynamic_links_shortened_urls
id :bigint not null, primary key
client_id :bigint
url :string(2083) not null
short_url :string(10) not null
expires_at :datetime
created_at :datetime not null
updated_at :datetime not null
Indexes
index_dynamic_links_shortened_urls_on_client_id (client_id)
index_dynamic_links_shortened_urls_on_short_url (short_url) UNIQUE
Defined Under Namespace
Modules: ApplicationHelper, Async, Generators, ShorteningStrategies
Classes: ApplicationController, ApplicationJob, ApplicationMailer, ApplicationRecord, Client, Configuration, ConfigurationError, Engine, GenerateShortLinksJob, InvalidURIError, Logger, MissingDependency, RedirectsController, RedisConfig, ShortenUrlJob, ShortenedUrl, Shortener, ShorteningFailed, StrategyFactory, Validator
Constant Summary
collapse
- VERSION =
"0.3.0"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.configuration ⇒ Object
44
45
46
|
# File 'lib/dynamic_links.rb', line 44
def configuration
@configuration ||= Configuration.new
end
|
Class Method Details
48
49
50
|
# File 'lib/dynamic_links.rb', line 48
def configure
yield(configuration)
end
|
.find_short_link(long_url, client) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/dynamic_links.rb', line 79
def self.find_short_link(long_url, client)
short_link = DynamicLinks::ShortenedUrl.find_by(url: long_url, client_id: client.id)
if short_link
{
short_url: "#{client.scheme}://#{client.hostname}/#{short_link.short_url}",
full_url: long_url
}
else
nil
end
end
|
.generate_short_url(original_url, client) ⇒ Object
mimic Firebase Dynamic Links API
65
66
67
68
69
70
71
72
73
|
# File 'lib/dynamic_links.rb', line 65
def self.generate_short_url(original_url, client)
short_link = shorten_url(original_url, client)
{
shortLink: short_link,
previewLink: "#{short_link}?preview=true",
warning: []
}
end
|
.resolve_short_url(short_link) ⇒ Object
75
76
77
|
# File 'lib/dynamic_links.rb', line 75
def self.resolve_short_url(short_link)
DynamicLinks::ShortenedUrl.find_by(short_url: short_link)&.url
end
|
.shorten_url(url, client, async: DynamicLinks.configuration.async_processing) ⇒ Object
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/dynamic_links.rb', line 53
def self.shorten_url(url, client, async: DynamicLinks.configuration.async_processing)
raise InvalidURIError, 'Invalid URL' unless Validator.valid_url?(url)
shortener = Shortener.new
if async
shortener.shorten_async(client, url)
else
shortener.shorten(client, url)
end
end
|