Skip to content

Commit

Permalink
refacotring und so dinge hier, ich weiß schon nicht mehr wo ich übera…
Browse files Browse the repository at this point in the history
…ll war
  • Loading branch information
Vincent Eichhorn committed Jul 8, 2024
1 parent 0332766 commit 5178b15
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 120 deletions.
26 changes: 22 additions & 4 deletions src/SpotifyConnect/SPOCApiEndpoint.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ SPOCApiEndpoint class >> apiHost [
^ 'https://api.spotify.com/'
]

{
#category : #constants,
#'squeak_changestamp' : 'VE 7/8/2024 16:21'
}
SPOCApiEndpoint class >> cannotRefreshErrorMessage [

^ 'Refreshing Access Token failed'
]

{
#category : #constants,
#'squeak_changestamp' : 'OW 7/7/2024 16:28'
Expand All @@ -39,6 +48,15 @@ SPOCApiEndpoint class >> mockdataBasepath [
^ 'assets/mockdata/'
]

{
#category : #constants,
#'squeak_changestamp' : 'VE 7/8/2024 16:20'
}
SPOCApiEndpoint class >> noAuthorizerErrorMessage [

^ 'Authorizer needed'
]

{
#category : #accessing,
#'squeak_changestamp' : 'TL 6/10/2024 03:37'
Expand Down Expand Up @@ -86,15 +104,15 @@ SPOCApiEndpoint >> endpointMethod [

{
#category : #'api-call',
#'squeak_changestamp' : 'TL 7/7/2024 02:41'
#'squeak_changestamp' : 'VE 7/8/2024 16:21'
}
SPOCApiEndpoint >> execute: aParamDictionary [

| response contentStream |
self returnsTestContent
ifTrue: [^ self tinkerReponseContent: self executeTest].
self authorizer
ifNil: [^ SPOCApiEndpointResult new error: 'Authorizer needed'].
ifNil: [^ SPOCApiEndpointResult new error: self class noAuthorizerErrorMessage].
response := self executeRequest: self tinkerRequest withParams: aParamDictionary.
response code = 401
ifTrue: [^ self refreshAccessTokenAndExecute: aParamDictionary].
Expand Down Expand Up @@ -146,14 +164,14 @@ SPOCApiEndpoint >> loadMockdataFromAsset: anAsset [

{
#category : #'api-call',
#'squeak_changestamp' : 'TL 7/7/2024 02:45'
#'squeak_changestamp' : 'VE 7/8/2024 16:21'
}
SPOCApiEndpoint >> refreshAccessTokenAndExecute: aParamDictionary [

self authorizer refreshAccessToken.
self authorizer isAuthorized
ifTrue: [^ self execute: aParamDictionary]
ifFalse: [^ SPOCApiEndpointResult new error: 'Access Token Refresh Failed']
ifFalse: [^ SPOCApiEndpointResult new error: self class cannotRefreshErrorMessage]
]

{
Expand Down
41 changes: 23 additions & 18 deletions src/SpotifyConnect/SPOCApiSearch.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ Class {
#'squeak_changestamp' : 'OW 7/4/2024 12:00'
}

{
#category : #response,
#'squeak_changestamp' : 'VE 7/8/2024 16:44'
}
SPOCApiSearch >> contentItemsAt: aSymbol in: aJsonContent [

(aJsonContent includesKey: aSymbol)
ifTrue: [^ (aJsonContent at: aSymbol) at: #items].
^ OrderedCollection new


]

{
#category : #parameters,
#'squeak_changestamp' : 'RK 5/16/2024 19:01'
Expand Down Expand Up @@ -57,27 +70,19 @@ SPOCApiSearch >> search: aString withFilter: aFilter [

{
#category : #response,
#'squeak_changestamp' : 'RK 7/7/2024 13:53'
#'squeak_changestamp' : 'VE 7/8/2024 16:43'
}
SPOCApiSearch >> tinkerReponseContent: aContentStream [

| content results index |
| content results |
content := Json readFrom: aContentStream readStream.
results := OrderedCollection new.
index := 0.
(content includesKey: #tracks)
ifTrue: [((content at: #tracks) at: #items)
do: [:aTrack | results add: ((self tinkerTrack: aTrack) offset: index + 1).
index := index + 1].
^ results].
(content includesKey: #albums)
ifTrue: [((content at: #albums) at: #items)
do: [:anAlbum | results add: ((self tinkerAlbum: anAlbum) offset: index + 1).
index := index + 1].
^ results].
(content includesKey: #playlists)
ifTrue: [((content at: #playlists) at: #items)
do: [:aPlaylist | results add: ((self tinkerPlaylist: aPlaylist) offset: index + 1).
index := index + 1].
^ results]
(self contentItemsAt: #tracks in: content)
do: [:aTrack | results add: (self tinkerTrack: aTrack)].
(self contentItemsAt: #albums in: content)
do: [:anAlbum | results add: (self tinkerAlbum: anAlbum)].
(self contentItemsAt: #playlists in: content)
do: [:aPlaylist | results add: (self tinkerPlaylist: aPlaylist)].
results withIndexDo: [:aDataPiece :anIndex | aDataPiece offset: anIndex].
^ results
]
13 changes: 6 additions & 7 deletions src/SpotifyConnect/SPOCApp.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,15 @@ SPOCApp >> logout [

{
#category : #ui,
#'squeak_changestamp' : 'VE 6/20/2024 19:00'
#'squeak_changestamp' : 'VE 7/8/2024 16:39'
}
SPOCApp >> open [

| a |
a := ToolBuilder open: self.
a color: SPOCStyle spotifyBlack.
a borderColor: SPOCStyle spotifyBlack.
a paneColor: SPOCStyle spotifyBlack.
^ a
^ (ToolBuilder open: self)
color: SPOCStyle spotifyBlack;
borderColor: SPOCStyle spotifyBlack;
paneColor: SPOCStyle spotifyBlack;
yourself
]

{
Expand Down
9 changes: 0 additions & 9 deletions src/SpotifyConnect/SPOCArtist.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ Class {
#'squeak_changestamp' : 'OW 7/4/2024 11:53'
}

{
#category : #actions,
#'squeak_changestamp' : 'RK 6/7/2024 11:19'
}
SPOCArtist >> clickAction [

^ ["To do: show artist page"]
]

{
#category : #testing,
#'squeak_changestamp' : 'TL 6/12/2024 01:10'
Expand Down
46 changes: 0 additions & 46 deletions src/SpotifyConnect/SPOCAssetImageMorph.class.st

This file was deleted.

23 changes: 16 additions & 7 deletions src/SpotifyConnect/SPOCAuthorizer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,17 @@ SPOCAuthorizer >> accessToken: aToken [
accessToken := aToken
]

{
#category : #authorization,
#'squeak_changestamp' : 'VE 7/8/2024 16:17'
}
SPOCAuthorizer >> authorizeByRefresh [

self refreshAccessToken.
self isAuthorized
ifTrue: [self callSuccessCallbacks]
]

{
#category : #authorization,
#'squeak_changestamp' : 'VE 6/4/2024 09:30'
Expand Down Expand Up @@ -325,16 +336,16 @@ SPOCAuthorizer >> randomState: aState [

{
#category : #utilities,
#'squeak_changestamp' : 'TL 7/7/2024 02:19'
#'squeak_changestamp' : 'VE 7/8/2024 16:17'
}
SPOCAuthorizer >> randomString: aLength [

| chars index randomString |
chars := Character alphabet asArray.
randomString := String new: aLength.
1 to: aLength
do: [:i | index := (1 to: chars size) atRandom.
randomString at: i put: (chars at: index)].
do: [:anIndex | index := (1 to: chars size) atRandom.
randomString at: anIndex put: (chars at: index)].
^ randomString
]

Expand Down Expand Up @@ -452,15 +463,13 @@ SPOCAuthorizer >> spotifyRefreshApiContent [

{
#category : #authorization,
#'squeak_changestamp' : 'TL 7/7/2024 02:24'
#'squeak_changestamp' : 'VE 7/8/2024 16:16'
}
SPOCAuthorizer >> startAuthorization [

| url |
self canRefresh
ifTrue: [self refreshAccessToken.
self isAuthorized
ifTrue: [self callSuccessCallbacks].
ifTrue: [self authorizeByRefresh.
^ self].
self setupCallbackService.
url := self buildAuthorizationUrl.
Expand Down
68 changes: 56 additions & 12 deletions src/SpotifyConnect/SPOCBoxedText.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ Class {

{
#category : #constants,
#'squeak_changestamp' : 'TL 6/10/2024 05:10'
#'squeak_changestamp' : 'VE 7/8/2024 17:14'
}
SPOCBoxedText class >> defaultContent [

^ 'SPOCBoxedText'
^ ''
]

{
Expand Down Expand Up @@ -108,13 +108,14 @@ SPOCBoxedText >> circleMorph [

{
#category : #updating,
#'squeak_changestamp' : 'VE 5/27/2024 20:33'
#'squeak_changestamp' : 'VE 7/8/2024 17:14'
}
SPOCBoxedText >> color: aColor [

super color: Color transparent.
self centerBox color: aColor.
self leftBorderCircle color: aColor.
self rightBorderCircle color: aColor.
self rightBorderCircle color: aColor
]

{
Expand All @@ -137,12 +138,12 @@ SPOCBoxedText >> contents [

{
#category : #updating,
#'squeak_changestamp' : 'VE 6/10/2024 21:54'
#'squeak_changestamp' : 'VE 7/8/2024 17:14'
}
SPOCBoxedText >> contents: aString [

self label contents: aString.
self updateAlignments.
self updateAlignments
]

{
Expand Down Expand Up @@ -270,14 +271,57 @@ SPOCBoxedText >> rightBorderCircle [

{
#category : #updating,
#'squeak_changestamp' : 'VE 5/27/2024 21:11'
#'squeak_changestamp' : 'VE 7/8/2024 16:49'
}
SPOCBoxedText >> updateAlignments [
self extent: (self label width + SPOCBoxedText horizontalSpacing + SPOCBoxedText height @ SPOCBoxedText height).
self centerBox extent: (self label width + SPOCBoxedText horizontalSpacing @ SPOCBoxedText height).
self centerBox position: self topLeft + (SPOCBoxedText height / 2 @ 0).
self label position: self topLeft + (SPOCBoxedText height + SPOCBoxedText horizontalSpacing @ (SPOCBoxedText height - self label height) / 2).
self rightBorderCircle position: self topRight - (SPOCBoxedText height @ 0).

self updateExtent;
updateCenterBoxExtent;
updateLabelPosition;
updateRightBorderCirclePosition

]

{
#category : #updating,
#'squeak_changestamp' : 'VE 7/8/2024 16:49'
}
SPOCBoxedText >> updateCenterBoxExtent [

self centerBox extent: (self label width + self class horizontalSpacing @ self class height).
self centerBox position: self topLeft + (self class height / 2 @ 0)


]

{
#category : #updating,
#'squeak_changestamp' : 'VE 7/8/2024 16:49'
}
SPOCBoxedText >> updateExtent [

self extent: (self label width + self class horizontalSpacing + self class height @ self class height)

]

{
#category : #updating,
#'squeak_changestamp' : 'VE 7/8/2024 16:50'
}
SPOCBoxedText >> updateLabelPosition [

self label position: self topLeft + (self class height + self class horizontalSpacing @ (self class height - self label height) / 2)


]

{
#category : #updating,
#'squeak_changestamp' : 'VE 7/8/2024 16:48'
}
SPOCBoxedText >> updateRightBorderCirclePosition [

self rightBorderCircle position: self topRight - (SPOCBoxedText height @ 0)


]
4 changes: 2 additions & 2 deletions src/SpotifyConnect/SPOCIcon.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ SPOCIcon class >> size [

{
#category : #initialization,
#'squeak_changestamp' : 'TL 7/7/2024 01:11'
#'squeak_changestamp' : 'VE 7/8/2024 17:06'
}
SPOCIcon >> attachButton [

self icon: SPOCAssetImageMorph new.
self icon: SPOCImage new.
self addMorph: self icon.
self icon position: (self icon position + 8 asPoint)
]
Expand Down
Loading

0 comments on commit 5178b15

Please sign in to comment.