blog_verification 1.0.0 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4e30db2372c43909004ba3957b8b16395fe38612a58d42729d8436b4a352295
4
- data.tar.gz: de9120839b129627959fd1ee8009edf77a18946619819b8b0079b65c1808de61
3
+ metadata.gz: 2a376d19d5eac865a22902230786f73bcfaa674ea207127e6c03a3463119bae3
4
+ data.tar.gz: aac7a61f515d09ba520458ec64de1513e59dca0c577058e506fb00867dad9263
5
5
  SHA512:
6
- metadata.gz: 1e0e7a2a96f8e3cf95d3b299d6081c9105d82389541a2588d38940070eaf03bbbcb683303f8f47c9e2bdfa9e529a80946ccf5b8794e0b46246c1cc0ec05b46e5
7
- data.tar.gz: 251e21438613a10575b486fe5d9c28912d8af49c9d9fe92382d6917b66deca802faa1dac5f0274efb8b8eab9913956ca7dd382231d5563cc8b76835882e17011
6
+ metadata.gz: ed2c5f8c6c941e3b937cc6d24a3081230bcf478d0e84c78970cdf41d0303c8fcb6f8e12c114662d5ef83e345b36d91b47df7e1ffce4703922b6b9a678b7e9c39
7
+ data.tar.gz: a1e53ae7a576cfa8d03d44b5e05a6a84458b00cdff3e979418f4660d69b0a4b6449d822213353350bef5f73ceae5700d602aeaf0e4738465237120780a956a97
data/README.md CHANGED
@@ -6,6 +6,9 @@ Built for **Ruby on Rails** applications and standalone Ruby backends.
6
6
 
7
7
  Supports **Medium** and **DEV Community (`dev.to`)**.
8
8
 
9
+ > [!TIP]
10
+ > **Sample Verification App & Server Included**: A complete verification runner and HTTP API server is available in [`ruby_verification_app/`](./ruby_verification_app) to test and run the gem locally.
11
+
9
12
  ---
10
13
 
11
14
  ## Key Features
@@ -26,6 +29,10 @@ Supports **Medium** and **DEV Community (`dev.to`)**.
26
29
  - **Quarter 4**: January 1 – March 31
27
30
  - Out-of-quarter articles fail with `NOT_IN_CURRENT_QUARTER`.
28
31
  - Supports optional `reference_date` (`YYYY-MM-DD`) for deterministic testing.
32
+ - **Current Month Verification**:
33
+ - Automatically verifies whether the blog was created in the current calendar month (e.g. October 2026).
34
+ - Out-of-month articles fail with `NOT_IN_CURRENT_MONTH`.
35
+ - Supports optional `reference_date` (`YYYY-MM-DD`) for deterministic testing.
29
36
  - **Article Word Count (Length Check)**:
30
37
  - Strips HTML tags and markdown formatting to count body words.
31
38
  - Verifies minimum word count (default: 500 words). Articles under 500 words fail with `INSUFFICIENT_CONTENT_LENGTH`.
@@ -408,6 +415,23 @@ gem 'blog_verification', '~> 1.0'
408
415
 
409
416
  ---
410
417
 
418
+ ## Sample Application & Verification Runner
419
+
420
+ This repository includes a standalone Ruby verification application located in [`ruby_verification_app/`](./ruby_verification_app):
421
+
422
+ - **Automated Verification Suite**: Exercises all 13 core scenarios (valid Medium with JSON-LD, valid DEV.to, author mismatch, date mismatch, quarter checks, word count checks, optional tags, topic derivation, summary comparison, and error handling).
423
+ - **HTTP API Server**: Runs an Express/Node.js-compatible HTTP server on `http://localhost:4567/api/v1/blogs/verify`.
424
+
425
+ To run the sample app:
426
+ ```bash
427
+ cd ruby_verification_app
428
+ bundle install
429
+ ruby app.rb # Runs the 13 verification scenarios
430
+ ruby app.rb --server # Starts the REST API server on port 4567
431
+ ```
432
+
433
+ ---
434
+
411
435
  ## License
