rails_url_shortener 0.2.9 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb56f22bb9dfb01fa0520b7793659d1561fc152403e6ec83b096a55c0d1caa2c
4
- data.tar.gz: fa519f996fd694af8c1d3a9e8f35bd75d4211036cc2771fe534502d4aee7e991
3
+ metadata.gz: 47080dc11acdaa0241ee52957569c21edbd5601520c0d38ec6af35235f908b93
4
+ data.tar.gz: 269295c42a9401047337940703d692514b93273d933556b8f6672ce06f636d49
5
5
  SHA512:
6
- metadata.gz: 8cc0b73eec14701368de967c3bf20e96cfc9c3fa53342c80d474329b723f27451d7235f7a2ed30d5656540af1eb746bd2148700804ac2d7ab10805568e80165e
7
- data.tar.gz: 2a3cf586ac8ee40b56ae28cae470e66f0214b5037e129013ab99ab56a3bcf418bf973fbb14ddf1ff2eaaa79fe2086f53c61e264e9132485ec71c3a4151313785
6
+ metadata.gz: 64af1ffcb6346cf73b6cbfa5b16df9fc376bfa8c787db032f8207df12ad9bc772ab794d997eb3a2f091ad57dac510d1f0f42a6fae4115a0d553dccc4d73f53a0
7
+ data.tar.gz: b012dfa013e104668245ceca19e4d4834684cf8552a1699e14af8729f1c8b60fbc6ce94c301f0bab61b6570ab17bc2b5f5c763605b1c28dd8101e4a1906fe3e5
data/README.md CHANGED
@@ -1,25 +1,53 @@
1
1
  # RailsUrlShortener
2
2
 
3
- RailsUrlShortener is a small rails engine that provide your app with short URLs functionalities. Like a Bitly on your app. By default, RailsUrlShortener save the visits to your link for future interesting things that you may want to do.
3
+ RailsUrlShortener is a small Rails engine that provides your app with short URL functionality and IP logging capabilities - like having your own Bitly service. By default, RailsUrlShortener saves all visits to your links for future analysis or other interesting uses.
4
4
 
5
- Why give your data to a third party app if you can do it by yourself?
5
+ Why give your data to a third-party app when you can manage it yourself?
6
6
 
