{"id":23317980,"url":"https://github.com/kg8m/tanshuku","last_synced_at":"2025-10-09T02:09:37.984Z","repository":{"id":66947133,"uuid":"603809336","full_name":"kg8m/tanshuku","owner":"kg8m","description":"A Rails engine for shortening URLs","archived":false,"fork":false,"pushed_at":"2025-10-07T17:31:20.000Z","size":1529,"stargazers_count":3,"open_issues_count":14,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-09T02:05:27.314Z","etag":null,"topics":["rails","ruby","url-shortener"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/tanshuku","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kg8m.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"kg8m"}},"created_at":"2023-02-19T16:30:52.000Z","updated_at":"2025-09-27T01:16:25.000Z","dependencies_parsed_at":"2023-05-27T16:00:41.694Z","dependency_job_id":"6659f882-d931-4772-9e10-3bc99fdf481f","html_url":"https://github.com/kg8m/tanshuku","commit_stats":{"total_commits":531,"total_committers":3,"mean_commits":177.0,"dds":"0.40866290018832396","last_synced_commit":"8921c6b58ab3b6b34b99d66decf8c6dbb4ac75ba"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"purl":"pkg:github/kg8m/tanshuku","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kg8m%2Ftanshuku","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kg8m%2Ftanshuku/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kg8m%2Ftanshuku/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kg8m%2Ftanshuku/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kg8m","download_url":"https://codeload.github.com/kg8m/tanshuku/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kg8m%2Ftanshuku/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000773,"owners_count":26082906,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rails","ruby","url-shortener"],"created_at":"2024-12-20T17:14:50.144Z","updated_at":"2025-10-09T02:09:37.967Z","avatar_url":"https://github.com/kg8m.png","language":"Ruby","funding_links":["https://github.com/sponsors/kg8m"],"categories":[],"sub_categories":[],"readme":"[![RubyGems.org](https://img.shields.io/badge/RubyGems.org-Tanshuku-red)](https://rubygems.org/gems/tanshuku)\n[![Ruby 2.5+](https://img.shields.io/badge/Ruby-2.5+-red)](https://www.ruby-lang.org)\n[![Rails 5.1+](https://img.shields.io/badge/Rails-5.1+-red)](https://rubyonrails.org/)\n[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n[![Checks](https://github.com/kg8m/tanshuku/actions/workflows/checks.yml/badge.svg)](https://github.com/kg8m/tanshuku/actions/workflows/checks.yml)\n\n# Tanshuku\n\nTanshuku is a simple and small Rails engine that makes it easier to shorten URLs.\n\n## Key Features\n\n- Generates a unique key for a URL.\n  - The uniqueness is ensured at database level.\n- Creates no additional shortened URL record if the given URL has already been shortened.\n  - You can create an additional record for the same URL with using a different namespace from existing records’.\n  - Checks its existence considering the performance.\n- Provides a Rails controller and action for finding a shortened URL record and redirecting to its original, i.e., non-shortened, URL.\n  - The redirection is done with 301 HTTP status.\n\n## Usage\n\n### 1. Mount `Tanshuku::Engine`\n\nFor example, the following code generates a routing `` GET `/t/:key` to `Tanshuku::UrlsController#show` ``. When your Rails app receives a request to `/t/abcdefghij0123456789`, `Tanshuku::UrlsController#show` will be called and a `Tanshuku::Url` record with a key `abcdefghij0123456789` will be found. Then the request will be redirected to the `Tanshuku::Url` record’s original URL.\n\n```rb\n# config/routes.rb\nRails.application.routes.draw do\n  mount Tanshuku::Engine, at: \"/t\"\nend\n```\n\n**Note**: You can customize the path `/t` as you like.\n\n### 2. Configure Tanshuku (Optional)\n\n**Note**: This step is optional.\n\n**Note**: An initializer file for configuration can be generated by `bin/rails generate tanshuku:install`. See the “[Installation](#installation)” section below for more information.\n\n**Note**: Mutating a `Tanshuku::Configuration` object is thread-**_unsafe_**. It is recommended to use `Tanshuku.configure` for configuration.\n\n#### `config.default_url_options`\n\nTanshuku uses configured `config.default_url_options` when generating shortened URLs.\n\nDefault value is `{}`.\n\nThe following example means that the configured host and protocol are used. Shortened URLs will be like `https://example.com/t/abcdefghij0123456789`.\n\n```rb\n# config/initializers/tanshuku.rb\nTanshuku.configure do |config|\n  config.default_url_options = { host: \"example.com\", protocol: :https }\nend\n```\n\n#### `config.exception_reporter`\n\nIf an exception occurs when shortening a URL, Tanshuku reports it with configured `config.exception_reporter` object.\n\nDefault value is [`Tanshuku::Configuration::DefaultExceptionReporter`](https://kg8m.github.io/tanshuku/Tanshuku/Configuration/DefaultExceptionReporter.html). It logs the exception and the original URL with `Rails.logger.warn`.\n\nValue of `config.exception_reporter` should respond to `#call` with keyword arguments `exception:` and `original_url:`.\n\nThe following example means that an exception and a URL will be reported to [Sentry](https://sentry.io/).\n\n```rb\n# config/initializers/tanshuku.rb\nTanshuku.configure do |config|\n  config.exception_reporter =\n    lambda { |exception:, original_url:|\n      Sentry.capture_exception(exception, tags: { original_url: })\n    }\nend\n```\n\n#### More information\n\ncf. [`Tanshuku::Configuration`’s API documentation](https://kg8m.github.io/tanshuku/Tanshuku/Configuration.html)\n\n### 3. Generate shortened URLs\n\n#### Basic cases\n\nYou can generate a shortened URL with `Tanshuku::Url.shorten`. For example:\n\n```rb\nTanshuku::Url.shorten(\"https://google.com/\")  #=\u003e \"https://example.com/t/abcdefghij0123456789\"\n```\n\n[`config.default_url_options`](https://kg8m.github.io/tanshuku/Tanshuku/Configuration.html#default_url_options-instance_method) is used for the shortened URL.\n\n**Note**: If a `Tanshuku::Url` record for the given URL already exists, no additional record will be created and always the existing record is used.\n\n```rb\n# When no record exists for \"https://google.com/\", a new record will be created.\nTanshuku::Url.shorten(\"https://google.com/\")  #=\u003e \"https://example.com/t/abcde0123456789fghij\"\n\n# When a record already exists for \"https://google.com/\", no additional record will be created.\nTanshuku::Url.shorten(\"https://google.com/\")  #=\u003e \"https://example.com/t/abcde0123456789fghij\"\nTanshuku::Url.shorten(\"https://google.com/\")  #=\u003e \"https://example.com/t/abcde0123456789fghij\"\nTanshuku::Url.shorten(\"https://google.com/\")  #=\u003e \"https://example.com/t/abcde0123456789fghij\"\n```\n\n#### Shortening a URL with ad hoc URL options\n\nYou can specify URL options to `Tanshuku::Url.shorten`. For example:\n\n```rb\nTanshuku::Url.shorten(\"https://google.com/\", url_options: { host: \"verycool.example.com\" })\n#=\u003e \"https://verycool.example.com/t/0123456789abcdefghij\"\n\nTanshuku::Url.shorten(\"https://google.com/\", url_options: { protocol: :http })\n#=\u003e \"http://example.com/t/abcde01234fghij56789\"\n```\n\n#### Shortening a URL with a namespace\n\nYou can create additional records for the same URL with specifying a namespace.\n\n```rb\n# When no record exists for “https://google.com/”, a new record will be created.\nTanshuku::Url.shorten(\"https://google.com/\")  #=\u003e \"https://example.com/t/abc012def345ghi678j9\"\n\n# Even when a record already exists for “https://google.com/”, an additional record will be created if namespace is\n# specified.\nTanshuku::Url.shorten(\"https://google.com/\", namespace: \"a\")  #=\u003e \"https://example.com/t/ab01cd23ef45gh67ij89\"\nTanshuku::Url.shorten(\"https://google.com/\", namespace: \"b\")  #=\u003e \"https://example.com/t/a0b1c2d3e4f5g6h7i8j9\"\nTanshuku::Url.shorten(\"https://google.com/\", namespace: \"c\")  #=\u003e \"https://example.com/t/abcd0123efgh4567ij89\"\n\n# When the same URL and the same namespace is specified, no additional record will be created.\nTanshuku::Url.shorten(\"https://google.com/\", namespace: \"a\")  #=\u003e \"https://example.com/t/ab01cd23ef45gh67ij89\"\nTanshuku::Url.shorten(\"https://google.com/\", namespace: \"a\")  #=\u003e \"https://example.com/t/ab01cd23ef45gh67ij89\"\n```\n\n#### More information\n\ncf. [`Tanshuku::Url.shorten`’s API documentation](https://kg8m.github.io/tanshuku/Tanshuku/Url.html#shorten-class_method)\n\n### 4. Share the shortened URLs\n\nYou can share the shortened URLs, e.g., `https://example.com/t/abcdefghij0123456789`.\n\nWhen a user clicks a link with a shortened URL, your Rails app redirects the user to its original URL.\n\n## Installation\n\n### 1. Enable Tanshuku\n\nAdd `gem \"tanshuku\"` to your application’s `Gemfile`.\n\n```rb\n# Gemfile\ngem \"tanshuku\"\n```\n\n### 2. Generate setup files\n\nExecute a shell command as following:\n\n```sh\nbin/rails generate tanshuku:install\n```\n\n### 3. Apply generated migration files\n\nExecute a shell command as following:\n\n```sh\nbin/rails db:migrate\n```\n\n## Q\u0026amp;A\n\n### Q. What does “tanshuku” mean?\n\nA. “Tanshuku” is a Japanese word “短縮.” It means “shortening.” And “短縮URL” in Japanese means “shortened URL” in English.\n\n### Q. \\*\\* (anything you want) isn’t implemented?\n\nA. Does Tanshuku have some missing features? Please [create an issue](https://github.com/kg8m/tanshuku/issues/new).\n\n## How to develop\n\n1. Fork this repository\n1. `git clone` your fork\n1. `bundle install` and `rake steep:prepare`\n1. Update sources\n1. `rake`\n1. Fix `rake` errors if `rake` fails\n1. Create a pull request\n\n## How to release\n\n1. Make your repository fresh\n1. `bump current` and confirm the current version\n1. `bump patch`, `bump minor`, or `bump major`\n1. `rake release`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkg8m%2Ftanshuku","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkg8m%2Ftanshuku","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkg8m%2Ftanshuku/lists"}