412
436
 
413
437
  The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ['thedevankit@gmail.com']
10
10
 
11
11
  spec.summary = 'Lightweight blog verification library for Medium and DEV Community'
12
- spec.description = 'Verifies whether a submitted blog URL belongs to the claimed author, matches publication date and quarter, meets minimum word length, and matches expected topic and summary metadata.'
12
+ spec.description = 'Verifies whether a submitted blog URL belongs to the claimed author, matches publication date, quarter, and month, meets minimum word length, and matches expected topic and summary metadata.'
13
13
  spec.homepage = 'https://github.com/thedevankit/blog_verification'
14
14
  spec.license = 'MIT'
15
15
  spec.required_ruby_version = '>= 2.7.8'
@@ -28,6 +28,7 @@ module BlogVerification
28
28
  AUTHOR_MISMATCH = 'AUTHOR_MISMATCH'
29
29
  PUBLICATION_DATE_MISMATCH = 'PUBLICATION_DATE_MISMATCH'
30
30
  NOT_IN_CURRENT_QUARTER = 'NOT_IN_CURRENT_QUARTER'
31
+ NOT_IN_CURRENT_MONTH = 'NOT_IN_CURRENT_MONTH'
31
32
  TAGS_MISMATCH = 'TAGS_MISMATCH'
32
33
  TOPIC_MISMATCH = 'TOPIC_MISMATCH'
33
34
  SUMMARY_MISMATCH = 'SUMMARY_MISMATCH'
@@ -50,6 +51,7 @@ module BlogVerification
50
51
  AUTHOR_MISMATCH => 'The submitted username does not match the blog author.',
51
52
  PUBLICATION_DATE_MISMATCH => "The submitted publication date does not match the blog's publication date.",
52
53
  NOT_IN_CURRENT_QUARTER => 'The blog publication date is not in the current quarter.',
54
+ NOT_IN_CURRENT_MONTH => 'The blog publication date is not in the current month.',
53
55
  TAGS_MISMATCH => "The submitted tags do not match the blog's tags.",
54
56
  TOPIC_MISMATCH => "The submitted topic does not match the blog's topic.",
55
57
  SUMMARY_MISMATCH => "The submitted summary does not match the blog's description.",
@@ -160,7 +160,54 @@ module BlogVerification
160
160
  }
161
161
  end
162
162
 
163
- # 5. Tags check (FR-06 - Optional)
163
+ # 5. Month verification check
164
+ if published_at_src && !published_at_src.to_s.strip.empty?
165
+ month_result = Utils::DateHelper.date_in_current_month?(published_at_src, req['reference_date'])
166
+ if month_result[:in_current_month]
167
+ checks['month'] = {
168
+ 'status' => CheckStatus::PASSED,
169
+ 'currentMonth' => month_result[:current_month][:label],
170
+ 'blogMonth' => month_result[:blog_month][:label],
171
+ 'message' => "Blog publication date is in the current month (#{month_result[:current_month][:label]})."
172
+ }
173
+ elsif month_result[:blog_month] && month_result[:current_month]
174
+ checks['month'] = {
175
+ 'status' => CheckStatus::FAILED,
176
+ 'currentMonth' => month_result[:current_month][:label],
177
+ 'blogMonth' => month_result[:blog_month][:label],
178
+ 'message' => "Blog publication date is not in the current month. Expected #{month_result[:current_month][:label]}, but blog was published in #{month_result[:blog_month][:label]}."
179
+ }
180
+ errors << {
181
+ 'code' => NOT_IN_CURRENT_MONTH,
182
+ 'field' => 'publishedAt',
183
+ 'message' => "Blog publication date is not in the current month. Expected #{month_result[:current_month][:label]}, but blog was published in #{month_result[:blog_month][:label]}.",
184
+ 'expected' => month_result[:current_month][:label],
185
+ 'actual' => month_result[:blog_month][:label]
186
+ }
187
+ else
188
+ checks['month'] = {
189
+ 'status' => CheckStatus::UNVERIFIED,
190
+ 'message' => 'Month could not be established from source publication date.'
191
+ }
192
+ errors << {
193
+ 'code' => SOURCE_METADATA_UNAVAILABLE,
194
+ 'field' => 'month',
195
+ 'message' => 'Month could not be established from source publication date.'
196
+ }
197
+ end
198
+ else
199
+ checks['month'] = {
200
+ 'status' => CheckStatus::UNVERIFIED,
201
+ 'message' => 'Month could not be verified because source publication date is unavailable.'
202
+ }
203
+ errors << {
204
+ 'code' => SOURCE_METADATA_UNAVAILABLE,
205
+ 'field' => 'month',
206
+ 'message' => 'Month could not be verified because source publication date is unavailable.'
207
+ }
208
+ end
209
+
210
+ # 6. Tags check (FR-06 - Optional)
164
211
  has_supplied_tags = req['tags'].is_a?(Array) && !req['tags'].empty?
