Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ jobs:
matrix:
ruby:
- '3.3.7'
- '3.4'

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [0.1.3] - 2026-08-19

- Add `Gslide::Presentation::PRESENTATION_ID_PATTERN` and `Gslide::Presentation.file_id_in`, so callers can validate a presentation id without repeating the pattern

## [0.1.2] - 2025-05-09

- Add `Gslide::HTTPError`, `Gslide::UnauthorizedError` and `Gslide::QuotaExceededError` #10
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
gslide (0.1.2)
gslide (0.1.3)

GEM
remote: https://rubygems.org/
Expand Down
11 changes: 9 additions & 2 deletions lib/gslide/models/presentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ class Presentation

attr_reader :id

PRESENTATION_PATTERN = %r[/presentation/d/([a-zA-Z0-9\-_]+)?]
PRESENTATION_ID_PATTERN = /[a-zA-Z0-9\-_]+/
PRESENTATION_PATTERN = %r[/presentation/d/(#{PRESENTATION_ID_PATTERN})?]

# @param [String] id_or_url a presentation id, or a sharing url holding one.
# @return [String] the presentation id, or the argument when it is not a url.
def self.file_id_in(id_or_url)
(url_id = id_or_url.match(PRESENTATION_PATTERN)) ? url_id[1] : id_or_url
end

def initialize(id_or_url, auth: nil)
@id = (url_id = id_or_url.match(PRESENTATION_PATTERN)) ? url_id[1] : id_or_url
@id = self.class.file_id_in(id_or_url)
@auth = auth
end

Expand Down
2 changes: 1 addition & 1 deletion lib/gslide/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Gslide
VERSION = "0.1.2"
VERSION = "0.1.3"
end
17 changes: 17 additions & 0 deletions test/test_gslide.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,21 @@ def test_initialized_with_presentation_id
presentation = Gslide::Presentation.new(presentation_id, auth: nil)
assert_equal "1W11pzmSEH7EoZXiMITa-cOM1y9Ym6Yby9pj_2l5NPm8", presentation.id
end

def test_file_id_in_url
url = "https://docs.google.com/presentation/d/1W11pzmSEH7EoZXiMITa-cOM1y9Ym6Yby9pj_2l5NPm8/edit?usp=sharing"

assert_equal "1W11pzmSEH7EoZXiMITa-cOM1y9Ym6Yby9pj_2l5NPm8", Gslide::Presentation.file_id_in(url)
end

def test_file_id_in_id
presentation_id = "1W11pzmSEH7EoZXiMITa-cOM1y9Ym6Yby9pj_2l5NPm8"

assert_equal presentation_id, Gslide::Presentation.file_id_in(presentation_id)
end

def test_presentation_id_pattern_matches_a_file_id
assert_match(/\A#{Gslide::Presentation::PRESENTATION_ID_PATTERN}\z/, "1W11pzmSEH7EoZ-XiMITa_cOM")
refute_match(/\A#{Gslide::Presentation::PRESENTATION_ID_PATTERN}\z/, "javascript:alert(1)")
end
end