From 26a7f763d1eb2b8473b606f445aab9f8aa491a1e Mon Sep 17 00:00:00 2001 From: ruidajo Date: Sun, 26 May 2024 17:42:12 -0500 Subject: [PATCH] Creating type setters an test methods. Modifying url setter-checker. --- Instagram/InstagramUrl.class.st | 59 +++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/Instagram/InstagramUrl.class.st b/Instagram/InstagramUrl.class.st index 180f582..17dc12b 100644 --- a/Instagram/InstagramUrl.class.st +++ b/Instagram/InstagramUrl.class.st @@ -32,17 +32,61 @@ InstagramUrl >> initialize [ ] +{ #category : 'testing' } +InstagramUrl >> isRootUrl [ + + | segments | + self type = 'root' ifFalse: [ + segments := self url segments. + segments ifNotNil: [ segments isEmpty ifFalse: [ ^ segments first = $/ ]]. + ^ true + ]. + ^ true +] + +{ #category : 'testing' } +InstagramUrl >> isUserUrl [ + + | segments | + self type = 'user' ifFalse: [ + segments := self url segments. + segments size = 1 ifFalse: [^ segments second = $/]. + ^ true + ]. + ^ true +] + { #category : 'opening' } InstagramUrl >> openWithoutTracking [ WebBrowser openOn: self urlWithoutTracking ] +{ #category : 'initialization' } +InstagramUrl >> setTypeByUrl [ + + self isRootUrl ifTrue: [ type := 'root'. ^ self ]. + self isUserUrl ifTrue: [ type := 'user'. ^ self ]. + type := 'UndefinedType'. + ^ self +] + { #category : 'accessing' } InstagramUrl >> type [ ^ type ] +{ #category : 'accessing' } +InstagramUrl >> type: aType [ + + (self urlTypes includes: aType) ifTrue: [ + type := aType. + ^ self ]. + UIManager default inform: + '" ' , aType , ' " it''s not a correct type. Setting automatic from url.'. + ^ self setTypeByUrl +] + { #category : 'accessing' } InstagramUrl >> url [ @@ -50,9 +94,18 @@ InstagramUrl >> url [ ] { #category : 'accessing' } -InstagramUrl >> url: aURL [ - - url := aURL +InstagramUrl >> url: anURLString [ + + | urlCheck | + (anURLString includesSubstring: 'instagram.com') + ifFalse: [ UIManager default inform: '" ', anURLString, ' " it''s not an instagram URL.'. + url := self url. + ^ self]. + urlCheck := anURLString asUrl. + urlCheck hasHost ifFalse: [ urlCheck host: urlCheck segments first. + urlCheck removeFirstPathSegment. ]. + urlCheck hasScheme ifFalse: [ urlCheck scheme: 'https' ]. + url := urlCheck ] { #category : 'accessing - data' }