Compare commits

...

5 Commits

4 changed files with 135 additions and 36 deletions

View File

@ -1,26 +1,69 @@
Class {
#name : #InstagramUrlTest,
#superclass : #TestCase,
#category : #'Instagram-Tests'
#name : 'InstagramUrlTest',
#superclass : 'TestCase',
#category : 'Instagram-Tests',
#package : 'Instagram-Tests'
}
{ #category : #tests }
{ #category : 'tests' }
InstagramUrlTest >> testCorrectType [
| i |
i := InstagramUrl newURL: 'instagram.com/ruidajo_'.
self assert: i type equals: 'user'.
]
{ #category : 'tests' }
InstagramUrlTest >> testCorrectType2 [
| i |
i := InstagramUrl newURL: 'instagram.com/ruidajo_/'.
self assert: i type equals: 'user'.
]
{ #category : 'tests' }
InstagramUrlTest >> testCorrectType3 [
| i |
i := InstagramUrl newURL: 'instagram.com/'.
self assert: i type equals: 'root'.
]
{ #category : 'tests' }
InstagramUrlTest >> testCorrectType4 [
| i |
i := InstagramUrl newURL: 'instagram.com'.
self assert: i type equals: 'root'.
]
{ #category : 'tests' }
InstagramUrlTest >> testIncorrectTypeSetByUrl [
| i |
i := InstagramUrl new type: 'as'.
self assert: i type equals: 'root'.
]
{ #category : 'tests' }
InstagramUrlTest >> testInstagramUrlInstanceCreation [
| i |
i := InstagramUrl newURL: 'instagram.com'.
self assert: i url asStringOrText equals: 'https://instagram.com/'
]
{ #category : #tests }
{ #category : 'tests' }
InstagramUrlTest >> testNotInstagramUrl1 [
| i |
i := InstagramUrl newURL: 'nstgrm.com'.
self assert: i url asStringOrText equals: 'https://www.instagram.com/'
self assert: i url asStringOrText equals: 'https://instagram.com/'
]
{ #category : #tests }
{ #category : 'tests' }
InstagramUrlTest >> testNotInstagramUrl2 [
| i |
i := InstagramUrl newURL: 'nstgrm.com'.
self assert: i class equals: InstagramUrl new class.
]
{ #category : 'tests' }
InstagramUrlTest >> testUndefindeType [
| i |
i := InstagramUrl newURL: 'instagram.com/ruidajo_/a'.
self assert: i type equals: 'UndefinedType'.
]

View File

@ -1 +1 @@
Package { #name : #'Instagram-Tests' }
Package { #name : 'Instagram-Tests' }

View File

@ -4,63 +4,119 @@ I manage instagram URLs information.
InstagramUrl newURL: 'https://instagram.com/restOfURL'
"
Class {
#name : #InstagramUrl,
#superclass : #Object,
#name : 'InstagramUrl',
#superclass : 'Object',
#instVars : [
'url'
'url',
'type'
],
#category : #Instagram
#category : 'Instagram',
#package : 'Instagram'
}
{ #category : #'instance creation' }
{ #category : 'instance creation' }
InstagramUrl class >> newURL: url [
| instance |
instance := self new.
instance url: (instance urlCheck: url).
instance url: url.
instance setTypeByUrl.
^ instance
]
{ #category : #initialization }
{ #category : 'initialization' }
InstagramUrl >> initialize [
| initial |
initial := 'https://www.instagram.com' asUrl.
super initialize.
self url: initial.
self url.
self type.
]
{ #category : #opening }
{ #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 : #accessing }
{ #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
^ url ifNil: [ url := 'https://instagram.com/' asUrl ]
]
{ #category : #accessing }
InstagramUrl >> url: aURL [
url := aURL
]
{ #category : #testing }
InstagramUrl >> urlCheck: aURL [
{ #category : 'accessing' }
InstagramUrl >> url: anURLString [
| urlCheck |
(aURL includesSubstring: 'instagram.com')
ifFalse: [ UIManager default inform: '" ', aURL, ' " it''s not an instagram URL.'.
^ self url].
urlCheck := aURL asUrl.
(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' ].
^ urlCheck
url := urlCheck
]
{ #category : #accessing }
{ #category : 'accessing - data' }
InstagramUrl >> urlTypes [
"I have the collection of correct types."
^ { 'root' . 'user' }
]
{ #category : 'accessing' }
InstagramUrl >> urlWithoutTracking [
^ self url queryRemoveAll; asStringOrText
]

View File

@ -1 +1 @@
Package { #name : #Instagram }
Package { #name : 'Instagram' }