123 lines
2.4 KiB
Smalltalk
123 lines
2.4 KiB
Smalltalk
"
|
|
I manage instagram URLs information.
|
|
|
|
InstagramUrl newURL: 'https://instagram.com/restOfURL'
|
|
"
|
|
Class {
|
|
#name : 'InstagramUrl',
|
|
#superclass : 'Object',
|
|
#instVars : [
|
|
'url',
|
|
'type'
|
|
],
|
|
#category : 'Instagram',
|
|
#package : 'Instagram'
|
|
}
|
|
|
|
{ #category : 'instance creation' }
|
|
InstagramUrl class >> newURL: url [
|
|
| instance |
|
|
instance := self new.
|
|
instance url: url.
|
|
instance setTypeByUrl.
|
|
^ instance
|
|
]
|
|
|
|
{ #category : 'initialization' }
|
|
InstagramUrl >> initialize [
|
|
|
|
super initialize.
|
|
self url.
|
|
self type.
|
|
|
|
|
|
]
|
|
|
|
{ #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 [
|
|
|
|
^ url ifNil: [ url := 'https://instagram.com/' asUrl ]
|
|
]
|
|
|
|
{ #category : 'accessing' }
|
|
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' }
|
|
InstagramUrl >> urlTypes [
|
|
"I have the collection of correct types."
|
|
|
|
^ { 'root' . 'user' }
|
|
]
|
|
|
|
{ #category : 'accessing' }
|
|
InstagramUrl >> urlWithoutTracking [
|
|
^ self url queryRemoveAll; asStringOrText
|
|
]
|