165
212
  if !has_supplied_tags
166
213
  checks['tags'] = {
@@ -370,6 +417,7 @@ module BlogVerification
370
417
  'username' => { 'status' => CheckStatus::UNVERIFIED },
371
418
  'publishedAt' => { 'status' => CheckStatus::UNVERIFIED },
372
419
  'quarter' => { 'status' => CheckStatus::UNVERIFIED },
420
+ 'month' => { 'status' => CheckStatus::UNVERIFIED },
373
421
  'tags' => has_supplied_tags ? { 'status' => CheckStatus::UNVERIFIED } : { 'status' => CheckStatus::SKIPPED, 'message' => 'Tag validation was skipped because tags were not provided.' },
374
422
  'topic' => { 'status' => CheckStatus::UNVERIFIED },
375
423
  'summary' => { 'status' => CheckStatus::UNVERIFIED },
@@ -399,6 +447,7 @@ module BlogVerification
399
447
  'username' => { 'status' => CheckStatus::UNVERIFIED },
400
448
  'publishedAt' => { 'status' => CheckStatus::UNVERIFIED },
401
449
  'quarter' => { 'status' => CheckStatus::UNVERIFIED },
450
+ 'month' => { 'status' => CheckStatus::UNVERIFIED },
402
451
  'tags' => has_supplied_tags ? { 'status' => CheckStatus::UNVERIFIED } : { 'status' => CheckStatus::SKIPPED, 'message' => 'Tag validation was skipped because tags were not provided.' },
403
452
  'topic' => { 'status' => CheckStatus::UNVERIFIED },
404
453
  'summary' => { 'status' => CheckStatus::UNVERIFIED },
@@ -76,37 +76,40 @@ module BlogVerification
76
76
  }
77
77
  end
78
78
 
79
- # Returns quarter details for any date or timestamp in UTC
80
- # Schedule:
81
- # - Quarter 1: 1st April to June (months 4, 5, 6)
82
- # - Quarter 2: 1st July to September (months 7, 8, 9)
83
- # - Quarter 3: 1st October to December (months 10, 11, 12)
84
- # - Quarter 4: 1st January to March (months 1, 2, 3)
85
- def get_quarter_info(date_input)
79
+ # Parses any accepted date/time representation into UTC Time object
80
+ def parse_to_utc_time(date_input)
86
81
  return nil if date_input.nil?
87
82
 
88
- parsed_time = nil
89
83
  if date_input.is_a?(Time)
90
- parsed_time = date_input.utc
84
+ date_input.utc
91
85
  elsif date_input.is_a?(Date)
92
- parsed_time = Time.utc(date_input.year, date_input.month, date_input.day)
86
+ Time.utc(date_input.year, date_input.month, date_input.day)
93
87
  elsif date_input.is_a?(String)
94
88
  if valid_calendar_date?(date_input)
