Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
fix: handle get and post differently
Browse files Browse the repository at this point in the history
  • Loading branch information
gigobyte committed May 3, 2020
1 parent 708ec18 commit fe2c1cd
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface Request {
url: string
method: HttpMethod
headers: Record<string, string>
data: string
data?: string
}

interface ResourceInfo<TResource extends Resource> {
Expand Down Expand Up @@ -59,7 +59,7 @@ export class HttpClient {
const marketplaceUri = this.options.marketplace.webServiceUri

const host = marketplaceUri.replace('https://', '')
const url = `${marketplaceUri}/${info.resource}/${info.version}/`
const url = `${marketplaceUri}/${info.resource}/${info.version}`

const parameters = {
AWSAccessKeyId: this.options.awsAccessKeyId,
Expand All @@ -79,13 +79,21 @@ export class HttpClient {
const signature = sign(queryStringToSign, this.options.secretKey)
const parametersWithSignature = { ...parameters, Signature: signature }

return this.fetch({
url,
method,
headers: {
'user-agent': '@scaleleap/amazon-mws-api-sdk/1.0.0 (Language=JavaScript)',
},
data: canonicalizeParameters(parametersWithSignature),
})
const headers = {
'user-agent': '@scaleleap/amazon-mws-api-sdk/1.0.0 (Language=JavaScript)',
}

return method === 'GET'
? this.fetch({
url: `${url}?${canonicalizeParameters(parametersWithSignature)}`,
method,
headers,
})
: this.fetch({
url,
method,
headers,
data: canonicalizeParameters(parametersWithSignature),
})
}
}

0 comments on commit fe2c1cd

Please sign in to comment.