7
- You can see a **demo project** of what you can do with this engine [HERE](https://paso-app.herokuapp.com/).
7
+ You can see a **demo project** of what you can do with this engine [HERE](https://paso.fly.dev/).
8
8
 
9
- ## Key features
9
+ ## Key Features
10
10
 
11
- A few of the things you can do with RailsUrlShortener:
11
+ Here are some of the things you can do with RailsUrlShortener:
12
12
 
13
- * Generate unique keys for links.
14
- * Provide a method controller that find, save request information and does a 301 redirect to the original url.
15
- * The short links can be associated with a model in your app.
16
- * Save interesting things like browser, system and ip data of the 'un-shortened' request.
17
- * Temporal short links using the expires_at option.
18
- * Get IP data from third part service.
13
+ * Generate unique keys for links
14
+ * Provide a controller method that finds, saves request information, and performs a 301 redirect to the original URL
15
+ * Associate short links with models in your app
16
+ * Save browser, system, and IP data from each request
17
+ * Create temporary short links using the expires_at option
18
+ * Get IP data from a third-party service
19
+
20
+ ## Installation
21
+
22
+ Follow these steps to install and configure RailsUrlShortener:
23
+
24
+ 1. Add this line to your application's Gemfile:
25
+
26
+ ```ruby
27
+ gem "rails_url_shortener"
28
+ ```
29
+
30
+ 2. Install the gem by running:
31
+
32
+ ```bash
33
+ bundle install
34
+ ```
35
+
36
+ 3. Install and run the migrations:
37
+
38
+ ```bash
39
+ bin/rails rails_url_shortener:install:migrations db:migrate
40
+ ```
41
+
42
+ 4. Generate the initializer for configuration:
43
+
44
+ ```bash
45
+ rails generate rails_url_shortener
46
+ ```
19
47
 
20
48
  ## Usage
21
49
 
22
- ### 1. Mount the engine
50
+ 1. Mount the engine
23
51
 
24
52
  Mount the engine on your app adding the next code on your config/routes.rb:
25
53
 
@@ -29,96 +57,75 @@ Mount the engine on your app adding the next code on your config/routes.rb:
29
57
  mount RailsUrlShortener::Engine, at: "/"
30
58
 
31
59
  ```
32
- ### 2. Generate the short link
60
+
61
+ 2. Generate the short link
33
62
 
34
63
  And generate the short links like you want:
35
64
 
36
- - Using the helper method, this return the ready short link.
65
+ * Using the helper method, this return the ready short link.
37
66
 
38
67
  ```ruby
39
68
  short_url("https://www.github.com/a-chacon/rails-url-shortener")
40
69
  ```
41
70
 
42
- - Or model method, this return the object built. So you can save this on a variable, extract the key and build the short link by your own:
71
+ * Or model method, this return the object built. So you can save this on a variable, extract the key and build the short link by your own:
43
72
 
44
73
  ```ruby
45
74
  RailsUrlShortener::Url.generate("https://www.github.com/a-chacon/rails-url-shortener")
46
75
  ```
47
- ### 3. Share the short link
76
+
77
+ 3. Share the short link
48
78
 
49
79
  **Then share the short link to your users or wherever you want.**
50
80
 
51
81
  ## Deeper
52
82
 
53
83
  Full params for the short_url helper:
84
+
54
85
  ```ruby
55
86
  short_url(url, owner: nil, key: nil, expires_at: nil, category: nil, url_options: {})
56
87
  ```
88
+
57
89
  Where:
58
- * **url**: Long url for short.
59
- * **owner**: Is a model of your app. You can relate an url whatever you want in your app.
60
- * **key**: Is a custom key that you want to set up.
61
- * **expires_at**: Is a datetime for expiration, after this the redirection doesn't work.
62
- * **category**: Tag that you want for that link.
63
- * **url_options**: Options for the url_for generator. Ex: subdomain or protocol.
64
90
 
91
+ * **url**: The long URL to be shortened
92
+ * **owner**: A model from your app to associate with the URL
93
+ * **key**: A custom key for the short URL (optional)
94
+ * **expires_at**: Expiration datetime (after which the redirect won't work)
95
+ * **category**: A tag for categorizing the link
96
+ * **url_options**: Options for the URL generator (e.g., subdomain or protocol)
97
+
98
+ The `generate` model method accepts the same parameters except for `url_options`:
65
99
 
66
- And the same for the generate model method except for url_options:
67
100
  ```ruby
68
101
  RailsUrlShortener::Url.generate(url, owner: nil, key: nil, expires_at: nil, category: nil)
69
102
  ```
70
103
 
71
- ### Data saved
72
-
73
- By default, this engine save all request made on your short url, you can use that data for some analytics or simple IP logger. So for get the data in a controller or do wherever you want, you can use the Visit model related to an Url:
104
+ ### Data Collection
74
105
 
75
- ```ruby
76
- RailsUrlShortener::Url.find_by_key("key").visits # all visits
106
+ By default, the engine saves all requests made to your short URLs. You can use this data for analytics or IP logging. To access the data:
77
107
 
78
- ```
79
- Or using the model class:
80
- ```ruby
81
- RailsUrlShortener::Visit.all # all in database
82
- ```
108
+ 1. Get visits for a specific URL:
83
109
 
84
- And a Visit is related to a Ipgeo model that contain information about the ip, so you can view this using the active record relation:
85
110
  ```ruby
86
- RailsUrlShortener::Visit.first.ipgeo # Ipgeo object that contain information of the ip
111
+ RailsUrlShortener::Url.find_by_key("key").visits
87
112
  ```
88
113
 
89
- ### Ip data
90
-
91
- When a Visit record is created, a job is enqueue for get Ip data from [this](https://ip-api.com/) service and create the Ipgeo record. It is integrated to the free endpoint, so if you think that you have more than 45 different IPS querying in a minute to your app, we need to think in a new solution.
92
-
93
- ## Installation
94
-
95
- Add this line to your application's Gemfile:
114
+ 2. Get all visits:
96
115
 
97
116
  ```ruby
98
- gem "rails_url_shortener"
117
+ RailsUrlShortener::Visit.all
99
118
  ```
100
119
 
101
- Or install it yourself as:
102
- ```bash
103
- gem install rails_url_shortener
104
- ```
105
-
106
- Then execute:
107
- ```bash
108
- bundle
109
- ```
120
+ Each Visit is associated with an Ipgeo model that contains information about the IP address:
110
121
 
111
- And finally install & run the migrations on your project and migrate:
112
- ```bash
113
- bin/rails rails_url_shortener:install:migrations db:migrate
122
+ ```ruby
123
+ RailsUrlShortener::Visit.first.ipgeo
114
124
  ```
115
125
 
116
- For the configurations generate the initializer whith this:
126
+ ### IP Data Collection
117
127
 
118
- ```bash
119
- rails generate RailsUrlShortener:initializer
120
- ```
121
- **Here is important to configure the host at least if your are not running your app in localhost**
128
+ When a Visit record is created, a background job is enqueued to fetch IP data from the [ip-api.com](https://ip-api.com/) service and create an Ipgeo record. This uses the free endpoint, which has a limit of 45 different IPs per minute. If you expect higher traffic, you'll need to implement an alternative solution.
122
129
 
123
130
  ## Contributing
124
131
 
@@ -134,4 +141,7 @@ Don't forget to give the project a star! Thanks again!
134
141
  5. Open a Pull Request
135
142
 
136
143
  ## License
144
+
137
145
  The gem is available as open source under the terms of the [GPL-3.0 License](https://www.github.com/a-chacon/rails-url-shortener/blob/main/LICENSE).
146
+
147
+ by: [a-chacon](https://a-chacon.com)
data/Rakefile CHANGED
@@ -17,10 +17,4 @@ Rake::TestTask.new(:test) do |t|
17
17
  t.test_files = FileList['test/**/*test.rb']
18
18
  end
19
19
 
20
- require 'rubocop/rake_task'
21
-
22
- RuboCop::RakeTask.new do |task|
23
- task.requires << 'rubocop-minitest'
24
- end
25
-
26
- task default: %i[test rubocop]
20
+ task default: %i[test]
@@ -1,5 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # == Schema Information
4
+ #
5
+ # Table name: rails_url_shortener_ipgeos
6
+ #
7
+ # id :integer not null, primary key
8
+ # as :string
9
+ # city :string
10
+ # country :string
11
+ # country_code :string
12
+ # hosting :boolean
13
+ # ip :string
14
+ # isp :string
15
+ # lat :string
16
+ # lon :string
17
+ # mobile :boolean
18
+ # org :string
19
+ # proxy :boolean
20
+ # region :string
21
+ # region_name :string
22
+ # timezone :string
23
+ # created_at :datetime not null
24
+ # updated_at :datetime not null
25
+ #
3
26
  module RailsUrlShortener
4
27
  class Ipgeo < ApplicationRecord
5
28
  has_many :visits, dependent: :nullify
@@ -1,5 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # == Schema Information
4
+ #
5
+ # Table name: rails_url_shortener_urls
6
+ #
7
+ # id :integer not null, primary key
8
+ # category :string
9
+ # expires_at :datetime
10
+ # key :string(10) not null
11
+ # owner_type :string
12
+ # url :text not null
13
+ # created_at :datetime not null
14
+ # updated_at :datetime not null
15
+ # owner_id :integer
16
+ #
17
+ # Indexes
18
+ #
19
+ # index_rails_url_shortener_urls_on_owner (owner_type,owner_id)
20
+ #
3
21
  module RailsUrlShortener
4
22
  class Url < ApplicationRecord
5
23
  # variables
@@ -1,5 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # == Schema Information
4
+ #
5
+ # Table name: rails_url_shortener_visits
6
+ #
7
+ # id :integer not null, primary key
8
+ # bot :boolean
9
+ # browser :string
10
+ # browser_version :string
11
+ # ip :string
12
+ # meta :text
13
+ # platform :string
14
+ # platform_version :string
15
+ # user_agent :string
16
+ # created_at :datetime not null
17
+ # updated_at :datetime not null
18
+ # ipgeo_id :integer
19
+ # url_id :integer
20
+ #
21
+ # Indexes
22
+ #
23
+ # index_rails_url_shortener_visits_on_ipgeo_id (ipgeo_id)
24
+ # index_rails_url_shortener_visits_on_url_id (url_id)
25
+ #
3
26
  module RailsUrlShortener
4
27
  require 'json'
5
28
  class Visit < ApplicationRecord
@@ -10,5 +10,5 @@ RailsUrlShortener.host = ENV['HOST'] || 'localhost:3000' # the host used for the
10
10
  RailsUrlShortener.default_redirect = '/' # where the users are redirect if the link is not found.
11
11
  RailsUrlShortener.charset = CHARSETS[:alphanumcase] # used for generate the keys, better long.
12
12
  RailsUrlShortener.key_length = 6 # Key length for random generator
13
- RailsUrlShortener.minimum_key_length = 3 # minimun permited for a key
13
+ RailsUrlShortener.minimum_key_length = 3 # minimum permited for a key
14
14
  RailsUrlShortener.save_bots_visits = false # if save bots visits
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsUrlShortener
4
- VERSION = '0.2.9'
4
+ VERSION = '0.3.0'
5
5
  end
@@ -3,6 +3,7 @@
3
3
  require 'rails_url_shortener/version'
4
4
  require 'rails_url_shortener/engine'
5
5
  require 'rails_url_shortener/model'
6
+ require_relative '../app/helpers/rails_url_shortener/urls_helper'
6
7
 
7
8
  module RailsUrlShortener
8
9
  ##
@@ -44,3 +45,11 @@ end
44
45
  ActiveSupport.on_load(:active_record) do
45
46
  extend RailsUrlShortener::Model
46
47
  end
48
+
49
+ ActiveSupport.on_load(:action_view) do
50
+ prepend RailsUrlShortener::UrlsHelper
51
+ end
52
+
53
+ ActiveSupport.on_load(:action_controller_base) do
54
+ prepend RailsUrlShortener::UrlsHelper
55
+ end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_url_shortener
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - a-chacon
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-07-12 00:00:00.000000000 Z
10
+ date: 2025-03-16 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: browser
@@ -24,20 +23,6 @@ dependencies:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
25
  version: 5.3.0
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 1.15.0
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: 1.15.0
41
26
  - !ruby/object:Gem::Dependency
42
27
  name: http
43
28
  requirement: !ruby/object:Gem::Requirement
@@ -52,9 +37,10 @@ dependencies:
52
37
  - - ">="
53
38
  - !ruby/object:Gem::Version
54
39
  version: 5.1.0
55
- description: |-
56
- RailsUrlShortener is a simple engine that provide to your rail's app the functionalities for
57
- short URLs. Like bitly.com, but working on your project only.
40
+ description: "RailsUrlShortener is a lightweight Rails engine that enables easy creation
41
+ and management of short URLs within your project. \nSimilar to bitly.com, it condenses
42
+ long links into short, user-friendly addresses. \nEnhance your app's functionality
43
+ with this simple yet powerful URL shortening solution.\n"
58
44
  email:
59
45
  - andres.ch@protonmail.com
60
46
  executables: []
@@ -87,11 +73,10 @@ licenses:
87
73
  - GPL-3.0
88
74
  metadata:
89
75
  bug_tracker_uri: https://www.github.com/a-chacon/rails-url-shortener/issues
90
- changelog_uri: https://www.github.com/a-chacon/rails-url-shortener/releases/tag/v0.2.9
76
+ changelog_uri: https://www.github.com/a-chacon/rails-url-shortener/releases/tag/v0.3.0
91
77
  documentation_uri: https://github.com/a-chacon/rails-url-shortener/blob/main/README.md
92
- source_code_uri: https://github.com/a-chacon/rails-url-shortener/tree/v0.2.9
78
+ source_code_uri: https://github.com/a-chacon/rails-url-shortener/tree/v0.3.0
93
79
  rubygems_mfa_required: 'true'
94
- post_install_message:
95
80
  rdoc_options: []
96
81
  require_paths:
97
82
  - lib
@@ -99,15 +84,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
84
  requirements:
100
85
  - - ">="
101
86
  - !ruby/object:Gem::Version
102
- version: 2.7.0
87
+ version: '3.1'
103
88
  required_rubygems_version: !ruby/object:Gem::Requirement
104
89
  requirements:
105
90
  - - ">="
106
91
  - !ruby/object:Gem::Version
107
92
  version: 1.8.11
108
93
  requirements: []
109
- rubygems_version: 3.4.14
110
- signing_key:
94
+ rubygems_version: 3.6.2
111
95
  specification_version: 4
112
96
  summary: Rails url shortener engine.
113
97
  test_files: []