Refactoring URL checking.

This commit is contained in:
ruidajo 2024-01-30 12:50:17 -05:00
parent fec33729f1
commit f80fe4fbc1
1 changed files with 15 additions and 9 deletions

View File

@ -14,16 +14,9 @@ Class {
{ #category : #'instance creation' } { #category : #'instance creation' }
InstagramUrl class >> newURL: url [ InstagramUrl class >> newURL: url [
| instance urlCheck | | instance |
instance := self new. instance := self new.
(url includesSubstring: 'instagram.com') instance url: (instance urlCheck: url).
ifFalse: [ UIManager default inform: '" ', url, ' " it''s not an instagram URL.'.
^ self new ].
urlCheck := url asUrl.
urlCheck hasHost ifFalse: [ urlCheck host: urlCheck segments first.
urlCheck removeFirstPathSegment. ].
urlCheck hasScheme ifFalse: [ urlCheck scheme: 'https' ].
instance url: urlCheck .
^ instance ^ instance
] ]
@ -54,6 +47,19 @@ InstagramUrl >> url: aURL [
url := aURL url := aURL
] ]
{ #category : #testing }
InstagramUrl >> urlCheck: aURL [
| urlCheck |
(aURL includesSubstring: 'instagram.com')
ifFalse: [ UIManager default inform: '" ', aURL, ' " it''s not an instagram URL.'.
^ self url].
urlCheck := aURL asUrl.
urlCheck hasHost ifFalse: [ urlCheck host: urlCheck segments first.
urlCheck removeFirstPathSegment. ].
urlCheck hasScheme ifFalse: [ urlCheck scheme: 'https' ].
^ urlCheck
]
{ #category : #accessing } { #category : #accessing }
InstagramUrl >> urlWithoutTracking [ InstagramUrl >> urlWithoutTracking [
^ self url queryRemoveAll; asStringOrText ^ self url queryRemoveAll; asStringOrText