6
6
File: %spotify.reb
7
7
Name: 'spotify
8
8
Type: 'module
9
- Version: 0.1.0
9
+ Version: 0.1.1
10
10
Require: 'httpd
11
11
Note: {
12
12
Useful info:
@@ -26,16 +26,18 @@ spotify: object [
26
26
scope: ""
27
27
port-id: 8989
28
28
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
32
33
]
33
34
34
35
authorize : function [
35
36
"OAuth2 Spotify authorization used to get the main context"
36
37
ctx [block! object! ] "Data used for initialization (at least client-id is needed)"
37
38
] [
38
39
ctx: make spotify ctx
40
+ ctx/request: :request
39
41
40
42
unless ctx/client-id [
41
43
print ajoin ["*** `" value "` is needed to authorize with Spotify!" ]
@@ -68,8 +70,10 @@ authorize: function [
68
70
]
69
71
; if client-secret was not specified, create challenge for PKCE extension
70
72
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
+ ]
73
77
]
74
78
; and open the url in user's default browser
75
79
browse url
@@ -80,7 +84,7 @@ authorize: function [
80
84
result: system/modules/httpd/http-server/config/actor ctx/port-id [
81
85
root: #[false] ; we are not serving any content!
82
86
keep-alive: #[false]
83
- ] object [
87
+ ] [
84
88
85
89
;- Server's actor functions
86
90
@@ -95,12 +99,11 @@ authorize: function [
95
99
%spotify-callback/ [
96
100
ctx/out/status: 200
97
101
ctx/out/content: ajoin [
98
- "<h1>OAuth2 Callback</h1>"
102
+ "<h1>OAuth2 Spotify Callback</h1>"
99
103
"<br/>Request header:<pre>" mold ctx/inp/header </pre >
100
104
"<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>"
102
106
]
103
- ;wake-up ctx/parent make event! [type: 'CLOSE port: port]
104
107
ctx/done?: ctx/inp/target/values
105
108
]
106
109
][
@@ -145,7 +148,7 @@ authorize: function [
145
148
ctx/token/expires_in: time + (to time! ctx/token/expires_in )
146
149
][
147
150
print "*** Failed to receive Spotify token!"
148
- ; probe system/state/last-error
151
+ probe system/state/last-error
149
152
return none
150
153
]
151
154
; return Spotify context
0 commit comments