Skip to content

Commit 1962565

Browse files
committed
FIX: minor code improvements in Spotify module
1 parent d920491 commit 1962565

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/modules/spotify.reb

+14-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Rebol [
66
File: %spotify.reb
77
Name: 'spotify
88
Type: 'module
9-
Version: 0.1.0
9+
Version: 0.1.1
1010
Require: 'httpd
1111
Note: {
1212
Useful info:
@@ -26,16 +26,18 @@ spotify: object [
2626
scope: ""
2727
port-id: 8989
2828
token: none
29-
get: func [what [any-string!]][system/modules/spotify/request self 'GET what none]
30-
put: func [what [any-string!] /with data][system/modules/spotify/request self 'PUT what data]
31-
del: func [what [any-string!]][system/modules/spotify/request self 'DELETE what none]
29+
get: func [what [any-string!]][request self 'GET what none]
30+
put: func [what [any-string!] /with data][request self 'PUT what data]
31+
del: func [what [any-string!]][request self 'DELETE what none]
32+
request: none
3233
]
3334

3435
authorize: function [
3536
"OAuth2 Spotify authorization used to get the main context"
3637
ctx [block! object!] "Data used for initialization (at least client-id is needed)"
3738
][
3839
ctx: make spotify ctx
40+
ctx/request: :request
3941

4042
unless ctx/client-id [
4143
print ajoin ["*** `" value "` is needed to authorize with Spotify!"]
@@ -68,8 +70,10 @@ authorize: function [
6870
]
6971
; if client-secret was not specified, create challenge for PKCE extension
7072
if code-challenge [
71-
append append url "&state=" state: form random 99999999999
72-
append append url "&code_challenge_method=S256&code_challenge=" code-challenge
73+
append url reduce [
74+
"&state=" state: form random 99999999999
75+
"&code_challenge_method=S256&code_challenge=" code-challenge
76+
]
7377
]
7478
; and open the url in user's default browser
7579
browse url
@@ -80,7 +84,7 @@ authorize: function [
8084
result: system/modules/httpd/http-server/config/actor ctx/port-id [
8185
root: #[false] ; we are not serving any content!
8286
keep-alive: #[false]
83-
] object [
87+
] [
8488

8589
;- Server's actor functions
8690

@@ -95,12 +99,11 @@ authorize: function [
9599
%spotify-callback/ [
96100
ctx/out/status: 200
97101
ctx/out/content: ajoin [
98-
"<h1>OAuth2 Callback</h1>"
102+
"<h1>OAuth2 Spotify Callback</h1>"
99103
"<br/>Request header:<pre>" mold ctx/inp/header </pre>
100104
"<br/>Values:<pre>" mold ctx/inp/target/values </pre>
101-
;<pre> mold ctx </pre>
105+
"<h2>You can close this window and return back to Rebol</h2>"
102106
]
103-
;wake-up ctx/parent make event! [type: 'CLOSE port: port]
104107
ctx/done?: ctx/inp/target/values
105108
]
106109
][
@@ -145,7 +148,7 @@ authorize: function [
145148
ctx/token/expires_in: time + (to time! ctx/token/expires_in)
146149
][
147150
print "*** Failed to receive Spotify token!"
148-
;probe system/state/last-error
151+
probe system/state/last-error
149152
return none
150153
]
151154
; return Spotify context

0 commit comments

Comments
 (0)