2024-01-30 17:08:29 +00:00
|
|
|
"
|
|
|
|
I manage instagram URLs information.
|
|
|
|
|
|
|
|
InstagramUrl newURL: 'https://instagram.com/restOfURL'
|
|
|
|
"
|
|
|
|
Class {
|
2024-05-26 18:44:40 +00:00
|
|
|
#name : 'InstagramUrl',
|
|
|
|
#superclass : 'Object',
|
2024-01-30 17:08:29 +00:00
|
|
|
#instVars : [
|
2024-05-26 22:37:09 +00:00
|
|
|
'url',
|
|
|
|
'type'
|
2024-01-30 17:08:29 +00:00
|
|
|
],
|
2024-05-26 18:44:40 +00:00
|
|
|
#category : 'Instagram',
|
|
|
|
#package : 'Instagram'
|
2024-01-30 17:08:29 +00:00
|
|
|
}
|
|
|
|
|
2024-05-26 18:44:40 +00:00
|
|
|
{ #category : 'instance creation' }
|
2024-01-30 17:08:29 +00:00
|
|
|
InstagramUrl class >> newURL: url [
|
2024-01-30 17:50:17 +00:00
|
|
|
| instance |
|
2024-01-30 17:08:29 +00:00
|
|
|
instance := self new.
|
2024-05-26 22:42:46 +00:00
|
|
|
instance url: url.
|
|
|
|
instance setTypeByUrl.
|
2024-01-30 17:08:29 +00:00
|
|
|
^ instance
|
|
|
|
]
|
|
|
|
|
2024-05-26 18:44:40 +00:00
|
|
|
{ #category : 'initialization' }
|
2024-01-30 17:08:29 +00:00
|
|
|
InstagramUrl >> initialize [
|
2024-05-26 22:37:09 +00:00
|
|
|
|
2024-01-30 17:08:29 +00:00
|
|
|
super initialize.
|
2024-05-26 22:37:09 +00:00
|
|
|
self url.
|
|
|
|
self type.
|
2024-01-30 17:08:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
]
|
|
|
|
|
2024-05-26 22:42:12 +00:00
|
|
|
{ #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
|
|
|
|
]
|
|
|
|
|
2024-05-26 18:44:40 +00:00
|
|
|
{ #category : 'opening' }
|
2024-01-30 17:08:29 +00:00
|
|
|
InstagramUrl >> openWithoutTracking [
|
|
|
|
WebBrowser openOn: self urlWithoutTracking
|
|
|
|
]
|
|
|
|
|
2024-05-26 22:42:12 +00:00
|
|
|
{ #category : 'initialization' }
|
|
|
|
InstagramUrl >> setTypeByUrl [
|
|
|
|
|
|
|
|
self isRootUrl ifTrue: [ type := 'root'. ^ self ].
|
|
|
|
self isUserUrl ifTrue: [ type := 'user'. ^ self ].
|
|
|
|
type := 'UndefinedType'.
|
|
|
|
^ self
|
|
|
|
]
|
|
|
|
|
2024-05-26 22:37:09 +00:00
|
|
|
{ #category : 'accessing' }
|
|
|
|
InstagramUrl >> type [
|
|
|
|
|
|
|
|
^ type
|
|
|
|
]
|
|
|
|
|
2024-05-26 22:42:12 +00:00
|
|
|
{ #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
|
|
|
|
]
|
|
|
|
|
2024-05-26 18:44:40 +00:00
|
|
|
{ #category : 'accessing' }
|
2024-01-30 17:08:29 +00:00
|
|
|
InstagramUrl >> url [
|
|
|
|
|
2024-05-26 22:37:09 +00:00
|
|
|
^ url ifNil: [ url := 'https://instagram.com/' asUrl ]
|
2024-01-30 17:08:29 +00:00
|
|
|
]
|
|
|
|
|
2024-05-26 18:44:40 +00:00
|
|
|
{ #category : 'accessing' }
|
2024-05-26 22:42:12 +00:00
|
|
|
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
|
2024-01-30 17:08:29 +00:00
|
|
|
]
|
|
|
|
|
2024-05-26 22:37:09 +00:00
|
|
|
{ #category : 'accessing - data' }
|
|
|
|
InstagramUrl >> urlTypes [
|
|
|
|
"I have the collection of correct types."
|
|
|
|
|
|
|
|
^ { 'root' . 'user' }
|
2024-01-30 17:50:17 +00:00
|
|
|
]
|
|
|
|
|
2024-05-26 18:44:40 +00:00
|
|
|
{ #category : 'accessing' }
|
2024-01-30 17:08:29 +00:00
|
|
|
InstagramUrl >> urlWithoutTracking [
|
|
|
|
^ self url queryRemoveAll; asStringOrText
|
|
|
|
]
|