Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add action to Content-Type header as the SOAP 1.2 API requires it #1

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions swea/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
scheme = "http"
host = "swea.riksbank.se"
path = "/sweaWS/services/SweaWebServiceHttpSoap12Endpoint"
contentType = "text/xml"
contentType = "application/soap+xml;charset=UTF-8"
)

var (
Expand Down Expand Up @@ -65,7 +65,7 @@ func (api *LiveAPI) GetCalendarDays(ctx context.Context, req *GetCalendarDaysReq
return nil, err
}
env := &responses.GetCalendarDaysResponseEnvelope{}
err = api.call(ctx, body, env)
err = api.call(ctx, body, "getCalendarDays", env)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -101,7 +101,7 @@ func (api *LiveAPI) GetAllCrossNames(ctx context.Context, req *GetAllCrossNamesR
return nil, err
}
env := &responses.GetAllCrossNamesResponseEnvelope{}
err = api.call(ctx, body, env)
err = api.call(ctx, body, "getAllCrossNames", env)
if err != nil {
return nil, err
}
Expand All @@ -126,7 +126,7 @@ func (api *LiveAPI) GetCrossRates(ctx context.Context, req *GetCrossRatesRequest
return nil, err
}
env := &responses.GetCrossRatesResponseEnvelope{}
err = api.call(ctx, body, env)
err = api.call(ctx, body, "getCrossRates", env)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -164,7 +164,7 @@ func (api *LiveAPI) GetInterestAndExchangeRates(ctx context.Context, req *GetInt
return nil, err
}
env := &responses.GetInterestAndExchangeRatesResponseEnvelope{}
err = api.call(ctx, body, env)
err = api.call(ctx, body, "getInterestAndExchangeRates", env)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -216,7 +216,7 @@ func (api *LiveAPI) GetInterestAndExchangeGroupNames(ctx context.Context, req *G
return nil, err
}
env := &responses.GetInterestAndExchangeGroupNamesResponseEnvelope{}
err = api.call(ctx, body, env)
err = api.call(ctx, body, "getInterestAndExchangeGroupNames", env)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -244,7 +244,7 @@ func (api *LiveAPI) GetInterestAndExchangeNames(ctx context.Context, req *GetInt
return nil, err
}
env := &responses.GetInterestAndExchangeNamesResponseEnvelope{}
err = api.call(ctx, body, env)
err = api.call(ctx, body, "getInterestAndExchangeNames", env)
if err != nil {
return nil, err
}
Expand All @@ -271,13 +271,13 @@ func (api *LiveAPI) GetInterestAndExchangeNames(ctx context.Context, req *GetInt
return res, nil
}

func (api *LiveAPI) call(ctx context.Context, body io.Reader, v interface{}) error {
func (api *LiveAPI) call(ctx context.Context, body io.Reader, action string, v interface{}) error {
// Build the request
req, err := http.NewRequest(http.MethodPost, api.url.String(), body)
if err != nil {
return err
}
req.Header.Add("Content-Type", contentType)
req.Header.Add("Content-Type", contentType+";action=urn:"+action)
req = req.WithContext(ctx)

// Perform the request
Expand Down