rails-index-now 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ad4c124b41275b81f3299ce0afd7b1721638e238173b81bcae8df2548f1f2167
4
+ data.tar.gz: db7d4b448d2c646de1a875976ad3c005ca6206796864f4f5990877f4d7529073
5
+ SHA512:
6
+ metadata.gz: 3a9c62210fcb82e0a3bbe815bc81865b4b579c559e31863831bed609ae2da6d8718afcae6469c8ea48aebd528840b6ed61f41b49ec3de9771c2a3bc2eeff8e82
7
+ data.tar.gz: 55932415ba6e8795add3d1f1bed9b47c2ed1953fe9cc39069b7784d65342fd6f0ae3083187a26e46a4f215f2539aeae0910e44385f048d8f96d9541e4542a873
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,29 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
6
+ Style/StringLiterals:
7
+ EnforcedStyle: double_quotes
8
+
9
+ Style/StringLiteralsInInterpolation:
10
+ EnforcedStyle: double_quotes
11
+
12
+ Style/Documentation:
13
+ Enabled: false
14
+
15
+ Metrics/BlockLength:
16
+ Exclude:
17
+ - "spec/**/*"
18
+
19
+ Metrics/MethodLength:
20
+ Max: 15
21
+
22
+ Metrics/AbcSize:
23
+ Max: 20
24
+
25
+ Layout/LineLength:
26
+ Max: 120
27
+
28
+ Naming/PredicateMethod:
29
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-07-26
4
+
5
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Aleksandr Ulanov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Aleks Ulanov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,219 @@
1
+ # Rails IndexNow
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/rails-index-now.svg)](https://badge.fury.io/rb/rails-index-now)
4
+ [![Build Status](https://github.com/aleksdavtian/rails-index-now/workflows/CI/badge.svg)](https://github.com/aleksdavtian/rails-index-now/actions)
5
+
6
+ A modern, lightweight Rails gem for seamless integration with Microsoft's IndexNow protocol. Get your content indexed by search engines instantly, without waiting for crawlers.
7
+
8
+ ## What is IndexNow?
9
+
10
+ [IndexNow](https://www.indexnow.org/) is a revolutionary protocol developed by Microsoft and adopted by major search engines including Bing, Yandex, and others. It allows websites to instantly notify search engines when content is added, updated, or deleted, dramatically reducing the time between content publication and search engine indexing.
11
+
12
+ ### Why IndexNow Matters
13
+
14
+ - **Instant Indexing**: Content appears in search results within minutes instead of days or weeks
15
+ - **Improved SEO**: Fresh content gets discovered and ranked faster
16
+ - **Better User Experience**: Users find your latest content immediately
17
+ - **Reduced Server Load**: No more waiting for search engine crawlers to discover changes
18
+ - **Free**: The IndexNow protocol is completely free to use
19
+
20
+ Traditional search engine indexing relies on crawlers periodically visiting your site. With IndexNow, you proactively tell search engines exactly what has changed, when it changed, making the indexing process nearly instantaneous.
21
+
22
+ ## Installation
23
+
24
+ Add this line to your application's Gemfile:
25
+
26
+ ```ruby
27
+ gem 'rails-index-now'
28
+ ```
29
+
30
+ And then execute:
31
+
32
+ ```bash
33
+ bundle install
34
+ ```
35
+
36
+ Or install it yourself as:
37
+
38
+ ```bash
39
+ gem install rails-index-now
40
+ ```
41
+
42
+ ## Configuration
43
+
44
+ Generate the initializer file:
45
+
46
+ ```bash
47
+ rails generate index_now:install
48
+ ```
49
+
50
+ This creates `config/initializers/index_now.rb`. Configure your IndexNow settings:
51
+
52
+ ```ruby
53
+ Rails::Index::Now.configure do |config|
54
+ # Required: Your IndexNow API key
55
+ # Get one free at https://www.indexnow.org/
56
+ config.api_key = ENV['INDEXNOW_API_KEY']
57
+
58
+ # Optional: Set a specific host for all submissions
59
+ # If not set, the gem will extract the host from submitted URLs
60
+ config.host = "yourdomain.com"
61
+
62
+ # Optional: Disable IndexNow in specific environments
63
+ # Recommended for test and development environments
64
+ config.disabled = Rails.env.test? || Rails.env.development?
65
+
66
+ # Optional: Set a custom logger
67
+ # Defaults to Rails.logger
68
+ config.logger = Rails.logger
69
+ end
70
+ ```
71
+
72
+ ### Getting Your IndexNow API Key
73
+
74
+ 1. Visit [IndexNow.org](https://www.indexnow.org/)
75
+ 2. Generate a free API key
76
+ 3. Add the key to your environment variables or Rails credentials
77
+
78
+ ## Usage
79
+
80
+ ### Basic Usage
81
+
82
+ Submit URLs for immediate indexing:
83
+
84
+ ```ruby
85
+ # Submit a single URL
86
+ Rails::Index::Now.submit("https://yourdomain.com/articles/123")
87
+
88
+ # Submit multiple URLs
89
+ Rails::Index::Now.submit([
90
+ "https://yourdomain.com/articles/123",
91
+ "https://yourdomain.com/articles/124"
92
+ ])
93
+ ```
94
+
95
+ ### Background Processing (Recommended)
96
+
97
+ For production applications, use background jobs to avoid blocking web requests:
98
+
99
+ ```ruby
100
+ # Submit URLs asynchronously using ActiveJob
101
+ Rails::Index::Now.submit_async("https://yourdomain.com/articles/123")
102
+
103
+ Rails::Index::Now.submit_async([
104
+ "https://yourdomain.com/articles/123",
105
+ "https://yourdomain.com/articles/124"
106
+ ])
107
+ ```
108
+
109
+ The gem works seamlessly with any ActiveJob backend (Sidekiq, SolidQueue, GoodJob, etc.).
110
+
111
+ ### Real-World Rails Integration
112
+
113
+ Here's how to integrate IndexNow with your Rails models for automatic indexing:
114
+
115
+ ```ruby
116
+ class Article < ApplicationRecord
117
+ # Submit to IndexNow after creating or updating articles
118
+ after_commit :submit_to_index_now, on: [:create, :update]
119
+
120
+ # Also submit when articles are published
121
+ after_commit :submit_to_index_now, if: :saved_change_to_published_at?
122
+
123
+ private
124
+
125
+ def submit_to_index_now
126
+ return unless published? && Rails.env.production?
127
+
128
+ # Submit asynchronously to avoid blocking the web request
129
+ Rails::Index::Now.submit_async(article_url)
130
+ end
131
+
132
+ def article_url
133
+ Rails.application.routes.url_helpers.article_url(
134
+ self,
135
+ host: Rails.application.config.action_mailer.default_url_options[:host]
136
+ )
137
+ end
138
+ end
139
+ ```
140
+
141
+ ### Advanced Usage
142
+
143
+ For more complex scenarios, you can also use the job directly:
144
+
145
+ ```ruby
146
+ # Use the provided ActiveJob directly
147
+ Rails::Index::Now::SubmitJob.perform_later([
148
+ "https://yourdomain.com/page1",
149
+ "https://yourdomain.com/page2"
150
+ ])
151
+
152
+ # Or perform immediately (not recommended for web requests)
153
+ Rails::Index::Now::SubmitJob.perform_now(["https://yourdomain.com/page"])
154
+ ```
155
+
156
+ ### Error Handling
157
+
158
+ The gem includes comprehensive error handling and logging:
159
+
160
+ ```ruby
161
+ # All operations are logged to Rails.logger by default
162
+ Rails::Index::Now.submit("https://yourdomain.com/page")
163
+ # => [IndexNow] Successfully submitted 1 URLs to IndexNow
164
+
165
+ # Failed submissions are also logged
166
+ Rails::Index::Now.submit("invalid-url")
167
+ # => [IndexNow] IndexNow API returned 400: Bad Request
168
+ ```
169
+
170
+ ## Framework Compatibility
171
+
172
+ This gem is designed specifically for Rails applications and requires:
173
+
174
+ - **Rails 6.0+** (for ActiveJob support)
175
+ - **Ruby 2.7+**
176
+
177
+ The gem automatically integrates with your existing Rails infrastructure:
178
+
179
+ - **ActiveJob**: Works with any ActiveJob backend (Sidekiq, SolidQueue, etc.)
180
+ - **Logging**: Uses Rails.logger by default
181
+ - **Environment Awareness**: Easy to disable in development/test environments
182
+ - **Rails Generators**: Includes installation generator for easy setup
183
+
184
+ ## Performance Considerations
185
+
186
+ - **Asynchronous by Design**: The `submit_async` method queues jobs to avoid blocking web requests
187
+ - **Lightweight**: Zero external dependencies beyond Rails
188
+ - **Efficient**: Batches multiple URLs in single API calls when possible
189
+ - **Fault Tolerant**: Gracefully handles network failures and API errors
190
+
191
+ ## Contributing
192
+
193
+ Bug reports and pull requests are welcome on GitHub at https://github.com/aleksdavtian/rails-index-now.
194
+
195
+ ## Author & Credit
196
+
197
+ This gem was created by **Aleks**. It is proudly used in production at **[DigitalReleaseDates.com](https://digitalreleasedates.com)**, the best place to track when movies and TV shows are available to stream.
198
+
199
+ ## License
200
+
201
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
202
+
203
+ ## Development
204
+
205
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
206
+
207
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
208
+
209
+ ## Contributing
210
+
211
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rails-index-now. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/rails-index-now/blob/master/CODE_OF_CONDUCT.md).
212
+
213
+ ## License
214
+
215
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
216
+
217
+ ## Code of Conduct
218
+
219
+ Everyone interacting in the Rails::Index::Now project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rails-index-now/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "json"
5
+ require "uri"
6
+
7
+ module Rails
8
+ module Index
9
+ module Now
10
+ class Client
11
+ INDEXNOW_API_URL = "https://api.indexnow.org/indexnow"
12
+
13
+ def initialize(config = Rails::Index::Now.configuration)
14
+ @config = config
15
+ end
16
+
17
+ def submit(urls)
18
+ return if @config.disabled?
19
+
20
+ unless @config.valid?
21
+ log_error("IndexNow configuration is invalid. API key is required.")
22
+ return false
23
+ end
24
+
25
+ url_list = Array(urls)
26
+ return if url_list.empty?
27
+
28
+ host = determine_host(url_list.first)
29
+ return nil if host.nil?
30
+
31
+ payload = build_payload(host, url_list)
32
+
33
+ make_request(payload)
34
+ end
35
+
36
+ private
37
+
38
+ def determine_host(sample_url)
39
+ return @config.host if @config.host
40
+
41
+ begin
42
+ URI.parse(sample_url).host
43
+ rescue URI::InvalidURIError => e
44
+ log_error("Invalid URL provided: #{sample_url}. Error: #{e.message}")
45
+ nil
46
+ end
47
+ end
48
+
49
+ def build_payload(host, url_list)
50
+ {
51
+ host: host,
52
+ key: @config.api_key,
53
+ urlList: url_list
54
+ }
55
+ end
56
+
57
+ def make_request(payload)
58
+ response = send_http_request(payload)
59
+ process_response(response, payload[:urlList].size)
60
+ rescue Net::ReadTimeout, Net::OpenTimeout => e
61
+ log_error("Request timeout when submitting to IndexNow: #{e.message}")
62
+ false
63
+ rescue StandardError => e
64
+ log_error("Unexpected error when submitting to IndexNow: #{e.message}")
65
+ false
66
+ end
67
+
68
+ def send_http_request(payload)
69
+ uri = URI(INDEXNOW_API_URL)
70
+ http = create_http_client(uri)
71
+ request = create_post_request(uri, payload)
72
+ http.request(request)
73
+ end
74
+
75
+ def create_http_client(uri)
76
+ http = Net::HTTP.new(uri.host, uri.port)
77
+ http.use_ssl = true
78
+ http
79
+ end
80
+
81
+ def create_post_request(uri, payload)
82
+ request = Net::HTTP::Post.new(uri)
83
+ request["Content-Type"] = "application/json"
84
+ request.body = payload.to_json
85
+ request
86
+ end
87
+
88
+ def process_response(response, url_count)
89
+ if response.code == "200"
90
+ log_info("Successfully submitted #{url_count} URLs to IndexNow")
91
+ true
92
+ else
93
+ log_error("IndexNow API returned #{response.code}: #{response.body}")
94
+ false
95
+ end
96
+ end
97
+
98
+ def log_info(message)
99
+ @config.logger&.info("[IndexNow] #{message}")
100
+ end
101
+
102
+ def log_error(message)
103
+ @config.logger&.error("[IndexNow] #{message}")
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ module Index
5
+ module Now
6
+ class Configuration
7
+ attr_accessor :api_key, :host, :disabled, :logger
8
+
9
+ def initialize
10
+ @api_key = nil
11
+ @host = nil
12
+ @disabled = false
13
+ @logger = default_logger
14
+ end
15
+
16
+ def disabled?
17
+ @disabled
18
+ end
19
+
20
+ def valid?
21
+ !api_key.nil? && !api_key.empty?
22
+ end
23
+
24
+ private
25
+
26
+ def default_logger
27
+ if defined?(::Rails) && ::Rails.respond_to?(:logger) && ::Rails.logger
28
+ ::Rails.logger
29
+ else
30
+ require "logger"
31
+ Logger.new($stdout)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators/base"
4
+
5
+ module Rails
6
+ module Index
7
+ module Now
8
+ module Generators
9
+ class InstallGenerator < ::Rails::Generators::Base
10
+ source_root File.expand_path("templates", __dir__)
11
+
12
+ desc "Creates an IndexNow initializer file"
13
+
14
+ def create_initializer_file
15
+ template "index_now.rb", "config/initializers/index_now.rb"
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ # IndexNow Configuration
4
+ # See https://github.com/your-username/rails-index-now for full documentation
5
+
6
+ Rails::Index::Now.configure do |config|
7
+ # Required: Your IndexNow API key
8
+ # You can get one from https://www.indexnow.org/
9
+ config.api_key = ENV.fetch("INDEXNOW_API_KEY", nil)
10
+
11
+ # Optional: Set a specific host for all submissions
12
+ # If not set, the gem will extract the host from the submitted URLs
13
+ # config.host = "example.com"
14
+
15
+ # Optional: Disable IndexNow in specific environments
16
+ # Recommended for test and development environments
17
+ config.disabled = Rails.env.test? || Rails.env.development?
18
+
19
+ # Optional: Set a custom logger
20
+ # Defaults to Rails.logger if available, otherwise STDOUT
21
+ # config.logger = Rails.logger
22
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/railtie"
4
+
5
+ module Rails
6
+ module Index
7
+ module Now
8
+ class Railtie < ::Rails::Railtie
9
+ generators do
10
+ require_relative "generators/install_generator"
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ module Index
5
+ module Now
6
+ class SubmitJob < ActiveJob::Base
7
+ queue_as :default
8
+
9
+ def perform(urls)
10
+ Client.new.submit(urls)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ module Index
5
+ module Now
6
+ VERSION = "0.1.0"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "now/version"
4
+ require_relative "now/configuration"
5
+ require_relative "now/client"
6
+ require_relative "now/submit_job" if defined?(ActiveJob::Base)
7
+ require_relative "now/railtie" if defined?(Rails::Railtie)
8
+
9
+ module Rails
10
+ module Index
11
+ module Now
12
+ class Error < StandardError; end
13
+
14
+ class << self
15
+ def configure
16
+ yield(configuration)
17
+ end
18
+
19
+ def configuration
20
+ @configuration ||= Configuration.new
21
+ end
22
+
23
+ def reset_configuration!
24
+ @configuration = nil
25
+ end
26
+
27
+ def submit(urls)
28
+ Client.new.submit(urls)
29
+ end
30
+
31
+ def submit_async(urls)
32
+ unless defined?(SubmitJob)
33
+ raise "ActiveJob is not available. Please ensure ActiveJob is loaded before using submit_async."
34
+ end
35
+
36
+ SubmitJob.perform_later(urls)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,8 @@
1
+ module Rails
2
+ module Index
3
+ module Now
4
+ VERSION: String
5
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
6
+ end
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-index-now
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aleks Ulanov
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2025-07-26 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Instantly notify search engines like Bing and DuckDuckGo of content changes
13
+ in your Rails app. This gem provides a simple client and Active Job integration
14
+ for the IndexNow API.
15
+ email:
16
+ - sashachilly.z@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".rspec"
22
+ - ".rubocop.yml"
23
+ - CHANGELOG.md
24
+ - CODE_OF_CONDUCT.md
25
+ - LICENSE
26
+ - LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - lib/rails/index/now.rb
30
+ - lib/rails/index/now/client.rb
31
+ - lib/rails/index/now/configuration.rb
32
+ - lib/rails/index/now/generators/install_generator.rb
33
+ - lib/rails/index/now/generators/templates/index_now.rb
34
+ - lib/rails/index/now/railtie.rb
35
+ - lib/rails/index/now/submit_job.rb
36
+ - lib/rails/index/now/version.rb
37
+ - sig/rails/index/now.rbs
38
+ homepage: https://github.com/ualeks/rails-index-now
39
+ licenses:
40
+ - MIT
41
+ metadata:
42
+ allowed_push_host: https://rubygems.org
43
+ homepage_uri: https://github.com/ualeks/rails-index-now
44
+ source_code_uri: https://github.com/ualeks/rails-index-now
45
+ changelog_uri: https://github.com/ualeks/rails-index-now/blob/main/CHANGELOG.md
46
+ rubygems_mfa_required: 'true'
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.0
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.6.2
62
+ specification_version: 4
63
+ summary: A simple Ruby client for the IndexNow protocol, with easy integration for
64
+ Rails.
65
+ test_files: []