Skip to content

Commit

Permalink
Allow customising MyRadio server URL
Browse files Browse the repository at this point in the history
Use case: dev/staging
  • Loading branch information
markspolakovs committed Jul 31, 2020
1 parent a24548f commit 2b440aa
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ func NewSession(apikey string) (*Session, error) {
return &Session{requester: api.NewRequester(apikey, *url)}, nil
}

// NewSessionForServer constructs a new Session with the given API key for a non-standard server URL.
func NewSessionForServer(apikey, server string) (*Session, error) {
url, err := url.Parse(server)
if err != nil {
return nil, err
}
return &Session{requester: api.NewRequester(apikey, *url)}, nil
}

// MockSession creates a new mocked API session returning the JSON message stored in message.
func MockSession(message []byte) (*Session, error) {
rm := json.RawMessage{}
Expand Down Expand Up @@ -75,3 +84,14 @@ func NewSessionFromKeyFile() (*Session, error) {

return NewSession(apikey)
}

// NewSessionFromKeyFileForServer tries to open a Session with the key from an API key file, with a non-standard server.
func NewSessionFromKeyFileForServer(server string) (*Session, error) {
apikey, err := api.GetAPIKey()
if err != nil {
return nil, err
}

return NewSessionForServer(apikey, server)
}

0 comments on commit 2b440aa

Please sign in to comment.