rails_url_shortener 0.2.10 → 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: d2eae8996ec1ecb9a6edf015f801174ba561d47a67f5898f516d8c37d4c10118
4
- data.tar.gz: 4070d28713ebdf08bf96068f4a10c1ee2369c77568a8fb0a11ea8b206e1f0521
3
+ metadata.gz: 47080dc11acdaa0241ee52957569c21edbd5601520c0d38ec6af35235f908b93
4
+ data.tar.gz: 269295c42a9401047337940703d692514b93273d933556b8f6672ce06f636d49
5
5
  SHA512:
6
- metadata.gz: b1d74a3df31a9b3a1eaa9eba0d2387ca1b2d572f40147ae12321172a093e998af28e63bdf8b8a6ab10416843a0c7e3a2574abe37ba5603b5086d0b8e5214eb8c
7
- data.tar.gz: ccb01b9e625ee0f2a3a38992a978cade1e05b0fc8e0144e12e93e1a3c95ff59c7683d2cd20d66c3238e5a88d90432377b880c9bbf8ee6f31b69a8ebad0be791d
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://s.a-chacon.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,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsUrlShortener
4
- VERSION = '0.2.10'
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
  ##
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.10
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-31 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,10 +37,10 @@ dependencies:
52
37
  - - ">="
53
38
  - !ruby/object:Gem::Version
54
39
  version: 5.1.0
55
- description: RailsUrlShortener is a lightweight Rails engine that enables easy creation
56
- and management of short URLs within your project. Similar to bitly.com, it condenses
57
- long links into short, user-friendly addresses. Enhance your app's functionality
58
- with this simple yet powerful URL shortening solution.
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"
59
44
  email:
60
45
  - andres.ch@protonmail.com
61
46
  executables: []
@@ -83,17 +68,15 @@ files:
83
68
  - lib/rails_url_shortener/engine.rb
84
69
  - lib/rails_url_shortener/model.rb
85
70
  - lib/rails_url_shortener/version.rb
86
- - lib/tasks/auto_annotate_models.rake
87
71
  homepage: https://www.github.com/a-chacon/rails-url-shortener
88
72
  licenses:
89
73
  - GPL-3.0
90
74
  metadata:
91
75
  bug_tracker_uri: https://www.github.com/a-chacon/rails-url-shortener/issues
92
- changelog_uri: https://www.github.com/a-chacon/rails-url-shortener/releases/tag/v0.2.10
76
+ changelog_uri: https://www.github.com/a-chacon/rails-url-shortener/releases/tag/v0.3.0
93
77
  documentation_uri: https://github.com/a-chacon/rails-url-shortener/blob/main/README.md
94
- source_code_uri: https://github.com/a-chacon/rails-url-shortener/tree/v0.2.10
78
+ source_code_uri: https://github.com/a-chacon/rails-url-shortener/tree/v0.3.0
95
79
  rubygems_mfa_required: 'true'
96
- post_install_message:
97
80
  rdoc_options: []
98
81
  require_paths:
99
82
  - lib
@@ -101,15 +84,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
84
  requirements:
102
85
  - - ">="
103
86
  - !ruby/object:Gem::Version
104
- version: 2.7.0
87
+ version: '3.1'
105
88
  required_rubygems_version: !ruby/object:Gem::Requirement
106
89
  requirements:
107
90
  - - ">="
108
91
  - !ruby/object:Gem::Version
109
92
  version: 1.8.11
110
93
  requirements: []
111
- rubygems_version: 3.4.16
112
- signing_key:
94
+ rubygems_version: 3.6.2
113
95
  specification_version: 4
114
96
  summary: Rails url shortener engine.
115
97
  test_files: []
@@ -1,59 +0,0 @@
1
- # NOTE: only doing this in development as some production environments (Heroku)
2
- # NOTE: are sensitive to local FS writes, and besides -- it's just not proper
3
- # NOTE: to have a dev-mode tool do its thing in production.
4
- if Rails.env.development?
5
- require 'annotate'
6
- task :set_annotation_options do
7
- # You can override any of these by setting an environment variable of the
8
- # same name.
9
- Annotate.set_defaults(
10
- 'active_admin' => 'false',
11
- 'additional_file_patterns' => [],
12
- 'routes' => 'false',
13
- 'models' => 'true',
14
- 'position_in_routes' => 'before',
15
- 'position_in_class' => 'before',
16
- 'position_in_test' => 'before',
17
- 'position_in_fixture' => 'before',
18
- 'position_in_factory' => 'before',
19
- 'position_in_serializer' => 'before',
20
- 'show_foreign_keys' => 'true',
21
- 'show_complete_foreign_keys' => 'false',
22
- 'show_indexes' => 'true',
23
- 'simple_indexes' => 'false',
24
- 'model_dir' => 'app/models',
25
- 'root_dir' => '',
26
- 'include_version' => 'false',
27
- 'require' => '',
28
- 'exclude_tests' => 'false',
29
- 'exclude_fixtures' => 'false',
30
- 'exclude_factories' => 'false',
31
- 'exclude_serializers' => 'false',
32
- 'exclude_scaffolds' => 'true',
33
- 'exclude_controllers' => 'true',
34
- 'exclude_helpers' => 'true',
35
- 'exclude_sti_subclasses' => 'false',
36
- 'ignore_model_sub_dir' => 'false',
37
- 'ignore_columns' => nil,
38
- 'ignore_routes' => nil,
39
- 'ignore_unknown_models' => 'false',
40
- 'hide_limit_column_types' => 'integer,bigint,boolean',
41
- 'hide_default_column_types' => 'json,jsonb,hstore',
42
- 'skip_on_db_migrate' => 'false',
43
- 'format_bare' => 'true',
44
- 'format_rdoc' => 'false',
45
- 'format_yard' => 'false',
46
- 'format_markdown' => 'false',
47
- 'sort' => 'false',
48
- 'force' => 'false',
49
- 'frozen' => 'false',
50
- 'classified_sort' => 'true',
51
- 'trace' => 'false',
52
- 'wrapper_open' => nil,
53
- 'wrapper_close' => nil,
54
- 'with_comment' => 'true'
55
- )
56
- end
57
-
58
- Annotate.load_tasks
59
- end