Skip to content

Commit

Permalink
Move the API endpoints to constants
Browse files Browse the repository at this point in the history
  • Loading branch information
ironsmile committed Oct 3, 2021
1 parent eb35489 commit 6da0f0a
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions euterpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def load_upstream_data(self):
self.new_model()

self.cancel_request()
search_url = self.build_API_URL(self.address_base, '/v1/search/')
search_url = self.build_API_URL(self.address_base, ENDPOINT_SEARCH)
print("Loading HTTPMS into the database")
self.loader = Loader()
self.loader.set_headers(self.auth_headers)
Expand All @@ -350,20 +350,20 @@ def add_track(self, db, entry_type, item):
# track_url is the canonical unique URL for this track.
track_url = self.build_API_URL(
self.address_base,
'/v1/file/{}'.format(item['id']),
ENDPOINT_FILE.format(item['id']),
)

# play_url is the URL at which this track can be loaded.
# Sometimes this can be different from track_url. For
# example when the URL includes a token or basic auth.
play_url = self.build_API_URL(
self.address_base,
'/v1/file/{}'.format(item['id']),
ENDPOINT_FILE.format(item['id']),
)

album_url = self.build_API_URL(
self.address_base,
'/v1/album/{}/artwork'.format(item['album_id']),
ENDPOINT_ALBUM_ART.format(item['album_id']),
)

if len(self.auth_token) > 0:
Expand Down Expand Up @@ -526,7 +526,7 @@ def try_authenticated(self, remote_url):
username = self.login_entry_user.get_text().strip()
password = self.login_entry_pass.get_text()

login_token_url = self.build_API_URL(remote_url, '/v1/login/token/')
login_token_url = self.build_API_URL(remote_url, ENDPOINT_LOGIN)
print("making auth request to {}".format(login_token_url))

loader = Loader()
Expand Down Expand Up @@ -581,7 +581,7 @@ def register_auth_token(self, token, remote_url):
order to activate the newly received token.
'''
register_token_url = self.build_API_URL(
remote_url, '/v1/register/token/')
remote_url, ENDPOINT_REGISTER_TOKEN)

register_token_url = '{}?token={}'.format(register_token_url, token)

Expand Down Expand Up @@ -702,4 +702,11 @@ def key_file_name(self):
return os.path.join(data_dir, "euterpe.auth")


ENDPOINT_LOGIN = '/v1/login/token/'
ENDPOINT_REGISTER_TOKEN = '/v1/register/token/'
ENDPOINT_SEARCH = '/v1/search/'
ENDPOINT_FILE = '/v1/file/{}'
ENDPOINT_ALBUM_ART = '/v1/album/{}/artwork'


GObject.type_register(EuterpeSource)

0 comments on commit 6da0f0a

Please sign in to comment.