Compare commits

..

No commits in common. "ac3f3757d80e6f29712a449ace229c201c884243" and "f80fe4fbc152fb17000d4ad0342303b694e35139" have entirely different histories.

4 changed files with 36 additions and 135 deletions

View File

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

View File

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