Skip to content

Commit

Permalink
feat(GiniBankAPILibrary): refactor APIResource
Browse files Browse the repository at this point in the history
PP-649
  • Loading branch information
mrkulik committed Dec 13, 2024
1 parent b5a3674 commit 0d58a76
Showing 1 changed file with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,33 +129,29 @@ struct APIResource<T: Decodable>: Resource {
}

var defaultHeaders: HTTPHeaders {
let acceptKey = "Accept"
let contentTypeKey = "Content-Type"

let jsonAcceptValue = ContentType.content(version: apiVersion, subtype: nil, mimeSubtype: "json").value
let jsonContentTypeValue = ContentType.content(version: apiVersion, subtype: nil, mimeSubtype: "json").value
let amplitudeEventsValue = "application/vnd.gini.v1.events.amplitude"

switch method {
case .createDocument(_, _, let mimeSubType, let documentType):
return ["Accept": ContentType.content(version: apiVersion,
subtype: nil,
mimeSubtype: "json").value,
"Content-Type": ContentType.content(version: apiVersion,
subtype: documentType?.name,
mimeSubtype: mimeSubType).value
]
let dynamicContentType = ContentType.content(version: apiVersion, subtype: documentType?.name, mimeSubtype: mimeSubType).value
return [acceptKey: jsonAcceptValue, contentTypeKey: dynamicContentType]

case .page, .pagePreview, .documentPage:
return [:]

case .paymentRequests:
return ["Accept": ContentType.content(version: apiVersion,
subtype: nil,
mimeSubtype: "json").value]
return [acceptKey: jsonAcceptValue]

case .analyticsEvent:
return ["Accept": ContentType.json.value,
"Content-Type": "application/vnd.gini.v1.events.amplitude"
]
return [acceptKey: ContentType.json.value, contentTypeKey: amplitudeEventsValue]

default:
return ["Accept": ContentType.content(version: apiVersion,
subtype: nil,
mimeSubtype: "json").value,
"Content-Type": ContentType.content(version: apiVersion,
subtype: nil,
mimeSubtype: "json").value
]
return [acceptKey: jsonAcceptValue, contentTypeKey: jsonContentTypeValue]
}
}

Expand Down

0 comments on commit 0d58a76

Please sign in to comment.