Swift SDK for connecting with Acrosure Insurance Gateway
You can use CocoaPods to install AcrosureSDK by adding it to your Podfile:
platform :ios, '8.0'
use_frameworks!
target 'MyApp' do
pod 'AcrosureSDK', '~> 1.0'
end
You can use Carthage to install AcrosureSDK by adding it to your Cartfile:
github "AcrosureSDK/acrosure-swift-sdk" ~> 1.0
If you use Carthage to build your dependencies, make sure you have added AcrosureSDK.framework to the "Linked Frameworks and Libraries" section of your target, and have included them in your Carthage framework copying build phase.
You can use The Swift Package Manager to install AcrosureSDK by adding the proper description to your Package.swift file:
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "YOUR_PROJECT_NAME",
dependencies: [
.package(url: "https://github.com/AcrosureSDK/acrosure-swift-sdk.git", from: "1.0.0"),
]
)
Then run swift build whenever you are prepared.
Import AcrosureClient into your project.
import AcrosureSDK
Instantiate with an API key from Acrosure Dashboard.
let client = AcrosureClient(token: '<YOUR_PUBLIC_TOKEN>')
AcrosureClient provides several objects such as application
, product
, etc. and associated APIs.
Any response will be inside an response object with type AcrosureResponse
which has following structure:
struct AcrosureResponse {
var status: String?
var data: JSON?
var message: String?
var pagination: JSON?
}
In which data
field is where the result will be in.
Functions use Closures in Swift for response handling.
This SDK uses SwiftyJSON for JSON handling and Alamofire for HTTP Request.
Get application with specified id.
client.application.get(id: "appl_SAMPLE01") { response in
// ...
}
Create an application.
client.application.create(productId: 'prod_ta') { response in
// ...
}
Update an application.
client.application.update(
id: "appl_SAMPLE01",
basicData: {},
packageOptions: {},
additionalData: {},
packageCode: '<package_code>',
) { response in
// ...
}
Get current application available packages.
client.application.getPackages(id: "appl_SAMPLE01") { response in
// ...
}
Select package for current application.
client.application.selectPackage(id: "appl_SAMPLE01", packageCode: '<package_code>) { response in
// ...
}
Get selected package of current application.
client.application.getPackage(id: "appl_SAMPLE01") { response in
// ...
}
Get hash object for 2C2P payment usage.
client.application.getHash(id: "appl_SAMPLE01", frontendUrl: "https://example.com") { response in
// ...
}
Submit current application.
client.application.submit(id: 'appl_SAMPLE01') { response in
// ...
}
List your applications (with or without query).
client.application.list() { response in
// ...
}
Get product with specified id.
client.product.get(id: 'prod_ta') { response in
// ...
}
List your products (with or without query).
client.product.list() { response in
// ...
}
Get policy with specified id.
client.policy.get(id: 'plcy_SAMPLE01') { response in
// ...
}
List your policies (with or without query).
client.policy.list() { response in
// ...
}
Get values for a handler (with or without dependencies, please refer to Acrosure API Document).
// Without dependencies
client.data.get(handler: "province") { response in
// ...
}
// With dependencies
client.data.get(handler: "subdistrict", dependencies:["กรุงเทพมหานคร","วังทองหลาง"]) { response in
// ...
}
Get current team information.
client.team.getInfo() { response in
// ...
}
Please refer to Acrosure API Document for more details on Acrosure API.
/applications/get
/applications/list
/applications/create
/applications/update
/applications/get-packages
/applications/get-package
/applications/select-package
/applications/submit
/applications/get-hash
/products/get
/products/list
/policies/get
/policies/list
/data/get
/teams/get-info
pod install
Use xcode!
Using xcpretty is recommended.
xcodebuild test -workspace AcrosureSDK.xcworkspace -scheme AcrosureSDKTests -destination 'platform=iOS Simulator,name=iPhone 6s,OS=12.0' | xcpretty
Without xcpretty:
xcodebuild test -workspace AcrosureSDK.xcworkspace -scheme AcrosureSDKTests -destination 'platform=iOS Simulator,name=iPhone 6s,OS=12.0'