95
89
  parts = date_input.split('-').map(&:to_i)
96
- parsed_time = Time.utc(parts[0], parts[1], parts[2])
90
+ Time.utc(parts[0], parts[1], parts[2])
97
91
  else
98
92
  begin
99
- parsed_time = Time.parse(date_input).utc
93
+ Time.parse(date_input).utc
100
94
  rescue ArgumentError
101
- return nil
95
+ nil
102
96
  end
103
97
  end
104
98
  elsif date_input.is_a?(Numeric)
105
99
  sec = date_input < 1e11 ? date_input : (date_input / 1000.0)
106
- parsed_time = Time.at(sec).utc
107
- else
108
- return nil
100
+ Time.at(sec).utc
109
101
  end
102
+ end
103
+
104
+ # Returns quarter details for any date or timestamp in UTC
105
+ # Schedule:
106
+ # - Quarter 1: 1st April to June (months 4, 5, 6)
107
+ # - Quarter 2: 1st July to September (months 7, 8, 9)
108
+ # - Quarter 3: 1st October to December (months 10, 11, 12)
109
+ # - Quarter 4: 1st January to March (months 1, 2, 3)
110
+ def get_quarter_info(date_input)
111
+ parsed_time = parse_to_utc_time(date_input)
112
+ return nil if parsed_time.nil?
110
113
 
111
114
  y = parsed_time.year
112
115
  m = parsed_time.month
@@ -161,6 +164,46 @@ module BlogVerification
161
164
  current_quarter: current_quarter
162
165
  }
163
166
  end
167
+
168
+ # Returns month details for any date or timestamp in UTC
169
+ def get_month_info(date_input)
170
+ parsed_time = parse_to_utc_time(date_input)
171
+ return nil if parsed_time.nil?
172
+
173
+ y = parsed_time.year
174
+ m = parsed_time.month
175
+ m_name = Date::MONTHNAMES[m]
176
+ last_day = days_in_month_for(y, m)
177
+ s_date = format('%04d-%02d-01', y, m)
178
+ e_date = format('%04d-%02d-%02d', y, m, last_day)
179
+
180
+ {
181
+ month_number: m,
182
+ month_name: m_name,
183
+ year: y,
184
+ label: "#{m_name} #{y}",
185
+ start_date: s_date,
186
+ end_date: e_date
187
+ }
188
+ end
189
+
190
+ # Verifies whether blog creation date falls in the current month
191
+ def date_in_current_month?(blog_date, reference_date = nil)
192
+ blog_month = get_month_info(blog_date)
193
+ current_month = get_month_info(reference_date || Time.now.utc)
194
+
195
+ return { in_current_month: false, blog_month: nil, current_month: current_month } if blog_month.nil?
196
+ return { in_current_month: false, blog_month: blog_month, current_month: nil } if current_month.nil?
197
+
198
+ in_current = (blog_month[:month_number] == current_month[:month_number]) &&
199
+ (blog_month[:year] == current_month[:year])
200
+
201
+ {
202
+ in_current_month: in_current,
203
+ blog_month: blog_month,
204
+ current_month: current_month
205
+ }
206
+ end
164
207
  end
165
208
  end
166
209
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BlogVerification
4
- VERSION = '1.0.0'
4
+ VERSION = '1.1.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blog_verification
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ankitkumar Singh (thedevankit)
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-10-29 00:00:00.000000000 Z
11
+ date: 2026-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -87,8 +87,8 @@ dependencies:
87
87
  - !ruby/object:Gem::Version
88
88
  version: '3.18'
89
89
  description: Verifies whether a submitted blog URL belongs to the claimed author,
90
- matches publication date and quarter, meets minimum word length, and matches expected
91
- topic and summary metadata.
90
+ matches publication date, quarter, and month, meets minimum word length, and matches
91
+ expected topic and summary metadata.
92
92
  email:
93
93
  - thedevankit@gmail.com
94
94
  executables: []