From fec33729f171da0a1887925ee71b8337d5c8f2ca Mon Sep 17 00:00:00 2001 From: ruidajo Date: Tue, 30 Jan 2024 12:08:29 -0500 Subject: [PATCH] Creating management for instagram urls. --- .project | 3 ++ .properties | 3 ++ Instagram-Tests/InstagramUrlTest.class.st | 26 ++++++++++ Instagram-Tests/package.st | 1 + Instagram/InstagramUrl.class.st | 60 +++++++++++++++++++++++ Instagram/package.st | 1 + 6 files changed, 94 insertions(+) create mode 100644 .project create mode 100644 .properties create mode 100644 Instagram-Tests/InstagramUrlTest.class.st create mode 100644 Instagram-Tests/package.st create mode 100644 Instagram/InstagramUrl.class.st create mode 100644 Instagram/package.st diff --git a/.project b/.project new file mode 100644 index 0000000..5e7754f --- /dev/null +++ b/.project @@ -0,0 +1,3 @@ +{ + 'srcDirectory' : '' +} \ No newline at end of file diff --git a/.properties b/.properties new file mode 100644 index 0000000..ad0471d --- /dev/null +++ b/.properties @@ -0,0 +1,3 @@ +{ + #format : #tonel +} \ No newline at end of file diff --git a/Instagram-Tests/InstagramUrlTest.class.st b/Instagram-Tests/InstagramUrlTest.class.st new file mode 100644 index 0000000..29a7f0d --- /dev/null +++ b/Instagram-Tests/InstagramUrlTest.class.st @@ -0,0 +1,26 @@ +Class { + #name : #InstagramUrlTest, + #superclass : #TestCase, + #category : #'Instagram-Tests' +} + +{ #category : #tests } +InstagramUrlTest >> testInstagramUrlInstanceCreation [ + | i | + i := InstagramUrl newURL: 'instagram.com'. + self assert: i url asStringOrText equals: 'https://instagram.com/' +] + +{ #category : #tests } +InstagramUrlTest >> testNotInstagramUrl1 [ + | i | + i := InstagramUrl newURL: 'nstgrm.com'. + self assert: i url asStringOrText equals: 'https://www.instagram.com/' +] + +{ #category : #tests } +InstagramUrlTest >> testNotInstagramUrl2 [ + | i | + i := InstagramUrl newURL: 'nstgrm.com'. + self assert: i class equals: InstagramUrl new class. +] diff --git a/Instagram-Tests/package.st b/Instagram-Tests/package.st new file mode 100644 index 0000000..3d65490 --- /dev/null +++ b/Instagram-Tests/package.st @@ -0,0 +1 @@ +Package { #name : #'Instagram-Tests' } diff --git a/Instagram/InstagramUrl.class.st b/Instagram/InstagramUrl.class.st new file mode 100644 index 0000000..26ca0f6 --- /dev/null +++ b/Instagram/InstagramUrl.class.st @@ -0,0 +1,60 @@ +" +I manage instagram URLs information. + +InstagramUrl newURL: 'https://instagram.com/restOfURL' +" +Class { + #name : #InstagramUrl, + #superclass : #Object, + #instVars : [ + 'url' + ], + #category : #Instagram +} + +{ #category : #'instance creation' } +InstagramUrl class >> newURL: url [ + | instance urlCheck | + instance := self new. + (url includesSubstring: 'instagram.com') + ifFalse: [ UIManager default inform: '" ', url, ' " it''s not an instagram URL.'. + ^ self new ]. + urlCheck := url asUrl. + urlCheck hasHost ifFalse: [ urlCheck host: urlCheck segments first. + urlCheck removeFirstPathSegment. ]. + urlCheck hasScheme ifFalse: [ urlCheck scheme: 'https' ]. + instance url: urlCheck . + ^ instance +] + +{ #category : #initialization } +InstagramUrl >> initialize [ + | initial | + initial := 'https://www.instagram.com' asUrl. + super initialize. + self url: initial. + + +] + +{ #category : #opening } +InstagramUrl >> openWithoutTracking [ + WebBrowser openOn: self urlWithoutTracking +] + +{ #category : #accessing } +InstagramUrl >> url [ + + ^ url +] + +{ #category : #accessing } +InstagramUrl >> url: aURL [ + + url := aURL +] + +{ #category : #accessing } +InstagramUrl >> urlWithoutTracking [ + ^ self url queryRemoveAll; asStringOrText +] diff --git a/Instagram/package.st b/Instagram/package.st new file mode 100644 index 0000000..898c19b --- /dev/null +++ b/Instagram/package.st @@ -0,0 +1 @@ +Package { #name : #Instagram }