Skip to content

Commit

Permalink
Merge pull request #27 from vora/support_direct_pushes-RESO-2247
Browse files Browse the repository at this point in the history
RESO-2247: Support Direct Pushes
  • Loading branch information
bkma authored Aug 26, 2021
2 parents 8fd3674 + 49e9ada commit f807ac5
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-urban-airship-client",
"version": "0.3.3",
"version": "0.3.4",
"description": "A client library to help with interacting with the Urban Airship API",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ export {
StaticListUploadRequest,
} from './lib/staticlists/StaticListUploadRequest'
export { Response } from './lib/client/Response'
export { PushPayload } from './lib/pushes/model/PushPayload'
export { PushRequest } from './lib/pushes/PushRequest'
37 changes: 37 additions & 0 deletions src/lib/pushes/PushRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { IHeaders } from '../client/IHeaders'
import { HttpMethod, IRequest } from '../client/IRequest'
import {
ACCEPT_HEADER,
CONTENT_TYPE,
CONTENT_TYPE_JSON,
UA_VERSION_JSON,
} from '../Constants'

import { PushPayload } from './model/PushPayload'

export class PushRequest implements IRequest {
private pushPayloads: PushPayload[] = []

addPushPayload(payload: PushPayload) {
this.pushPayloads.push(payload)
}

getHttpMethod(): HttpMethod {
return HttpMethod.POST
}

getRequestBody(): string {
return JSON.stringify(this.pushPayloads)
}

getRequestHeaders(): IHeaders {
return {
[ACCEPT_HEADER]: UA_VERSION_JSON,
[CONTENT_TYPE]: CONTENT_TYPE_JSON,
}
}

getUriPath(): string {
return `/api/push/`
}
}
60 changes: 60 additions & 0 deletions src/lib/pushes/model/PushPayload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { DeviceType } from '../../templates/model/TemplatePushPayload'

export class PushPayload {
audience: object
campaigns?: any
feed_references?: any
localizations?: ILocalization[]
message?: any
notification?: INotification
snippet_references?: ISnippetReferences
options?: IOptions
device_types: DeviceType[]
}

interface IOptions {
bypass_frequency_limits?: boolean
expiry?: string | number
no_throttle?: boolean
personalization?: boolean
redact_payload?: boolean
}

interface ISnippetReferences {
snippets: { name: string }[]
}

interface INotification {
actions?: IActions
alert?: string
amazon?: any
android?: any
email?: any
ios?: any
mms?: any
sms?: any
web?: any
wns?: any
}

interface IActions {
add_tag?: string[]
app_defined?: { string: string }
open?: IOpen
remove_tag?: string[]
share?: string
}

interface IOpen {
type: string
content: string
fallback_url?: string
}

interface ILocalization {
country?: string
in_app?: any
language: string
message?: any
notification?: INotification
}

0 comments on commit f807ac5

Please sign in to comment.